@harbour-enterprises/superdoc 1.0.0-beta.99 → 1.0.0-next.1

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 (28) hide show
  1. package/dist/chunks/{PdfViewer-DF-v5Yrr.es.js → PdfViewer-BKujh9gl.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-BtuTHUW7.cjs → PdfViewer-Cu04k0JZ.cjs} +1 -1
  3. package/dist/chunks/{index-BBu9BBvp.cjs → index-CZ4149Px.cjs} +3 -3
  4. package/dist/chunks/{index-CJy3FxL7.es.js → index-Cl0tjE1C.es.js} +3 -3
  5. package/dist/chunks/{index-BB0msI45-DUPBw4Bh.es.js → index-Dlj3l0Hk-BuYH_UIe.es.js} +1 -1
  6. package/dist/chunks/{index-BB0msI45-CPU6Ak2R.cjs → index-Dlj3l0Hk-CJ0YBOja.cjs} +1 -1
  7. package/dist/chunks/{super-editor.es-C04sFzVD.cjs → super-editor.es-CjRtsxTt.cjs} +973 -178
  8. package/dist/chunks/{super-editor.es-BiaFIbw-.es.js → super-editor.es-D0WByw5h.es.js} +973 -178
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-B_cVJPnh.js → converter-BS4FD8AG.js} +12 -6
  12. package/dist/super-editor/chunks/{docx-zipper-fPWx7kV0.js → docx-zipper-DpiCpt0d.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-DS9z42Je.js → editor-BeacbTQe.js} +963 -170
  14. package/dist/super-editor/chunks/{index-BB0msI45.js → index-Dlj3l0Hk.js} +1 -1
  15. package/dist/super-editor/chunks/{toolbar-aIFlIr6h.js → toolbar-BNQDvBCn.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/super-editor.es.js +10 -10
  21. package/dist/super-editor/toolbar.es.js +2 -2
  22. package/dist/super-editor.cjs +1 -1
  23. package/dist/super-editor.es.js +1 -1
  24. package/dist/superdoc.cjs +2 -2
  25. package/dist/superdoc.es.js +2 -2
  26. package/dist/superdoc.umd.js +975 -180
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +10 -1
@@ -39793,7 +39793,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39793
39793
  const trackedDeletedText = attributes["custom:trackedDeletedText"] !== "null" ? attributes["custom:trackedDeletedText"] : null;
39794
39794
  const date = new Date(createdDate);
39795
39795
  const unixTimestampMs = date.getTime();
39796
- const parsedComment = nodeListHandler.handler({
39796
+ const parsedElements = nodeListHandler.handler({
39797
39797
  nodes: el.elements,
39798
39798
  nodeListHandler,
39799
39799
  docx,
@@ -39801,7 +39801,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39801
39801
  converter,
39802
39802
  path: [el]
39803
39803
  });
39804
- const { attrs } = parsedComment[0];
39804
+ const { attrs } = parsedElements[0];
39805
39805
  const paraId = attrs["w14:paraId"];
39806
39806
  return {
39807
39807
  commentId: internalId || v4$1(),
@@ -39809,7 +39809,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39809
39809
  creatorName: authorName,
39810
39810
  creatorEmail: authorEmail,
39811
39811
  createdTime: unixTimestampMs,
39812
- textJson: parsedComment[0],
39812
+ textJson: parsedElements[0],
39813
+ elements: parsedElements,
39813
39814
  initials,
39814
39815
  paraId,
39815
39816
  trackedChange,
@@ -39835,7 +39836,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39835
39836
  const { elements = [] } = initialElements[0] ?? {};
39836
39837
  const commentEx = elements.filter((el) => el.name === "w15:commentEx");
39837
39838
  return comments.map((comment2) => {
39838
- const extendedDef = commentEx.find((ce2) => ce2.attributes["w15:paraId"] === comment2.paraId);
39839
+ const extendedDef = commentEx.find((ce2) => {
39840
+ const isIncludedInCommentElements = comment2.elements?.some(
39841
+ (el) => el.attrs?.["w14:paraId"] === ce2.attributes["w15:paraId"]
39842
+ );
39843
+ return isIncludedInCommentElements;
39844
+ });
39839
39845
  if (!extendedDef) return { ...comment2, isDone: comment2.isDone ?? false };
39840
39846
  const { isDone, paraIdParent } = getExtendedDetails(extendedDef);
39841
39847
  let parentComment;
@@ -41956,7 +41962,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41956
41962
  name: "w16cex:commentExtensible",
41957
41963
  attributes: {
41958
41964
  "w16cex:durableId": newDurableId,
41959
- "w16cex:dateUtc": toIsoNoFractional()
41965
+ "w16cex:dateUtc": toIsoNoFractional(comment2.createdTime)
41960
41966
  }
41961
41967
  };
41962
41968
  extensibleUpdated.elements[0].elements.push(newExtensible);
@@ -42422,7 +42428,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42422
42428
  static getStoredSuperdocVersion(docx) {
42423
42429
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42424
42430
  }
42425
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.99") {
42431
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-next.1") {
42426
42432
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42427
42433
  }
42428
42434
  /**
@@ -53591,7 +53597,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
53591
53597
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
53592
53598
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
53593
53599
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
53594
- var _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, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _dimmingOverlay, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _dragHandlerCleanup, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _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, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _dragAnchor, _isDragging, _dragExtensionMode, _cellAnchor, _cellDragMode, _remoteCursorState, _remoteCursorElements, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _scrollTimeout, _lastRemoteCursorRenderTime, _remoteCursorThrottleTimeout, _PresentationEditor_instances, collectCommentPositions_fn, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, updateLocalAwarenessCursor_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_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, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _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, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, scrollPageIntoView_fn, computeAnchorMap_fn, waitForPageMount_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, applyDomCorrectionToRects_fn, renderCellSelectionOverlay_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, parseColumns_fn, inchesToPx_fn, applyZoom_fn, createLayoutMetrics_fn, getPageOffsetX_fn, convertPageLocalToOverlayCoords_fn, computeDomCaretPageLocal_fn, normalizeClientPoint_fn, computeCaretLayoutRectGeometry_fn, computeCaretLayoutRect_fn, computeTableCaretLayoutRect_fn, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _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, _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;
53600
+ var _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, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _dimmingOverlay, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _pageGeometryHelper, _dragHandlerCleanup, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _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, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _dragAnchor, _isDragging, _dragExtensionMode, _cellAnchor, _cellDragMode, _remoteCursorState, _remoteCursorElements, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _scrollTimeout, _lastRemoteCursorRenderTime, _remoteCursorThrottleTimeout, _PresentationEditor_instances, collectCommentPositions_fn, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, updateLocalAwarenessCursor_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_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, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _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, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, scrollPageIntoView_fn, computeAnchorMap_fn, waitForPageMount_fn, getEffectivePageGap_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, applyDomCorrectionToRects_fn, renderCellSelectionOverlay_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, parseColumns_fn, inchesToPx_fn, applyZoom_fn, createLayoutMetrics_fn, getPageOffsetX_fn, convertPageLocalToOverlayCoords_fn, computeDomCaretPageLocal_fn, normalizeClientPoint_fn, computeCaretLayoutRectGeometry_fn, computeCaretLayoutRect_fn, computeTableCaretLayoutRect_fn, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _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, _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;
53595
53601
  var GOOD_LEAF_SIZE = 200;
53596
53602
  var RopeSequence = function RopeSequence2() {
53597
53603
  };
@@ -62675,6 +62681,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62675
62681
  const selectAll = () => ({ state: state2, dispatch }) => selectAll$1(state2, dispatch);
62676
62682
  const deleteSelection = () => ({ state: state2, tr, dispatch }) => {
62677
62683
  const { from: from2, to, empty: empty2 } = state2.selection;
62684
+ if (typeof document !== "undefined" && document.getSelection) {
62685
+ const currentDomSelection = document.getSelection();
62686
+ const selectedLength = currentDomSelection?.toString?.().length;
62687
+ const isCollapsed = currentDomSelection?.isCollapsed;
62688
+ if (!isCollapsed && selectedLength === 1) {
62689
+ return false;
62690
+ }
62691
+ }
62678
62692
  if (empty2) {
62679
62693
  return deleteSelection$1(state2, dispatch);
62680
62694
  }
@@ -64974,12 +64988,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64974
64988
  importedId: node2.attrs["w:id"]
64975
64989
  });
64976
64990
  if (type2.name === "commentRangeStart") {
64977
- toMark.push({
64978
- commentId: resolvedCommentId,
64979
- importedId,
64980
- internal,
64981
- start: pos
64982
- });
64991
+ if (!matchingImportedComment?.isDone) {
64992
+ toMark.push({
64993
+ commentId: resolvedCommentId,
64994
+ importedId,
64995
+ internal,
64996
+ start: pos
64997
+ });
64998
+ }
64983
64999
  ensureFallbackComment({
64984
65000
  converter,
64985
65001
  matchingImportedComment,
@@ -67497,7 +67513,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67497
67513
  const shouldSkipNodeView = (editor) => {
67498
67514
  return isHeadless(editor);
67499
67515
  };
67500
- const summaryVersion = "1.0.0-beta.99";
67516
+ const summaryVersion = "1.0.0-next.1";
67501
67517
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
67502
67518
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
67503
67519
  function mapAttributes(attrs) {
@@ -67857,11 +67873,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67857
67873
  if (!this.options.isNewFile || !this.options.collaborationProvider) return;
67858
67874
  const provider2 = this.options.collaborationProvider;
67859
67875
  const postSyncInit = () => {
67860
- provider2.off("synced", postSyncInit);
67876
+ provider2.off?.("synced", postSyncInit);
67861
67877
  __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
67862
67878
  };
67863
67879
  if (provider2.synced) __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
67864
- else provider2.on("synced", postSyncInit);
67880
+ else provider2.on?.("synced", postSyncInit);
67865
67881
  }
67866
67882
  /**
67867
67883
  * Replace content of editor that was created with loadFromSchema option
@@ -68286,7 +68302,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68286
68302
  { default: remarkStringify2 },
68287
68303
  { default: remarkGfm2 }
68288
68304
  ] = await Promise.all([
68289
- Promise.resolve().then(() => indexBB0msI45),
68305
+ Promise.resolve().then(() => indexDlj3l0Hk),
68290
68306
  Promise.resolve().then(() => indexDRCvimau),
68291
68307
  Promise.resolve().then(() => indexC_x_N6Uh),
68292
68308
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -68491,7 +68507,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68491
68507
  * Process collaboration migrations
68492
68508
  */
68493
68509
  processCollaborationMigrations() {
68494
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.99");
68510
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-next.1");
68495
68511
  if (!this.options.ydoc) return;
68496
68512
  const metaMap = this.options.ydoc.getMap("meta");
68497
68513
  let docVersion = metaMap.get("version");
@@ -71606,6 +71622,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
71606
71622
  if (cellChanged) {
71607
71623
  return {
71608
71624
  ...cell2,
71625
+ // Cast to expected type - hydrateBlock preserves block kinds, just hydrates image sources
71609
71626
  blocks: hydratedBlocks.length > 0 ? hydratedBlocks : cell2.blocks,
71610
71627
  paragraph: hydratedParagraph
71611
71628
  };
@@ -75226,7 +75243,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75226
75243
  };
75227
75244
  }
75228
75245
  const hasValidNumbering = rawNumberingProps && isValidNumberingId(rawNumberingProps.numId);
75229
- if (hasValidNumbering) {
75246
+ if (hasValidNumbering && rawNumberingProps) {
75230
75247
  const numberingProps = rawNumberingProps;
75231
75248
  const numId = numberingProps.numId;
75232
75249
  const ilvl = Number.isFinite(numberingProps.ilvl) ? Math.max(0, Math.floor(Number(numberingProps.ilvl))) : 0;
@@ -75266,6 +75283,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75266
75283
  const resolvedCounterValue = path2[path2.length - 1] ?? counterValue;
75267
75284
  const enrichedNumberingProps = {
75268
75285
  ...numberingProps,
75286
+ numId: numberingProps.numId,
75287
+ ilvl: numberingProps.ilvl,
75269
75288
  path: path2,
75270
75289
  counterValue: resolvedCounterValue
75271
75290
  };
@@ -77362,7 +77381,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77362
77381
  context.nextBlockId,
77363
77382
  context.positions
77364
77383
  );
77365
- if (drawingBlock) {
77384
+ if (drawingBlock && drawingBlock.kind === "drawing") {
77366
77385
  blocks2.push(drawingBlock);
77367
77386
  }
77368
77387
  continue;
@@ -77373,7 +77392,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77373
77392
  context.nextBlockId,
77374
77393
  context.positions
77375
77394
  );
77376
- if (drawingBlock) {
77395
+ if (drawingBlock && drawingBlock.kind === "drawing") {
77377
77396
  blocks2.push(drawingBlock);
77378
77397
  }
77379
77398
  continue;
@@ -77384,7 +77403,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77384
77403
  context.nextBlockId,
77385
77404
  context.positions
77386
77405
  );
77387
- if (drawingBlock) {
77406
+ if (drawingBlock && drawingBlock.kind === "drawing") {
77388
77407
  blocks2.push(drawingBlock);
77389
77408
  }
77390
77409
  continue;
@@ -77395,7 +77414,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77395
77414
  context.nextBlockId,
77396
77415
  context.positions
77397
77416
  );
77398
- if (drawingBlock) {
77417
+ if (drawingBlock && drawingBlock.kind === "drawing") {
77399
77418
  blocks2.push(drawingBlock);
77400
77419
  }
77401
77420
  }
@@ -77850,7 +77869,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77850
77869
  bookmarks2,
77851
77870
  hyperlinkConfig2,
77852
77871
  themeColorsParam ?? themeColors,
77853
- paragraphConverter
77872
+ paragraphConverter,
77873
+ converterCtx ?? converterContext,
77874
+ {
77875
+ listCounterContext: { getListCounter, incrementListCounter, resetListCounter },
77876
+ converters: {
77877
+ paragraphToFlowBlocks: paragraphConverter,
77878
+ imageNodeToBlock,
77879
+ vectorShapeNodeToDrawingBlock,
77880
+ shapeGroupNodeToDrawingBlock,
77881
+ shapeContainerNodeToDrawingBlock,
77882
+ shapeTextboxNodeToDrawingBlock
77883
+ }
77884
+ }
77854
77885
  );
77855
77886
  const handlerContext = {
77856
77887
  blocks: blocks2,
@@ -77871,6 +77902,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77871
77902
  currentParagraphIndex: 0
77872
77903
  },
77873
77904
  converters: {
77905
+ // Type assertion needed due to signature mismatch between actual function and type definition
77874
77906
  paragraphToFlowBlocks: paragraphConverter,
77875
77907
  tableNodeToBlock: tableConverter,
77876
77908
  imageNodeToBlock,
@@ -77966,6 +77998,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77966
77998
  {
77967
77999
  listCounterContext,
77968
78000
  converters: {
78001
+ // Type assertion needed due to signature mismatch between actual function and type definition
77969
78002
  paragraphToFlowBlocks: paragraphToFlowBlocks$1,
77970
78003
  imageNodeToBlock,
77971
78004
  vectorShapeNodeToDrawingBlock,
@@ -77979,7 +78012,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77979
78012
  converterContext
77980
78013
  );
77981
78014
  }
77982
- function tableNodeToBlock(node2, nextBlockId, positions, defaultFont, defaultSize, styleContext, trackedChanges, bookmarks, hyperlinkConfig, themeColors, converterContext) {
78015
+ function tableNodeToBlock(node2, nextBlockId, positions, defaultFont, defaultSize, styleContext, trackedChanges, bookmarks, hyperlinkConfig, themeColors, _paragraphToFlowBlocksParam, converterContext, options) {
77983
78016
  return tableNodeToBlock$1(
77984
78017
  node2,
77985
78018
  nextBlockId,
@@ -77993,8 +78026,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77993
78026
  themeColors,
77994
78027
  paragraphToFlowBlocks,
77995
78028
  converterContext,
77996
- {
78029
+ options ?? {
77997
78030
  converters: {
78031
+ // Type assertion needed due to signature mismatch between actual function and type definition
77998
78032
  paragraphToFlowBlocks: paragraphToFlowBlocks$1,
77999
78033
  imageNodeToBlock,
78000
78034
  vectorShapeNodeToDrawingBlock,
@@ -80574,7 +80608,7 @@ ${l}
80574
80608
  alignItems: "center",
80575
80609
  background: "transparent",
80576
80610
  padding: "0",
80577
- gap: "24px",
80611
+ // gap is set dynamically by renderer based on pageGap option (default: 24px)
80578
80612
  overflowY: "auto"
80579
80613
  };
80580
80614
  const containerStylesHorizontal = {
@@ -80584,7 +80618,7 @@ ${l}
80584
80618
  justifyContent: "safe center",
80585
80619
  background: "transparent",
80586
80620
  padding: "0",
80587
- gap: "20px",
80621
+ // gap is set dynamically by renderer based on pageGap option (default: 20px for horizontal)
80588
80622
  overflowX: "auto",
80589
80623
  minHeight: "100%"
80590
80624
  };
@@ -82298,6 +82332,49 @@ ${l}
82298
82332
  if (borders.left) parts.push(`l:[${hashParagraphBorder$1(borders.left)}]`);
82299
82333
  return parts.join(";");
82300
82334
  };
82335
+ const isNoneBorder$1 = (value) => {
82336
+ return typeof value === "object" && value !== null && "none" in value && value.none === true;
82337
+ };
82338
+ const isBorderSpec$1 = (value) => {
82339
+ return typeof value === "object" && value !== null && !("none" in value);
82340
+ };
82341
+ const hashBorderSpec$1 = (border) => {
82342
+ const parts = [];
82343
+ if (border.style !== void 0) parts.push(`s:${border.style}`);
82344
+ if (border.width !== void 0) parts.push(`w:${border.width}`);
82345
+ if (border.color !== void 0) parts.push(`c:${border.color}`);
82346
+ if (border.space !== void 0) parts.push(`sp:${border.space}`);
82347
+ return parts.join(",");
82348
+ };
82349
+ const hashTableBorderValue$1 = (borderValue) => {
82350
+ if (borderValue === void 0) return "";
82351
+ if (borderValue === null) return "null";
82352
+ if (isNoneBorder$1(borderValue)) return "none";
82353
+ if (isBorderSpec$1(borderValue)) {
82354
+ return hashBorderSpec$1(borderValue);
82355
+ }
82356
+ return "";
82357
+ };
82358
+ const hashTableBorders$1 = (borders) => {
82359
+ if (!borders) return "";
82360
+ const parts = [];
82361
+ if (borders.top !== void 0) parts.push(`t:[${hashTableBorderValue$1(borders.top)}]`);
82362
+ if (borders.right !== void 0) parts.push(`r:[${hashTableBorderValue$1(borders.right)}]`);
82363
+ if (borders.bottom !== void 0) parts.push(`b:[${hashTableBorderValue$1(borders.bottom)}]`);
82364
+ if (borders.left !== void 0) parts.push(`l:[${hashTableBorderValue$1(borders.left)}]`);
82365
+ if (borders.insideH !== void 0) parts.push(`ih:[${hashTableBorderValue$1(borders.insideH)}]`);
82366
+ if (borders.insideV !== void 0) parts.push(`iv:[${hashTableBorderValue$1(borders.insideV)}]`);
82367
+ return parts.join(";");
82368
+ };
82369
+ const hashCellBorders$1 = (borders) => {
82370
+ if (!borders) return "";
82371
+ const parts = [];
82372
+ if (borders.top) parts.push(`t:[${hashBorderSpec$1(borders.top)}]`);
82373
+ if (borders.right) parts.push(`r:[${hashBorderSpec$1(borders.right)}]`);
82374
+ if (borders.bottom) parts.push(`b:[${hashBorderSpec$1(borders.bottom)}]`);
82375
+ if (borders.left) parts.push(`l:[${hashBorderSpec$1(borders.left)}]`);
82376
+ return parts.join(";");
82377
+ };
82301
82378
  const hasStringProp = (run2, prop) => {
82302
82379
  return prop in run2 && typeof run2[prop] === "string";
82303
82380
  };
@@ -82387,6 +82464,7 @@ ${l}
82387
82464
  const LIST_MARKER_GAP$1 = 8;
82388
82465
  const DEFAULT_TAB_INTERVAL_PX$1 = 48;
82389
82466
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
82467
+ const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
82390
82468
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
82391
82469
  const COMMENT_INTERNAL_COLOR = "#078383";
82392
82470
  const COMMENT_INACTIVE_ALPHA = "22";
@@ -82516,10 +82594,11 @@ ${l}
82516
82594
  this.totalPages = 0;
82517
82595
  this.linkIdCounter = 0;
82518
82596
  this.pendingTooltips = /* @__PURE__ */ new WeakMap();
82597
+ this.pageGap = 24;
82519
82598
  this.virtualEnabled = false;
82520
82599
  this.virtualWindow = 5;
82521
82600
  this.virtualOverscan = 0;
82522
- this.virtualGap = 72;
82601
+ this.virtualGap = DEFAULT_VIRTUALIZED_PAGE_GAP$1;
82523
82602
  this.virtualPaddingTop = null;
82524
82603
  this.topSpacerEl = null;
82525
82604
  this.bottomSpacerEl = null;
@@ -82538,13 +82617,14 @@ ${l}
82538
82617
  this.blockLookup = this.buildBlockLookup(blocks2, measures);
82539
82618
  this.headerProvider = options.headerProvider;
82540
82619
  this.footerProvider = options.footerProvider;
82620
+ const defaultGap = this.layoutMode === "horizontal" ? 20 : 24;
82621
+ this.pageGap = typeof options.pageGap === "number" && Number.isFinite(options.pageGap) ? Math.max(0, options.pageGap) : defaultGap;
82541
82622
  if (this.layoutMode === "vertical" && options.virtualization?.enabled) {
82542
82623
  this.virtualEnabled = true;
82543
82624
  this.virtualWindow = Math.max(1, options.virtualization.window ?? 5);
82544
82625
  this.virtualOverscan = Math.max(0, options.virtualization.overscan ?? 0);
82545
- if (typeof options.virtualization.gap === "number" && Number.isFinite(options.virtualization.gap)) {
82546
- this.virtualGap = Math.max(0, options.virtualization.gap);
82547
- }
82626
+ const hasExplicitVirtualGap = typeof options.virtualization.gap === "number" && Number.isFinite(options.virtualization.gap);
82627
+ this.virtualGap = hasExplicitVirtualGap ? Math.max(0, options.virtualization.gap) : DEFAULT_VIRTUALIZED_PAGE_GAP$1;
82548
82628
  if (typeof options.virtualization.paddingTop === "number" && Number.isFinite(options.virtualization.paddingTop)) {
82549
82629
  this.virtualPaddingTop = Math.max(0, options.virtualization.paddingTop);
82550
82630
  }
@@ -82645,6 +82725,7 @@ ${l}
82645
82725
  const mode = this.layoutMode;
82646
82726
  if (mode === "horizontal") {
82647
82727
  applyStyles$2(mount2, containerStylesHorizontal);
82728
+ mount2.style.gap = `${this.pageGap}px`;
82648
82729
  this.renderHorizontal(layout, mount2);
82649
82730
  this.currentLayout = layout;
82650
82731
  this.pageStates = [];
@@ -82667,6 +82748,7 @@ ${l}
82667
82748
  this.changedBlocks.clear();
82668
82749
  return;
82669
82750
  }
82751
+ mount2.style.gap = `${this.pageGap}px`;
82670
82752
  if (!this.currentLayout || this.pageStates.length === 0) {
82671
82753
  this.fullRender(layout);
82672
82754
  } else {
@@ -82991,9 +83073,15 @@ ${l}
82991
83073
  const container = existing ?? this.doc.createElement("div");
82992
83074
  container.className = className;
82993
83075
  container.innerHTML = "";
82994
- const offset2 = data.offset ?? (kind === "footer" ? pageEl.clientHeight - data.height : 0);
83076
+ const baseOffset = data.offset ?? (kind === "footer" ? pageEl.clientHeight - data.height : 0);
82995
83077
  const marginLeft = data.marginLeft ?? 0;
82996
83078
  const marginRight = page.margins?.right ?? 0;
83079
+ let effectiveHeight = data.height;
83080
+ let effectiveOffset = baseOffset;
83081
+ if (kind === "footer" && typeof data.contentHeight === "number" && Number.isFinite(data.contentHeight) && data.contentHeight > 0 && data.contentHeight > data.height) {
83082
+ effectiveHeight = data.contentHeight;
83083
+ effectiveOffset = baseOffset - (data.contentHeight - data.height);
83084
+ }
82997
83085
  container.style.position = "absolute";
82998
83086
  container.style.left = `${marginLeft}px`;
82999
83087
  if (typeof data.contentWidth === "number") {
@@ -83002,8 +83090,8 @@ ${l}
83002
83090
  container.style.width = `calc(100% - ${marginLeft + marginRight}px)`;
83003
83091
  }
83004
83092
  container.style.pointerEvents = "none";
83005
- container.style.height = `${data.height}px`;
83006
- container.style.top = `${Math.max(0, offset2)}px`;
83093
+ container.style.height = `${effectiveHeight}px`;
83094
+ container.style.top = `${Math.max(0, effectiveOffset)}px`;
83007
83095
  container.style.zIndex = "1";
83008
83096
  container.style.overflow = "visible";
83009
83097
  let footerYOffset = 0;
@@ -83012,7 +83100,7 @@ ${l}
83012
83100
  const fragHeight = "height" in f2 && typeof f2.height === "number" ? f2.height : this.estimateFragmentHeight(f2);
83013
83101
  return Math.max(max2, f2.y + Math.max(0, fragHeight));
83014
83102
  }, 0);
83015
- footerYOffset = Math.max(0, data.height - contentHeight);
83103
+ footerYOffset = Math.max(0, effectiveHeight - contentHeight);
83016
83104
  }
83017
83105
  const context = {
83018
83106
  pageNumber: page.number,
@@ -85502,6 +85590,25 @@ ${l}
85502
85590
  hash2 = hashNumber(hash2, cellBlocks.length);
85503
85591
  hash2 = hashNumber(hash2, cell2.rowSpan ?? 1);
85504
85592
  hash2 = hashNumber(hash2, cell2.colSpan ?? 1);
85593
+ if (cell2.attrs) {
85594
+ const cellAttrs = cell2.attrs;
85595
+ if (cellAttrs.borders) {
85596
+ hash2 = hashString(hash2, hashCellBorders$1(cellAttrs.borders));
85597
+ }
85598
+ if (cellAttrs.padding) {
85599
+ const p2 = cellAttrs.padding;
85600
+ hash2 = hashNumber(hash2, p2.top ?? 0);
85601
+ hash2 = hashNumber(hash2, p2.right ?? 0);
85602
+ hash2 = hashNumber(hash2, p2.bottom ?? 0);
85603
+ hash2 = hashNumber(hash2, p2.left ?? 0);
85604
+ }
85605
+ if (cellAttrs.verticalAlign) {
85606
+ hash2 = hashString(hash2, cellAttrs.verticalAlign);
85607
+ }
85608
+ if (cellAttrs.background) {
85609
+ hash2 = hashString(hash2, cellAttrs.background);
85610
+ }
85611
+ }
85505
85612
  for (const cellBlock of cellBlocks) {
85506
85613
  hash2 = hashString(hash2, cellBlock?.kind ?? "unknown");
85507
85614
  if (cellBlock?.kind === "paragraph") {
@@ -85547,6 +85654,18 @@ ${l}
85547
85654
  }
85548
85655
  }
85549
85656
  }
85657
+ if (tableBlock.attrs) {
85658
+ const tblAttrs = tableBlock.attrs;
85659
+ if (tblAttrs.borders) {
85660
+ hash2 = hashString(hash2, hashTableBorders$1(tblAttrs.borders));
85661
+ }
85662
+ if (tblAttrs.borderCollapse) {
85663
+ hash2 = hashString(hash2, tblAttrs.borderCollapse);
85664
+ }
85665
+ if (tblAttrs.cellSpacing !== void 0) {
85666
+ hash2 = hashNumber(hash2, tblAttrs.cellSpacing);
85667
+ }
85668
+ }
85550
85669
  return [block.id, tableBlock.rows.length, hash2.toString(16)].join("|");
85551
85670
  }
85552
85671
  return block.id;
@@ -85880,6 +85999,7 @@ ${l}
85880
85999
  const painter = new DomPainter(options.blocks, options.measures, {
85881
86000
  pageStyles: options.pageStyles,
85882
86001
  layoutMode: options.layoutMode,
86002
+ pageGap: options.pageGap,
85883
86003
  headerProvider: options.headerProvider,
85884
86004
  footerProvider: options.footerProvider,
85885
86005
  virtualization: options.virtualization,
@@ -86298,7 +86418,7 @@ ${l}
86298
86418
  return false;
86299
86419
  }
86300
86420
  const wordLayout = getWordLayoutConfig(block);
86301
- const hasListAttrs = block.attrs?.listItem != null || wordLayout?.marker != null;
86421
+ const hasListAttrs = block.attrs?.listItem != null || block.attrs?.numberingProperties != null || wordLayout?.marker != null;
86302
86422
  if (hasListAttrs) {
86303
86423
  return true;
86304
86424
  }
@@ -86728,7 +86848,7 @@ ${l}
86728
86848
  });
86729
86849
  return nextSectionPropsAtBreak;
86730
86850
  }
86731
- function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight = 0) {
86851
+ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight = 0, maxFooterContentHeight = 0) {
86732
86852
  const next2 = { ...state2 };
86733
86853
  const calcRequiredTopMargin = (headerDistance, baseTop) => {
86734
86854
  if (maxHeaderContentHeight > 0) {
@@ -86736,6 +86856,12 @@ ${l}
86736
86856
  }
86737
86857
  return Math.max(baseTop, headerDistance);
86738
86858
  };
86859
+ const calcRequiredBottomMargin = (footerDistance, baseBottom) => {
86860
+ if (maxFooterContentHeight > 0) {
86861
+ return Math.max(baseBottom, footerDistance + maxFooterContentHeight);
86862
+ }
86863
+ return Math.max(baseBottom, footerDistance);
86864
+ };
86739
86865
  if (block.attrs?.isFirstSection && !next2.hasAnyPages) {
86740
86866
  if (block.pageSize) {
86741
86867
  next2.activePageSize = { w: block.pageSize.w, h: block.pageSize.h };
@@ -86756,7 +86882,7 @@ ${l}
86756
86882
  const footerDistance = Math.max(0, block.margins.footer);
86757
86883
  next2.activeFooterDistance = footerDistance;
86758
86884
  next2.pendingFooterDistance = footerDistance;
86759
- next2.activeBottomMargin = Math.max(baseMargins.bottom, footerDistance);
86885
+ next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
86760
86886
  next2.pendingBottomMargin = next2.activeBottomMargin;
86761
86887
  }
86762
86888
  if (block.columns) {
@@ -86779,8 +86905,14 @@ ${l}
86779
86905
  next2.pendingTopMargin = nextTop;
86780
86906
  next2.pendingHeaderDistance = nextHeader;
86781
86907
  }
86782
- next2.pendingBottomMargin = typeof footerPx === "number" ? Math.max(baseMargins.bottom, footerPx) : nextBottom;
86783
- next2.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
86908
+ if (typeof footerPx === "number") {
86909
+ const newFooterDist = Math.max(0, footerPx);
86910
+ next2.pendingFooterDistance = newFooterDist;
86911
+ next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
86912
+ } else {
86913
+ next2.pendingBottomMargin = nextBottom;
86914
+ next2.pendingFooterDistance = nextFooter;
86915
+ }
86784
86916
  if (block.pageSize) {
86785
86917
  next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
86786
86918
  }
@@ -88380,7 +88512,7 @@ ${l}
88380
88512
  if (contentWidth <= 0) {
88381
88513
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
88382
88514
  }
88383
- const validateHeaderHeight = (height) => {
88515
+ const validateContentHeight = (height) => {
88384
88516
  if (height === void 0) return 0;
88385
88517
  if (!Number.isFinite(height) || height < 0) return 0;
88386
88518
  return height;
@@ -88388,15 +88520,25 @@ ${l}
88388
88520
  const headerContentHeights = options.headerContentHeights;
88389
88521
  const maxHeaderContentHeight = headerContentHeights ? Math.max(
88390
88522
  0,
88391
- validateHeaderHeight(headerContentHeights.default),
88392
- validateHeaderHeight(headerContentHeights.first),
88393
- validateHeaderHeight(headerContentHeights.even),
88394
- validateHeaderHeight(headerContentHeights.odd)
88523
+ validateContentHeight(headerContentHeights.default),
88524
+ validateContentHeight(headerContentHeights.first),
88525
+ validateContentHeight(headerContentHeights.even),
88526
+ validateContentHeight(headerContentHeights.odd)
88395
88527
  ) : 0;
88396
88528
  const headerDistance = margins.header ?? margins.top;
88397
88529
  const effectiveTopMargin = maxHeaderContentHeight > 0 ? Math.max(margins.top, headerDistance + maxHeaderContentHeight) : margins.top;
88530
+ const footerContentHeights = options.footerContentHeights;
88531
+ const maxFooterContentHeight = footerContentHeights ? Math.max(
88532
+ 0,
88533
+ validateContentHeight(footerContentHeights.default),
88534
+ validateContentHeight(footerContentHeights.first),
88535
+ validateContentHeight(footerContentHeights.even),
88536
+ validateContentHeight(footerContentHeights.odd)
88537
+ ) : 0;
88538
+ const footerDistance = margins.footer ?? margins.bottom;
88539
+ const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
88398
88540
  let activeTopMargin = effectiveTopMargin;
88399
- let activeBottomMargin = margins.bottom;
88541
+ let activeBottomMargin = effectiveBottomMargin;
88400
88542
  let pendingTopMargin = null;
88401
88543
  let pendingBottomMargin = null;
88402
88544
  let activeHeaderDistance = margins.header ?? margins.top;
@@ -88419,7 +88561,7 @@ ${l}
88419
88561
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks2);
88420
88562
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
88421
88563
  if (typeof scheduleSectionBreak === "function") {
88422
- return scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight);
88564
+ return scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight, maxFooterContentHeight);
88423
88565
  }
88424
88566
  const next2 = { ...state2 };
88425
88567
  if (block.attrs?.isFirstSection && !next2.hasAnyPages) {
@@ -88440,10 +88582,11 @@ ${l}
88440
88582
  next2.pendingTopMargin = next2.activeTopMargin;
88441
88583
  }
88442
88584
  if (block.margins?.footer !== void 0) {
88443
- const footerDistance = Math.max(0, block.margins.footer);
88444
- next2.activeFooterDistance = footerDistance;
88445
- next2.pendingFooterDistance = footerDistance;
88446
- next2.activeBottomMargin = Math.max(baseMargins.bottom, footerDistance);
88585
+ const footerDistance2 = Math.max(0, block.margins.footer);
88586
+ next2.activeFooterDistance = footerDistance2;
88587
+ next2.pendingFooterDistance = footerDistance2;
88588
+ const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
88589
+ next2.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
88447
88590
  next2.pendingBottomMargin = next2.activeBottomMargin;
88448
88591
  }
88449
88592
  if (block.columns) {
@@ -88488,7 +88631,13 @@ ${l}
88488
88631
  } else {
88489
88632
  next2.pendingTopMargin = nextTop;
88490
88633
  }
88491
- next2.pendingBottomMargin = typeof footerPx === "number" ? Math.max(baseMargins.bottom, footerPx) : nextBottom;
88634
+ if (typeof footerPx === "number") {
88635
+ const sectionFooter = next2.pendingFooterDistance;
88636
+ const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
88637
+ next2.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
88638
+ } else {
88639
+ next2.pendingBottomMargin = nextBottom;
88640
+ }
88492
88641
  if (block.pageSize) next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
88493
88642
  if (block.orientation) next2.pendingOrientation = block.orientation;
88494
88643
  const sectionType = block.type ?? "continuous";
@@ -89255,6 +89404,49 @@ ${l}
89255
89404
  if (borders.left) parts.push(`l:[${hashParagraphBorder(borders.left)}]`);
89256
89405
  return parts.join(";");
89257
89406
  };
89407
+ function isNoneBorder(value) {
89408
+ return typeof value === "object" && value !== null && "none" in value && value.none === true;
89409
+ }
89410
+ function isBorderSpec(value) {
89411
+ return typeof value === "object" && value !== null && !("none" in value);
89412
+ }
89413
+ const hashBorderSpec = (border) => {
89414
+ const parts = [];
89415
+ if (border.style !== void 0) parts.push(`s:${border.style}`);
89416
+ if (border.width !== void 0) parts.push(`w:${border.width}`);
89417
+ if (border.color !== void 0) parts.push(`c:${border.color}`);
89418
+ if (border.space !== void 0) parts.push(`sp:${border.space}`);
89419
+ return parts.join(",");
89420
+ };
89421
+ const hashTableBorderValue = (borderValue) => {
89422
+ if (borderValue === void 0) return "";
89423
+ if (borderValue === null) return "null";
89424
+ if (isNoneBorder(borderValue)) return "none";
89425
+ if (isBorderSpec(borderValue)) {
89426
+ return hashBorderSpec(borderValue);
89427
+ }
89428
+ return "";
89429
+ };
89430
+ const hashTableBorders = (borders) => {
89431
+ if (!borders) return "";
89432
+ const parts = [];
89433
+ if (borders.top !== void 0) parts.push(`t:[${hashTableBorderValue(borders.top)}]`);
89434
+ if (borders.right !== void 0) parts.push(`r:[${hashTableBorderValue(borders.right)}]`);
89435
+ if (borders.bottom !== void 0) parts.push(`b:[${hashTableBorderValue(borders.bottom)}]`);
89436
+ if (borders.left !== void 0) parts.push(`l:[${hashTableBorderValue(borders.left)}]`);
89437
+ if (borders.insideH !== void 0) parts.push(`ih:[${hashTableBorderValue(borders.insideH)}]`);
89438
+ if (borders.insideV !== void 0) parts.push(`iv:[${hashTableBorderValue(borders.insideV)}]`);
89439
+ return parts.join(";");
89440
+ };
89441
+ const hashCellBorders = (borders) => {
89442
+ if (!borders) return "";
89443
+ const parts = [];
89444
+ if (borders.top) parts.push(`t:[${hashBorderSpec(borders.top)}]`);
89445
+ if (borders.right) parts.push(`r:[${hashBorderSpec(borders.right)}]`);
89446
+ if (borders.bottom) parts.push(`b:[${hashBorderSpec(borders.bottom)}]`);
89447
+ if (borders.left) parts.push(`l:[${hashBorderSpec(borders.left)}]`);
89448
+ return parts.join(";");
89449
+ };
89258
89450
  const MAX_CACHE_SIZE$1 = 1e4;
89259
89451
  const BYTES_PER_ENTRY_ESTIMATE = 5e3;
89260
89452
  const NORMALIZED_WHITESPACE = /\s+/g;
@@ -89282,6 +89474,26 @@ ${l}
89282
89474
  continue;
89283
89475
  }
89284
89476
  for (const cell2 of row2.cells) {
89477
+ if (cell2.attrs) {
89478
+ const cellAttrs = cell2.attrs;
89479
+ const cellAttrParts = [];
89480
+ if (cellAttrs.borders) {
89481
+ cellAttrParts.push(`cb:${hashCellBorders(cellAttrs.borders)}`);
89482
+ }
89483
+ if (cellAttrs.padding) {
89484
+ const p2 = cellAttrs.padding;
89485
+ cellAttrParts.push(`cp:${p2.top ?? 0}:${p2.right ?? 0}:${p2.bottom ?? 0}:${p2.left ?? 0}`);
89486
+ }
89487
+ if (cellAttrs.verticalAlign) {
89488
+ cellAttrParts.push(`va:${cellAttrs.verticalAlign}`);
89489
+ }
89490
+ if (cellAttrs.background) {
89491
+ cellAttrParts.push(`bg:${cellAttrs.background}`);
89492
+ }
89493
+ if (cellAttrParts.length > 0) {
89494
+ cellHashes.push(`ca:${cellAttrParts.join(":")}`);
89495
+ }
89496
+ }
89285
89497
  const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
89286
89498
  for (const cellBlock of cellBlocks) {
89287
89499
  const paragraphBlock = cellBlock;
@@ -89348,8 +89560,25 @@ ${l}
89348
89560
  }
89349
89561
  }
89350
89562
  }
89563
+ let tableAttrsKey = "";
89564
+ if (tableBlock.attrs) {
89565
+ const tblAttrs = tableBlock.attrs;
89566
+ const tableAttrParts = [];
89567
+ if (tblAttrs.borders) {
89568
+ tableAttrParts.push(`tb:${hashTableBorders(tblAttrs.borders)}`);
89569
+ }
89570
+ if (tblAttrs.borderCollapse) {
89571
+ tableAttrParts.push(`bc:${tblAttrs.borderCollapse}`);
89572
+ }
89573
+ if (tblAttrs.cellSpacing !== void 0) {
89574
+ tableAttrParts.push(`cs:${tblAttrs.cellSpacing}`);
89575
+ }
89576
+ if (tableAttrParts.length > 0) {
89577
+ tableAttrsKey = `|ta:${tableAttrParts.join(":")}`;
89578
+ }
89579
+ }
89351
89580
  const contentHash = cellHashes.join("|");
89352
- return `${block.id}:table:${contentHash}`;
89581
+ return `${block.id}:table:${contentHash}${tableAttrsKey}`;
89353
89582
  }
89354
89583
  if (block.kind !== "paragraph") return block.id;
89355
89584
  const trackedMode = block.attrs && "trackedChangesMode" in block.attrs && block.attrs.trackedChangesMode || "review";
@@ -90871,17 +91100,67 @@ ${l}
90871
91100
  for (const [type2, value] of Object.entries(preHeaderLayouts)) {
90872
91101
  if (!isValidHeaderType(type2)) continue;
90873
91102
  if (value?.layout && typeof value.layout.height === "number") {
90874
- headerContentHeights[type2] = value.layout.height;
91103
+ const height = value.layout.height;
91104
+ if (Number.isFinite(height) && height >= 0) {
91105
+ headerContentHeights[type2] = height;
91106
+ }
90875
91107
  }
90876
91108
  }
90877
91109
  const hfPreEnd = performance.now();
90878
91110
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
90879
91111
  }
91112
+ let footerContentHeights;
91113
+ if (headerFooter?.constraints && headerFooter.footerBlocks) {
91114
+ const footerPreStart = performance.now();
91115
+ const measureFn = headerFooter.measure ?? measureBlock2;
91116
+ if (!headerFooter.headerBlocks) {
91117
+ invalidateHeaderFooterCache(
91118
+ headerMeasureCache,
91119
+ headerFooterCacheState,
91120
+ headerFooter.headerBlocks,
91121
+ headerFooter.footerBlocks,
91122
+ headerFooter.constraints,
91123
+ options.sectionMetadata
91124
+ );
91125
+ }
91126
+ const FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
91127
+ try {
91128
+ const preFooterLayouts = await layoutHeaderFooterWithCache(
91129
+ headerFooter.footerBlocks,
91130
+ headerFooter.constraints,
91131
+ measureFn,
91132
+ headerMeasureCache,
91133
+ FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
91134
+ void 0
91135
+ // No page resolver needed for height calculation
91136
+ );
91137
+ const isValidFooterType = (key2) => {
91138
+ return ["default", "first", "even", "odd"].includes(key2);
91139
+ };
91140
+ footerContentHeights = {};
91141
+ for (const [type2, value] of Object.entries(preFooterLayouts)) {
91142
+ if (!isValidFooterType(type2)) continue;
91143
+ if (value?.layout && typeof value.layout.height === "number") {
91144
+ const height = value.layout.height;
91145
+ if (Number.isFinite(height) && height >= 0) {
91146
+ footerContentHeights[type2] = height;
91147
+ }
91148
+ }
91149
+ }
91150
+ } catch (error) {
91151
+ console.error("[Layout] Footer pre-layout failed:", error);
91152
+ footerContentHeights = void 0;
91153
+ }
91154
+ const footerPreEnd = performance.now();
91155
+ perfLog(`[Perf] 4.1.6 Pre-layout footers for height: ${(footerPreEnd - footerPreStart).toFixed(2)}ms`);
91156
+ }
90880
91157
  const layoutStart = performance.now();
90881
91158
  let layout = layoutDocument(nextBlocks, measures, {
90882
91159
  ...options,
90883
91160
  headerContentHeights,
90884
91161
  // Pass header heights to prevent overlap
91162
+ footerContentHeights,
91163
+ // Pass footer heights to prevent overlap
90885
91164
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
90886
91165
  });
90887
91166
  const layoutEnd = performance.now();
@@ -90930,6 +91209,8 @@ ${l}
90930
91209
  ...options,
90931
91210
  headerContentHeights,
90932
91211
  // Pass header heights to prevent overlap
91212
+ footerContentHeights,
91213
+ // Pass footer heights to prevent overlap
90933
91214
  remeasureParagraph: (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)
90934
91215
  });
90935
91216
  const relayoutEnd = performance.now();
@@ -91096,6 +91377,285 @@ ${l}
91096
91377
  }
91097
91378
  return updatedMeasures;
91098
91379
  }
91380
+ class PageGeometryHelper {
91381
+ /**
91382
+ * Creates a new PageGeometryHelper instance.
91383
+ *
91384
+ * @param config - Page geometry configuration
91385
+ */
91386
+ constructor(config2) {
91387
+ this.cache = null;
91388
+ this.config = config2;
91389
+ }
91390
+ /**
91391
+ * Updates the layout and invalidates the cache.
91392
+ *
91393
+ * Call this whenever the layout changes (new pages, different heights, etc.)
91394
+ *
91395
+ * @param layout - New layout data
91396
+ * @param pageGap - Optional new page gap (if not provided, uses current gap)
91397
+ */
91398
+ updateLayout(layout, pageGap) {
91399
+ this.config.layout = layout;
91400
+ if (pageGap !== void 0) {
91401
+ this.config.pageGap = pageGap;
91402
+ }
91403
+ this.cache = null;
91404
+ }
91405
+ /**
91406
+ * Updates the page gap and invalidates the cache.
91407
+ *
91408
+ * @param pageGap - New gap between pages in pixels
91409
+ */
91410
+ updatePageGap(pageGap) {
91411
+ if (this.config.pageGap !== pageGap) {
91412
+ this.config.pageGap = pageGap;
91413
+ this.cache = null;
91414
+ }
91415
+ }
91416
+ /**
91417
+ * Gets the cumulative Y position (top edge) of a page in container space.
91418
+ *
91419
+ * The returned value is the distance from the top of the container to the
91420
+ * top of the specified page, accounting for all previous pages and gaps.
91421
+ *
91422
+ * @param pageIndex - Zero-based page index
91423
+ * @returns Y position in pixels, or 0 if page index is invalid
91424
+ *
91425
+ * @example
91426
+ * ```typescript
91427
+ * // Get Y position of page 0 (first page)
91428
+ * const y0 = helper.getPageTop(0); // Returns 0
91429
+ *
91430
+ * // Get Y position of page 2 (third page)
91431
+ * // Assumes page 0 height = 1000, page 1 height = 1200, gap = 24
91432
+ * const y2 = helper.getPageTop(2); // Returns 1000 + 24 + 1200 + 24 = 2248
91433
+ * ```
91434
+ */
91435
+ getPageTop(pageIndex) {
91436
+ this.ensureCache();
91437
+ if (pageIndex < 0 || pageIndex >= this.cache.cumulativeY.length) {
91438
+ return 0;
91439
+ }
91440
+ return this.cache.cumulativeY[pageIndex];
91441
+ }
91442
+ /**
91443
+ * Gets the height of a specific page.
91444
+ *
91445
+ * Uses per-page height if available (from layout.pages[i].size?.h),
91446
+ * otherwise falls back to layout.pageSize.h.
91447
+ *
91448
+ * @param pageIndex - Zero-based page index
91449
+ * @returns Page height in pixels, or 0 if page index is invalid
91450
+ *
91451
+ * @example
91452
+ * ```typescript
91453
+ * const height = helper.getPageHeight(0); // Returns page-specific height
91454
+ * ```
91455
+ */
91456
+ getPageHeight(pageIndex) {
91457
+ this.ensureCache();
91458
+ if (pageIndex < 0 || pageIndex >= this.cache.pageHeights.length) {
91459
+ return 0;
91460
+ }
91461
+ return this.cache.pageHeights[pageIndex];
91462
+ }
91463
+ /**
91464
+ * Gets the gap between pages.
91465
+ *
91466
+ * @returns Gap in pixels
91467
+ *
91468
+ * @example
91469
+ * ```typescript
91470
+ * const gap = helper.getPageGap(); // Returns 24
91471
+ * ```
91472
+ */
91473
+ getPageGap() {
91474
+ this.ensureCache();
91475
+ return this.cache.pageGap;
91476
+ }
91477
+ /**
91478
+ * Gets the total height of all pages including gaps.
91479
+ *
91480
+ * Total height = sum of all page heights + (pageCount - 1) * gap
91481
+ *
91482
+ * @returns Total height in pixels
91483
+ *
91484
+ * @example
91485
+ * ```typescript
91486
+ * // 3 pages: heights [1000, 1200, 1000], gap = 24
91487
+ * const total = helper.getTotalHeight();
91488
+ * // Returns 1000 + 24 + 1200 + 24 + 1000 = 3248
91489
+ * ```
91490
+ */
91491
+ getTotalHeight() {
91492
+ this.ensureCache();
91493
+ return this.cache.totalHeight;
91494
+ }
91495
+ /**
91496
+ * Gets the number of pages in the layout.
91497
+ *
91498
+ * @returns Page count
91499
+ */
91500
+ getPageCount() {
91501
+ return this.config.layout.pages.length;
91502
+ }
91503
+ /**
91504
+ * Finds the page index containing a given Y coordinate.
91505
+ *
91506
+ * This performs a linear search through cached cumulative positions.
91507
+ * For large documents, consider adding binary search optimization.
91508
+ *
91509
+ * @param containerY - Y coordinate in container space
91510
+ * @returns Page index, or null if Y is outside all pages
91511
+ *
91512
+ * @example
91513
+ * ```typescript
91514
+ * // Find which page contains Y = 1500
91515
+ * const pageIndex = helper.getPageIndexAtY(1500);
91516
+ * // Returns 1 (second page) if first page ends at Y=1024
91517
+ * ```
91518
+ */
91519
+ getPageIndexAtY(containerY) {
91520
+ this.ensureCache();
91521
+ const cache2 = this.cache;
91522
+ for (let i2 = 0; i2 < cache2.cumulativeY.length; i2++) {
91523
+ const pageTop = cache2.cumulativeY[i2];
91524
+ const pageBottom = pageTop + cache2.pageHeights[i2];
91525
+ if (containerY >= pageTop && containerY < pageBottom) {
91526
+ return i2;
91527
+ }
91528
+ }
91529
+ return null;
91530
+ }
91531
+ /**
91532
+ * Finds the nearest page index to a given Y coordinate (snap-to-nearest).
91533
+ *
91534
+ * Returns the page containing Y when inside a page; otherwise returns the
91535
+ * closest page based on distance to page center. Useful for dragging through
91536
+ * page gaps where getPageIndexAtY would return null.
91537
+ *
91538
+ * @param containerY - Y coordinate in container space
91539
+ * @returns Nearest page index, or null if there are no pages
91540
+ */
91541
+ getNearestPageIndex(containerY) {
91542
+ this.ensureCache();
91543
+ const cache2 = this.cache;
91544
+ const pageCount = cache2.pageHeights.length;
91545
+ if (pageCount === 0) return null;
91546
+ const direct = this.getPageIndexAtY(containerY);
91547
+ if (direct !== null) return direct;
91548
+ let nearestIndex = 0;
91549
+ let nearestDistance = Infinity;
91550
+ for (let i2 = 0; i2 < pageCount; i2++) {
91551
+ const top2 = cache2.cumulativeY[i2];
91552
+ const height = cache2.pageHeights[i2];
91553
+ const center = top2 + height / 2;
91554
+ const distance = Math.abs(containerY - center);
91555
+ if (distance < nearestDistance) {
91556
+ nearestDistance = distance;
91557
+ nearestIndex = i2;
91558
+ }
91559
+ }
91560
+ return nearestIndex;
91561
+ }
91562
+ /**
91563
+ * Ensures the cache is built and up-to-date.
91564
+ * Validates cache state and rebuilds if needed.
91565
+ * @private
91566
+ * @throws Never throws - handles errors gracefully with fallback values
91567
+ */
91568
+ ensureCache() {
91569
+ if (this.cache !== null) {
91570
+ if (!Array.isArray(this.cache.cumulativeY) || !Array.isArray(this.cache.pageHeights)) {
91571
+ console.warn("[PageGeometryHelper] Cache corruption detected, rebuilding cache");
91572
+ this.cache = null;
91573
+ } else {
91574
+ return;
91575
+ }
91576
+ }
91577
+ this.buildCache();
91578
+ }
91579
+ /**
91580
+ * Builds the geometry cache from current layout data.
91581
+ * Handles errors gracefully by providing fallback values.
91582
+ * @private
91583
+ * @throws Never throws - catches all errors and provides safe defaults
91584
+ */
91585
+ buildCache() {
91586
+ try {
91587
+ const layout = this.config.layout;
91588
+ if (!layout || !Array.isArray(layout.pages)) {
91589
+ throw new Error("Invalid layout: missing or invalid pages array");
91590
+ }
91591
+ const pageGap = this.config.pageGap ?? layout.pageGap ?? 0;
91592
+ const pageCount = layout.pages.length;
91593
+ if (!Number.isFinite(pageGap) || pageGap < 0) {
91594
+ throw new Error(`Invalid pageGap: ${pageGap} (must be non-negative finite number)`);
91595
+ }
91596
+ const cumulativeY = new Array(pageCount);
91597
+ const pageHeights = new Array(pageCount);
91598
+ let currentY = 0;
91599
+ for (let i2 = 0; i2 < pageCount; i2++) {
91600
+ const page = layout.pages[i2];
91601
+ if (!page) {
91602
+ throw new Error(`Invalid page at index ${i2}: page is null or undefined`);
91603
+ }
91604
+ const pageHeight = page.size?.h ?? layout.pageSize.h;
91605
+ if (!Number.isFinite(pageHeight) || pageHeight < 0) {
91606
+ throw new Error(`Invalid page height at index ${i2}: ${pageHeight} (must be non-negative finite number)`);
91607
+ }
91608
+ cumulativeY[i2] = currentY;
91609
+ pageHeights[i2] = pageHeight;
91610
+ currentY += pageHeight;
91611
+ if (i2 < pageCount - 1) {
91612
+ currentY += pageGap;
91613
+ }
91614
+ }
91615
+ const totalHeight = currentY;
91616
+ this.cache = {
91617
+ cumulativeY,
91618
+ pageHeights,
91619
+ pageGap,
91620
+ totalHeight,
91621
+ layoutVersion: 0
91622
+ // Placeholder for future version tracking
91623
+ };
91624
+ } catch (error) {
91625
+ const errorMessage = error instanceof Error ? error.message : String(error);
91626
+ console.error(`[PageGeometryHelper] Cache build failed: ${errorMessage}. Using fallback empty cache.`);
91627
+ this.cache = {
91628
+ cumulativeY: [],
91629
+ pageHeights: [],
91630
+ pageGap: 0,
91631
+ totalHeight: 0,
91632
+ layoutVersion: 0
91633
+ };
91634
+ }
91635
+ }
91636
+ /**
91637
+ * Clears the cache, forcing recalculation on next access.
91638
+ * Useful for testing or manual cache invalidation.
91639
+ */
91640
+ clearCache() {
91641
+ this.cache = null;
91642
+ }
91643
+ /**
91644
+ * Gets debug information about the current cache state.
91645
+ * @internal
91646
+ */
91647
+ getDebugInfo() {
91648
+ this.ensureCache();
91649
+ return {
91650
+ isCached: this.cache !== null,
91651
+ pageCount: this.config.layout.pages.length,
91652
+ pageGap: this.cache.pageGap,
91653
+ totalHeight: this.cache.totalHeight,
91654
+ cumulativeY: [...this.cache.cumulativeY],
91655
+ pageHeights: [...this.cache.pageHeights]
91656
+ };
91657
+ }
91658
+ }
91099
91659
  var Priority = /* @__PURE__ */ ((Priority2) => {
91100
91660
  Priority2[Priority2["P0"] = 0] = "P0";
91101
91661
  Priority2[Priority2["P1"] = 1] = "P1";
@@ -91389,18 +91949,41 @@ ${l}
91389
91949
  const effectiveEndA = endA ?? startA + 1;
91390
91950
  return effectiveEndA > startB && startA < endB;
91391
91951
  };
91392
- function hitTestPage(layout, point2) {
91952
+ function hitTestPage(layout, point2, geometryHelper) {
91953
+ if (geometryHelper) {
91954
+ const pageIndex = geometryHelper.getPageIndexAtY(point2.y);
91955
+ if (pageIndex !== null) {
91956
+ return { pageIndex, page: layout.pages[pageIndex] };
91957
+ }
91958
+ const nearest = geometryHelper.getNearestPageIndex(point2.y);
91959
+ if (nearest !== null) {
91960
+ return { pageIndex: nearest, page: layout.pages[nearest] };
91961
+ }
91962
+ return null;
91963
+ }
91393
91964
  const pageGap = layout.pageGap ?? 0;
91394
91965
  let cursorY = 0;
91966
+ let nearestIndex = null;
91967
+ let nearestDistance = Infinity;
91395
91968
  for (let pageIndex = 0; pageIndex < layout.pages.length; pageIndex += 1) {
91396
91969
  const page = layout.pages[pageIndex];
91970
+ const pageHeight = page.size?.h ?? layout.pageSize.h;
91397
91971
  const top2 = cursorY;
91398
- const bottom2 = top2 + layout.pageSize.h;
91972
+ const bottom2 = top2 + pageHeight;
91399
91973
  if (point2.y >= top2 && point2.y < bottom2) {
91400
91974
  return { pageIndex, page };
91401
91975
  }
91976
+ const center = top2 + pageHeight / 2;
91977
+ const distance = Math.abs(point2.y - center);
91978
+ if (distance < nearestDistance) {
91979
+ nearestDistance = distance;
91980
+ nearestIndex = pageIndex;
91981
+ }
91402
91982
  cursorY = bottom2 + pageGap;
91403
91983
  }
91984
+ if (nearestIndex !== null) {
91985
+ return { pageIndex: nearestIndex, page: layout.pages[nearestIndex] };
91986
+ }
91404
91987
  return null;
91405
91988
  }
91406
91989
  function hitTestFragment(layout, pageHit, blocks2, measures, point2) {
@@ -91561,7 +92144,7 @@ ${l}
91561
92144
  }
91562
92145
  return null;
91563
92146
  };
91564
- function clickToPosition(layout, blocks2, measures, containerPoint, domContainer, clientX, clientY) {
92147
+ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer, clientX, clientY, geometryHelper) {
91565
92148
  logClickStage("log", "entry", {
91566
92149
  pages: layout.pages.length
91567
92150
  });
@@ -91604,75 +92187,132 @@ ${l}
91604
92187
  return { pos: domPos, blockId: "", pageIndex: 0, column: 0, lineIndex: -1 };
91605
92188
  }
91606
92189
  }
91607
- const pageHit = hitTestPage(layout, containerPoint);
92190
+ const pageHit = hitTestPage(layout, containerPoint, geometryHelper);
91608
92191
  if (!pageHit) {
91609
92192
  return null;
91610
92193
  }
91611
- const pageGap = layout.pageGap ?? 0;
92194
+ const pageTopY = geometryHelper ? geometryHelper.getPageTop(pageHit.pageIndex) : calculatePageTopFallback(layout, pageHit.pageIndex);
91612
92195
  const pageRelativePoint = {
91613
92196
  x: containerPoint.x,
91614
- y: containerPoint.y - pageHit.pageIndex * (layout.pageSize.h + pageGap)
92197
+ y: containerPoint.y - pageTopY
91615
92198
  };
91616
92199
  logClickStage("log", "page-hit", {
91617
92200
  pageIndex: pageHit.pageIndex
91618
92201
  });
91619
- const fragmentHit = hitTestFragment(layout, pageHit, blocks2, measures, pageRelativePoint);
92202
+ let fragmentHit = hitTestFragment(layout, pageHit, blocks2, measures, pageRelativePoint);
92203
+ if (!fragmentHit) {
92204
+ const page = pageHit.page;
92205
+ const fragments = page.fragments.filter(
92206
+ (f2) => f2 != null && typeof f2 === "object"
92207
+ );
92208
+ if (fragments.length > 0) {
92209
+ let nearest = null;
92210
+ let nearestDist = Infinity;
92211
+ for (const frag of fragments) {
92212
+ const top2 = frag.y;
92213
+ const bottom2 = frag.y + frag.height;
92214
+ let dist2;
92215
+ if (pageRelativePoint.y < top2) {
92216
+ dist2 = top2 - pageRelativePoint.y;
92217
+ } else if (pageRelativePoint.y > bottom2) {
92218
+ dist2 = pageRelativePoint.y - bottom2;
92219
+ } else {
92220
+ dist2 = 0;
92221
+ }
92222
+ if (dist2 < nearestDist) {
92223
+ nearestDist = dist2;
92224
+ nearest = frag;
92225
+ }
92226
+ }
92227
+ if (nearest) {
92228
+ const blockIndex = findBlockIndexByFragmentId(blocks2, nearest.blockId);
92229
+ if (blockIndex !== -1) {
92230
+ const block = blocks2[blockIndex];
92231
+ const measure = measures[blockIndex];
92232
+ if (block && measure) {
92233
+ fragmentHit = {
92234
+ fragment: nearest,
92235
+ block,
92236
+ measure,
92237
+ pageIndex: pageHit.pageIndex,
92238
+ pageY: 0
92239
+ };
92240
+ }
92241
+ }
92242
+ }
92243
+ }
92244
+ }
91620
92245
  if (fragmentHit) {
91621
92246
  const { fragment, block, measure, pageIndex, pageY } = fragmentHit;
91622
- if (fragment.kind !== "para" || measure.kind !== "paragraph" || block.kind !== "paragraph") {
91623
- logClickStage("warn", "fragment-type-mismatch", {
91624
- fragmentKind: fragment.kind,
91625
- measureKind: measure.kind,
91626
- blockKind: block.kind
92247
+ if (fragment.kind === "para" && measure.kind === "paragraph" && block.kind === "paragraph") {
92248
+ const lineIndex = findLineIndexAtY(measure, pageY, fragment.fromLine, fragment.toLine);
92249
+ if (lineIndex == null) {
92250
+ logClickStage("warn", "no-line", {
92251
+ blockId: fragment.blockId
92252
+ });
92253
+ return null;
92254
+ }
92255
+ const line = measure.lines[lineIndex];
92256
+ const isRTL = isRtlBlock(block);
92257
+ const indentLeft = typeof block.attrs?.indent?.left === "number" ? block.attrs.indent.left : 0;
92258
+ const indentRight = typeof block.attrs?.indent?.right === "number" ? block.attrs.indent.right : 0;
92259
+ const paraIndentLeft = Number.isFinite(indentLeft) ? indentLeft : 0;
92260
+ const paraIndentRight = Number.isFinite(indentRight) ? indentRight : 0;
92261
+ const totalIndent = paraIndentLeft + paraIndentRight;
92262
+ const availableWidth = Math.max(0, fragment.width - totalIndent);
92263
+ if (totalIndent > fragment.width) {
92264
+ console.warn(
92265
+ `[clickToPosition] Paragraph indents (${totalIndent}px) exceed fragment width (${fragment.width}px) for block ${fragment.blockId}. This may indicate a layout miscalculation. Available width clamped to 0.`
92266
+ );
92267
+ }
92268
+ const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
92269
+ const isListItem3 = markerWidth > 0;
92270
+ const alignmentOverride = isListItem3 ? "left" : void 0;
92271
+ const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL, availableWidth, alignmentOverride);
92272
+ if (pos == null) {
92273
+ logClickStage("warn", "no-position", {
92274
+ blockId: fragment.blockId
92275
+ });
92276
+ return null;
92277
+ }
92278
+ const column = determineColumn(layout, fragment.x);
92279
+ logPositionDebug({
92280
+ blockId: fragment.blockId,
92281
+ x: pageRelativePoint.x - fragment.x
91627
92282
  });
91628
- return null;
91629
- }
91630
- const lineIndex = findLineIndexAtY(measure, pageY, fragment.fromLine, fragment.toLine);
91631
- if (lineIndex == null) {
91632
- logClickStage("warn", "no-line", {
92283
+ logClickStage("log", "success", {
91633
92284
  blockId: fragment.blockId
91634
92285
  });
91635
- return null;
91636
- }
91637
- const line = measure.lines[lineIndex];
91638
- const isRTL = isRtlBlock(block);
91639
- const indentLeft = typeof block.attrs?.indent?.left === "number" ? block.attrs.indent.left : 0;
91640
- const indentRight = typeof block.attrs?.indent?.right === "number" ? block.attrs.indent.right : 0;
91641
- const paraIndentLeft = Number.isFinite(indentLeft) ? indentLeft : 0;
91642
- const paraIndentRight = Number.isFinite(indentRight) ? indentRight : 0;
91643
- const totalIndent = paraIndentLeft + paraIndentRight;
91644
- const availableWidth = Math.max(0, fragment.width - totalIndent);
91645
- if (totalIndent > fragment.width) {
91646
- console.warn(
91647
- `[clickToPosition] Paragraph indents (${totalIndent}px) exceed fragment width (${fragment.width}px) for block ${fragment.blockId}. This may indicate a layout miscalculation. Available width clamped to 0.`
91648
- );
92286
+ return {
92287
+ pos,
92288
+ blockId: fragment.blockId,
92289
+ pageIndex,
92290
+ column,
92291
+ lineIndex
92292
+ // lineIndex is now already absolute (within measure.lines), no need to add fragment.fromLine
92293
+ };
91649
92294
  }
91650
- const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
91651
- const isListItem3 = markerWidth > 0;
91652
- const alignmentOverride = isListItem3 ? "left" : void 0;
91653
- const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL, availableWidth, alignmentOverride);
91654
- if (pos == null) {
91655
- logClickStage("warn", "no-position", {
91656
- blockId: fragment.blockId
92295
+ if (isAtomicFragment(fragment)) {
92296
+ const pmRange = getAtomicPmRange(fragment, block);
92297
+ const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
92298
+ if (pos == null) {
92299
+ logClickStage("warn", "atomic-without-range", {
92300
+ fragmentId: fragment.blockId
92301
+ });
92302
+ return null;
92303
+ }
92304
+ logClickStage("log", "success", {
92305
+ blockId: fragment.blockId,
92306
+ column: determineColumn(layout, fragment.x)
91657
92307
  });
91658
- return null;
92308
+ return {
92309
+ pos,
92310
+ blockId: fragment.blockId,
92311
+ pageIndex,
92312
+ column: determineColumn(layout, fragment.x),
92313
+ lineIndex: -1
92314
+ };
91659
92315
  }
91660
- const column = determineColumn(layout, fragment.x);
91661
- logPositionDebug({
91662
- blockId: fragment.blockId,
91663
- x: pageRelativePoint.x - fragment.x
91664
- });
91665
- logClickStage("log", "success", {
91666
- blockId: fragment.blockId
91667
- });
91668
- return {
91669
- pos,
91670
- blockId: fragment.blockId,
91671
- pageIndex,
91672
- column,
91673
- lineIndex
91674
- // lineIndex is now already absolute (within measure.lines), no need to add fragment.fromLine
91675
- };
91676
92316
  }
91677
92317
  const tableHit = hitTestTableFragment(pageHit, blocks2, measures, pageRelativePoint);
91678
92318
  if (tableHit) {
@@ -91822,12 +92462,22 @@ ${l}
91822
92462
  }
91823
92463
  return height;
91824
92464
  };
91825
- function selectionToRects(layout, blocks2, measures, from2, to) {
92465
+ const calculatePageTopFallback = (layout, pageIndex) => {
92466
+ const pageGap = layout.pageGap ?? 0;
92467
+ let y2 = 0;
92468
+ for (let i2 = 0; i2 < pageIndex; i2++) {
92469
+ const pageHeight = layout.pages[i2]?.size?.h ?? layout.pageSize.h;
92470
+ y2 += pageHeight + pageGap;
92471
+ }
92472
+ return y2;
92473
+ };
92474
+ function selectionToRects(layout, blocks2, measures, from2, to, geometryHelper) {
91826
92475
  if (from2 === to) {
91827
92476
  return [];
91828
92477
  }
91829
92478
  const rects = [];
91830
92479
  layout.pages.forEach((page, pageIndex) => {
92480
+ const pageTopY = geometryHelper ? geometryHelper.getPageTop(pageIndex) : calculatePageTopFallback(layout, pageIndex);
91831
92481
  page.fragments.forEach((fragment) => {
91832
92482
  if (fragment.kind === "para") {
91833
92483
  const blockIndex = findBlockIndexByFragmentId(blocks2, fragment.blockId, { from: from2, to });
@@ -91869,12 +92519,16 @@ ${l}
91869
92519
  wordLayout
91870
92520
  });
91871
92521
  const rectX = fragment.x + indentAdjust + Math.min(startX, endX);
91872
- const rectWidth = Math.max(1, Math.abs(endX - startX));
92522
+ const rectWidth = Math.max(
92523
+ 1,
92524
+ Math.min(Math.abs(endX - startX), line.width)
92525
+ // clamp to line width to prevent runaway widths
92526
+ );
91873
92527
  const lineOffset = lineHeightBeforeIndex(measure, index2) - lineHeightBeforeIndex(measure, fragment.fromLine);
91874
92528
  const rectY = fragment.y + lineOffset;
91875
92529
  rects.push({
91876
92530
  x: rectX,
91877
- y: rectY + pageIndex * (layout.pageSize.h + (layout.pageGap ?? 0)),
92531
+ y: rectY + pageTopY,
91878
92532
  width: rectWidth,
91879
92533
  height: line.lineHeight,
91880
92534
  pageIndex
@@ -92002,12 +92656,16 @@ ${l}
92002
92656
  wordLayout: cellWordLayout
92003
92657
  });
92004
92658
  const rectX = fragment.x + cellX + padding.left + textIndentAdjust + Math.min(startX, endX);
92005
- const rectWidth = Math.max(1, Math.abs(endX - startX));
92659
+ const rectWidth = Math.max(
92660
+ 1,
92661
+ Math.min(Math.abs(endX - startX), line.width)
92662
+ // clamp to line width to prevent runaway widths
92663
+ );
92006
92664
  const lineOffset = lineHeightBeforeIndex(info.measure, index2) - lineHeightBeforeIndex(info.measure, info.startLine);
92007
92665
  const rectY = fragment.y + rowOffset + blockTopCursor + lineOffset;
92008
92666
  rects.push({
92009
92667
  x: rectX,
92010
- y: rectY + pageIndex * (layout.pageSize.h + (layout.pageGap ?? 0)),
92668
+ y: rectY + pageTopY,
92011
92669
  width: rectWidth,
92012
92670
  height: line.lineHeight,
92013
92671
  pageIndex
@@ -92036,7 +92694,7 @@ ${l}
92036
92694
  if (!rangesOverlap(pmRange.pmStart, pmRange.pmEnd, from2, to)) return;
92037
92695
  rects.push({
92038
92696
  x: fragment.x,
92039
- y: fragment.y + pageIndex * (layout.pageSize.h + (layout.pageGap ?? 0)),
92697
+ y: fragment.y + pageTopY,
92040
92698
  width: fragment.width,
92041
92699
  height: fragment.height,
92042
92700
  pageIndex
@@ -93152,7 +93810,7 @@ ${l}
93152
93810
  const wordEndWithSpace = charPosInRun + (isLastWord ? word.length : word.length + 1);
93153
93811
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
93154
93812
  if (wordOnlyWidth > effectiveMaxWidth && word.length > 1) {
93155
- if (currentLine && currentLine.width > 0 && currentLine.segments.length > 0) {
93813
+ if (currentLine && currentLine.width > 0 && currentLine.segments && currentLine.segments.length > 0) {
93156
93814
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
93157
93815
  const { spaceCount: _sc, ...lineBase } = currentLine;
93158
93816
  const completedLine = { ...lineBase, ...metrics };
@@ -93163,7 +93821,7 @@ ${l}
93163
93821
  currentLine = null;
93164
93822
  }
93165
93823
  const lineMaxWidth = getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
93166
- const hasTabOnlyLine = currentLine && currentLine.segments.length === 0 && currentLine.width > 0;
93824
+ const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
93167
93825
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
93168
93826
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
93169
93827
  const chunks = breakWordIntoChunks(word, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
@@ -93174,7 +93832,7 @@ ${l}
93174
93832
  const chunkEndChar = chunkCharOffset + chunk.text.length;
93175
93833
  const isLastChunk = chunkIndex === chunks.length - 1;
93176
93834
  const isFirstChunk = chunkIndex === 0;
93177
- if (isFirstChunk && hasTabOnlyLine && currentLine) {
93835
+ if (isFirstChunk && hasTabOnlyLine && currentLine && currentLine.segments) {
93178
93836
  currentLine.toRun = runIndex;
93179
93837
  currentLine.toChar = chunkEndChar;
93180
93838
  currentLine.width = roundValue(currentLine.width + chunk.width);
@@ -94007,6 +94665,7 @@ ${l}
94007
94665
  const fontSizeInPixles = fontSizePt * 1.3333;
94008
94666
  const lineHeight2 = fontSizeInPixles * 1.2;
94009
94667
  applyStyleIsolationClass(editorContainer);
94668
+ const isFooter = type2 === "footer";
94010
94669
  Object.assign(editorContainer.style, {
94011
94670
  padding: "0",
94012
94671
  margin: "0",
@@ -94021,7 +94680,7 @@ ${l}
94021
94680
  fontFamily: fontFamilyCss || typeface,
94022
94681
  fontSize: `${fontSizeInPixles}px`,
94023
94682
  lineHeight: `${lineHeight2}px`,
94024
- overflow: "hidden",
94683
+ overflow: isFooter ? "visible" : "hidden",
94025
94684
  pointerEvents: "auto",
94026
94685
  // Critical: enables click interaction
94027
94686
  backgroundColor: "white"
@@ -95100,6 +95759,7 @@ ${l}
95100
95759
  const editorContainer = __privateGet$1(this, _activeEditorHost).querySelector(".super-editor");
95101
95760
  if (editorContainer instanceof HTMLElement) {
95102
95761
  editorContainer.style.top = "0";
95762
+ editorContainer.style.transform = "";
95103
95763
  }
95104
95764
  }
95105
95765
  }
@@ -95275,6 +95935,7 @@ ${l}
95275
95935
  const DEFAULT_MARGINS = { top: 72, right: 72, bottom: 72, left: 72 };
95276
95936
  const DEFAULT_VIRTUALIZED_PAGE_GAP = 72;
95277
95937
  const DEFAULT_PAGE_GAP = 24;
95938
+ const DEFAULT_HORIZONTAL_PAGE_GAP = 20;
95278
95939
  const WORD_CHARACTER_REGEX = /[\p{L}\p{N}''_~-]/u;
95279
95940
  const MULTI_CLICK_TIME_THRESHOLD_MS = 400;
95280
95941
  const MULTI_CLICK_DISTANCE_THRESHOLD_PX = 5;
@@ -95298,6 +95959,7 @@ ${l}
95298
95959
  __privateAdd$1(this, _layoutOptions);
95299
95960
  __privateAdd$1(this, _layoutState, { blocks: [], measures: [], layout: null, bookmarks: /* @__PURE__ */ new Map() });
95300
95961
  __privateAdd$1(this, _domPainter, null);
95962
+ __privateAdd$1(this, _pageGeometryHelper, null);
95301
95963
  __privateAdd$1(this, _dragHandlerCleanup, null);
95302
95964
  __privateAdd$1(this, _layoutError, null);
95303
95965
  __privateAdd$1(this, _layoutErrorState, "healthy");
@@ -95450,7 +96112,8 @@ ${l}
95450
96112
  { x: x2, y: y2 },
95451
96113
  __privateGet$1(this, _viewportHost),
95452
96114
  event.clientX,
95453
- event.clientY
96115
+ event.clientY,
96116
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
95454
96117
  );
95455
96118
  const doc22 = __privateGet$1(this, _editor3).state?.doc;
95456
96119
  const hit = rawHit && doc22 ? { ...rawHit, pos: Math.max(0, Math.min(rawHit.pos, doc22.content.size)) } : rawHit;
@@ -95649,7 +96312,8 @@ ${l}
95649
96312
  { x: normalized.x, y: normalized.y },
95650
96313
  __privateGet$1(this, _viewportHost),
95651
96314
  event.clientX,
95652
- event.clientY
96315
+ event.clientY,
96316
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
95653
96317
  );
95654
96318
  if (!hit) return;
95655
96319
  const currentTableHit = __privateMethod$1(this, _PresentationEditor_instances, hitTestTable_fn).call(this, normalized.x, normalized.y);
@@ -96496,7 +97160,14 @@ ${l}
96496
97160
  return __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterSelectionRects_fn).call(this, start2, end2);
96497
97161
  }
96498
97162
  if (!__privateGet$1(this, _layoutState).layout) return [];
96499
- const rects = selectionToRects(__privateGet$1(this, _layoutState).layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, start2, end2) ?? [];
97163
+ const rects = selectionToRects(
97164
+ __privateGet$1(this, _layoutState).layout,
97165
+ __privateGet$1(this, _layoutState).blocks,
97166
+ __privateGet$1(this, _layoutState).measures,
97167
+ start2,
97168
+ end2,
97169
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
97170
+ ) ?? [];
96500
97171
  return rects;
96501
97172
  };
96502
97173
  const rawRects = layoutRectSource();
@@ -96761,6 +97432,7 @@ ${l}
96761
97432
  };
96762
97433
  }
96763
97434
  __privateSet(this, _domPainter, null);
97435
+ __privateSet(this, _pageGeometryHelper, null);
96764
97436
  __privateSet(this, _pendingDocChange, true);
96765
97437
  __privateMethod$1(this, _PresentationEditor_instances, scheduleRerender_fn).call(this);
96766
97438
  }
@@ -96793,7 +97465,16 @@ ${l}
96793
97465
  x: localX,
96794
97466
  y: headerPageIndex * headerPageHeight + (localY - headerPageIndex * headerPageHeight)
96795
97467
  };
96796
- const hit2 = clickToPosition(context.layout, context.blocks, context.measures, headerPoint) ?? null;
97468
+ const hit2 = clickToPosition(
97469
+ context.layout,
97470
+ context.blocks,
97471
+ context.measures,
97472
+ headerPoint,
97473
+ void 0,
97474
+ void 0,
97475
+ void 0,
97476
+ void 0
97477
+ ) ?? null;
96797
97478
  return hit2;
96798
97479
  }
96799
97480
  if (!__privateGet$1(this, _layoutState).layout) {
@@ -96806,7 +97487,8 @@ ${l}
96806
97487
  normalized,
96807
97488
  __privateGet$1(this, _viewportHost),
96808
97489
  clientX,
96809
- clientY
97490
+ clientY,
97491
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
96810
97492
  ) ?? null;
96811
97493
  return hit;
96812
97494
  }
@@ -97029,6 +97711,7 @@ ${l}
97029
97711
  __privateSet(this, _session, { mode: "body" });
97030
97712
  __privateSet(this, _activeHeaderFooterEditor, null);
97031
97713
  __privateSet(this, _domPainter, null);
97714
+ __privateSet(this, _pageGeometryHelper, null);
97032
97715
  (_a2 = __privateGet$1(this, _dragHandlerCleanup)) == null ? void 0 : _a2.call(this);
97033
97716
  __privateSet(this, _dragHandlerCleanup, null);
97034
97717
  __privateGet$1(this, _selectionOverlay2)?.remove();
@@ -97082,7 +97765,14 @@ ${l}
97082
97765
  if (!normalized) return false;
97083
97766
  const pmPos = __privateGet$1(this, _layoutState).bookmarks.get(normalized);
97084
97767
  if (pmPos == null) return false;
97085
- const rects = selectionToRects(layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, pmPos, pmPos + 1) ?? [];
97768
+ const rects = selectionToRects(
97769
+ layout,
97770
+ __privateGet$1(this, _layoutState).blocks,
97771
+ __privateGet$1(this, _layoutState).measures,
97772
+ pmPos,
97773
+ pmPos + 1,
97774
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
97775
+ ) ?? [];
97086
97776
  const rect = rects[0];
97087
97777
  let pageIndex = rect?.pageIndex ?? null;
97088
97778
  if (pageIndex == null) {
@@ -97146,6 +97836,7 @@ ${l}
97146
97836
  _layoutOptions = /* @__PURE__ */ new WeakMap();
97147
97837
  _layoutState = /* @__PURE__ */ new WeakMap();
97148
97838
  _domPainter = /* @__PURE__ */ new WeakMap();
97839
+ _pageGeometryHelper = /* @__PURE__ */ new WeakMap();
97149
97840
  _dragHandlerCleanup = /* @__PURE__ */ new WeakMap();
97150
97841
  _layoutError = /* @__PURE__ */ new WeakMap();
97151
97842
  _layoutErrorState = /* @__PURE__ */ new WeakMap();
@@ -97378,18 +98069,19 @@ ${l}
97378
98069
  const normalized = /* @__PURE__ */ new Map();
97379
98070
  states?.forEach((aw, clientId) => {
97380
98071
  if (clientId === provider2.awareness?.clientID) return;
97381
- if (!aw.cursor) return;
98072
+ const awState = aw;
98073
+ if (!awState.cursor) return;
97382
98074
  try {
97383
98075
  const anchor = relativePositionToAbsolutePosition(
97384
98076
  ystate.doc,
97385
98077
  ystate.type,
97386
- Y__namespace.createRelativePositionFromJSON(aw.cursor.anchor),
98078
+ Y__namespace.createRelativePositionFromJSON(awState.cursor.anchor),
97387
98079
  ystate.binding.mapping
97388
98080
  );
97389
98081
  const head = relativePositionToAbsolutePosition(
97390
98082
  ystate.doc,
97391
98083
  ystate.type,
97392
- Y__namespace.createRelativePositionFromJSON(aw.cursor.head),
98084
+ Y__namespace.createRelativePositionFromJSON(awState.cursor.head),
97393
98085
  ystate.binding.mapping
97394
98086
  );
97395
98087
  if (anchor === null || head === null) return;
@@ -97401,9 +98093,9 @@ ${l}
97401
98093
  normalized.set(clientId, {
97402
98094
  clientId,
97403
98095
  user: {
97404
- name: aw.user?.name,
97405
- email: aw.user?.email,
97406
- color: aw.user?.color || __privateMethod$1(this, _PresentationEditor_instances, getFallbackColor_fn).call(this, clientId)
98096
+ name: awState.user?.name,
98097
+ email: awState.user?.email,
98098
+ color: awState.user?.color || __privateMethod$1(this, _PresentationEditor_instances, getFallbackColor_fn).call(this, clientId)
97407
98099
  },
97408
98100
  anchor: clampedAnchor,
97409
98101
  head: clampedHead,
@@ -97604,7 +98296,7 @@ ${l}
97604
98296
  if (!layout || !blocks2 || !measures) return;
97605
98297
  const start2 = Math.min(cursor.anchor, cursor.head);
97606
98298
  const end2 = Math.max(cursor.anchor, cursor.head);
97607
- const rects = selectionToRects(layout, blocks2, measures, start2, end2) ?? [];
98299
+ const rects = selectionToRects(layout, blocks2, measures, start2, end2, __privateGet$1(this, _pageGeometryHelper) ?? void 0) ?? [];
97608
98300
  const color2 = __privateMethod$1(this, _PresentationEditor_instances, getValidatedColor_fn).call(this, cursor);
97609
98301
  const opacity = __privateGet$1(this, _layoutOptions).presence?.highlightOpacity ?? 0.35;
97610
98302
  const pageHeight = layout.pageSize?.h ?? __privateGet$1(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
@@ -97964,15 +98656,25 @@ ${l}
97964
98656
  const configuredPageSize = __privateGet$1(this, _layoutOptions).pageSize ?? DEFAULT_PAGE_SIZE;
97965
98657
  let pageY = 0;
97966
98658
  let pageHit = null;
97967
- for (let i2 = 0; i2 < layout.pages.length; i2++) {
97968
- const page = layout.pages[i2];
97969
- const pageHeight = page.size?.h ?? configuredPageSize.h;
97970
- const gap = __privateGet$1(this, _layoutOptions).virtualization?.gap ?? DEFAULT_PAGE_GAP;
97971
- if (normalizedY >= pageY && normalizedY < pageY + pageHeight) {
97972
- pageHit = { pageIndex: i2, page };
97973
- break;
98659
+ const geometryHelper = __privateGet$1(this, _pageGeometryHelper);
98660
+ if (geometryHelper) {
98661
+ const idx = geometryHelper.getPageIndexAtY(normalizedY) ?? geometryHelper.getNearestPageIndex(normalizedY);
98662
+ if (idx != null && layout.pages[idx]) {
98663
+ pageHit = { pageIndex: idx, page: layout.pages[idx] };
98664
+ pageY = geometryHelper.getPageTop(idx);
98665
+ }
98666
+ }
98667
+ if (!pageHit) {
98668
+ const gap = layout.pageGap ?? __privateMethod$1(this, _PresentationEditor_instances, getEffectivePageGap_fn).call(this);
98669
+ for (let i2 = 0; i2 < layout.pages.length; i2++) {
98670
+ const page = layout.pages[i2];
98671
+ const pageHeight = page.size?.h ?? configuredPageSize.h;
98672
+ if (normalizedY >= pageY && normalizedY < pageY + pageHeight) {
98673
+ pageHit = { pageIndex: i2, page };
98674
+ break;
98675
+ }
98676
+ pageY += pageHeight + gap;
97974
98677
  }
97975
- pageY += pageHeight + gap;
97976
98678
  }
97977
98679
  if (!pageHit) {
97978
98680
  return null;
@@ -98224,12 +98926,7 @@ ${l}
98224
98926
  return;
98225
98927
  }
98226
98928
  ({ layout, measures } = result);
98227
- if (__privateGet$1(this, _layoutOptions).virtualization?.enabled) {
98228
- const gap = __privateGet$1(this, _layoutOptions).virtualization.gap ?? DEFAULT_VIRTUALIZED_PAGE_GAP;
98229
- layout.pageGap = Math.max(0, gap);
98230
- } else {
98231
- layout.pageGap = DEFAULT_PAGE_GAP;
98232
- }
98929
+ layout.pageGap = __privateMethod$1(this, _PresentationEditor_instances, getEffectivePageGap_fn).call(this);
98233
98930
  headerLayouts = result.headers;
98234
98931
  footerLayouts = result.footers;
98235
98932
  } catch (error) {
@@ -98246,6 +98943,17 @@ ${l}
98246
98943
  __privateSet(this, _layoutState, { blocks: blocks2, measures, layout, bookmarks, anchorMap });
98247
98944
  __privateSet(this, _headerLayoutResults, headerLayouts ?? null);
98248
98945
  __privateSet(this, _footerLayoutResults, footerLayouts ?? null);
98946
+ if (__privateGet$1(this, _layoutState).layout) {
98947
+ const pageGap = __privateGet$1(this, _layoutState).layout.pageGap ?? __privateMethod$1(this, _PresentationEditor_instances, getEffectivePageGap_fn).call(this);
98948
+ if (!__privateGet$1(this, _pageGeometryHelper)) {
98949
+ __privateSet(this, _pageGeometryHelper, new PageGeometryHelper({
98950
+ layout: __privateGet$1(this, _layoutState).layout,
98951
+ pageGap
98952
+ }));
98953
+ } else {
98954
+ __privateGet$1(this, _pageGeometryHelper).updateLayout(__privateGet$1(this, _layoutState).layout, pageGap);
98955
+ }
98956
+ }
98249
98957
  await __privateMethod$1(this, _PresentationEditor_instances, layoutPerRIdHeaderFooters_fn).call(this, headerFooterInput, layout, sectionMetadata);
98250
98958
  __privateMethod$1(this, _PresentationEditor_instances, updateDecorationProviders_fn).call(this, layout);
98251
98959
  const painter = __privateMethod$1(this, _PresentationEditor_instances, ensurePainter_fn).call(this, blocks2, measures);
@@ -98315,7 +99023,8 @@ ${l}
98315
99023
  pageStyles: __privateGet$1(this, _layoutOptions).pageStyles,
98316
99024
  headerProvider: __privateGet$1(this, _headerDecorationProvider),
98317
99025
  footerProvider: __privateGet$1(this, _footerDecorationProvider),
98318
- ruler: __privateGet$1(this, _layoutOptions).ruler
99026
+ ruler: __privateGet$1(this, _layoutOptions).ruler,
99027
+ pageGap: __privateGet$1(this, _layoutState).layout?.pageGap ?? __privateMethod$1(this, _PresentationEditor_instances, getEffectivePageGap_fn).call(this)
98319
99028
  }));
98320
99029
  }
98321
99030
  return __privateGet$1(this, _domPainter);
@@ -98403,7 +99112,14 @@ ${l}
98403
99112
  }
98404
99113
  return;
98405
99114
  }
98406
- const rects = selectionToRects(layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, from2, to) ?? [];
99115
+ const rects = selectionToRects(
99116
+ layout,
99117
+ __privateGet$1(this, _layoutState).blocks,
99118
+ __privateGet$1(this, _layoutState).measures,
99119
+ from2,
99120
+ to,
99121
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
99122
+ ) ?? [];
98407
99123
  let domStart = null;
98408
99124
  let domEnd = null;
98409
99125
  try {
@@ -98417,7 +99133,9 @@ ${l}
98417
99133
  const correctedRects = __privateMethod$1(this, _PresentationEditor_instances, applyDomCorrectionToRects_fn).call(this, rects, domStart, domEnd);
98418
99134
  try {
98419
99135
  __privateGet$1(this, _localSelectionLayer).innerHTML = "";
98420
- __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, correctedRects);
99136
+ if (correctedRects.length > 0) {
99137
+ __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, correctedRects);
99138
+ }
98421
99139
  } catch (error) {
98422
99140
  if (process$1$1.env.NODE_ENV === "development") {
98423
99141
  console.warn("[PresentationEditor] Failed to render selection rects:", error);
@@ -98609,8 +99327,10 @@ ${l}
98609
99327
  const pageHeight2 = page?.size?.h ?? layout.pageSize?.h ?? __privateGet$1(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
98610
99328
  const margins2 = pageMargins ?? layout.pages[0]?.margins ?? __privateGet$1(this, _layoutOptions).margins ?? DEFAULT_MARGINS;
98611
99329
  const box2 = __privateMethod$1(this, _PresentationEditor_instances, computeDecorationBox_fn).call(this, kind, margins2, pageHeight2);
99330
+ const layoutMinY2 = rIdLayout.layout.minY ?? 0;
99331
+ const normalizedFragments2 = layoutMinY2 < 0 ? fragments2.map((f2) => ({ ...f2, y: f2.y - layoutMinY2 })) : fragments2;
98612
99332
  return {
98613
- fragments: fragments2,
99333
+ fragments: normalizedFragments2,
98614
99334
  height: box2.height,
98615
99335
  contentHeight: rIdLayout.layout.height ?? box2.height,
98616
99336
  offset: box2.offset,
@@ -98618,6 +99338,7 @@ ${l}
98618
99338
  contentWidth: box2.width,
98619
99339
  headerId: sectionRId,
98620
99340
  sectionType: headerFooterType,
99341
+ minY: layoutMinY2,
98621
99342
  box: {
98622
99343
  x: box2.x,
98623
99344
  y: box2.offset,
@@ -98650,8 +99371,10 @@ ${l}
98650
99371
  const box = __privateMethod$1(this, _PresentationEditor_instances, computeDecorationBox_fn).call(this, kind, margins, pageHeight);
98651
99372
  const fallbackId = __privateGet$1(this, _headerFooterManager)?.getVariantId(kind, headerFooterType);
98652
99373
  const finalHeaderId = sectionRId ?? fallbackId ?? void 0;
99374
+ const layoutMinY = variant.layout.minY ?? 0;
99375
+ const normalizedFragments = layoutMinY < 0 ? fragments.map((f2) => ({ ...f2, y: f2.y - layoutMinY })) : fragments;
98653
99376
  return {
98654
- fragments,
99377
+ fragments: normalizedFragments,
98655
99378
  height: box.height,
98656
99379
  contentHeight: variant.layout.height ?? box.height,
98657
99380
  offset: box.offset,
@@ -98659,6 +99382,7 @@ ${l}
98659
99382
  contentWidth: box.width,
98660
99383
  headerId: finalHeaderId,
98661
99384
  sectionType: headerFooterType,
99385
+ minY: layoutMinY,
98662
99386
  box: {
98663
99387
  x: box.x,
98664
99388
  y: box.offset,
@@ -98773,7 +99497,9 @@ ${l}
98773
99497
  localX: footerPayload?.hitRegion?.x ?? footerBox.x,
98774
99498
  localY: footerPayload?.hitRegion?.y ?? footerBox.offset,
98775
99499
  width: footerPayload?.hitRegion?.width ?? footerBox.width,
98776
- height: footerPayload?.hitRegion?.height ?? footerBox.height
99500
+ height: footerPayload?.hitRegion?.height ?? footerBox.height,
99501
+ contentHeight: footerPayload?.contentHeight,
99502
+ minY: footerPayload?.minY
98777
99503
  });
98778
99504
  });
98779
99505
  };
@@ -98903,6 +99629,18 @@ ${l}
98903
99629
  });
98904
99630
  return;
98905
99631
  }
99632
+ if (region.kind === "footer") {
99633
+ const editorContainer = editorHost.firstElementChild;
99634
+ if (editorContainer instanceof HTMLElement) {
99635
+ editorContainer.style.overflow = "visible";
99636
+ if (region.minY != null && region.minY < 0) {
99637
+ const shiftDown = Math.abs(region.minY);
99638
+ editorContainer.style.transform = `translateY(${shiftDown}px)`;
99639
+ } else {
99640
+ editorContainer.style.transform = "";
99641
+ }
99642
+ }
99643
+ }
98906
99644
  try {
98907
99645
  editor.setEditable(true);
98908
99646
  editor.setOptions({ documentMode: "editing" });
@@ -99185,6 +99923,15 @@ ${l}
99185
99923
  checkPage();
99186
99924
  });
99187
99925
  };
99926
+ getEffectivePageGap_fn = function() {
99927
+ if (__privateGet$1(this, _layoutOptions).virtualization?.enabled) {
99928
+ return Math.max(0, __privateGet$1(this, _layoutOptions).virtualization.gap ?? DEFAULT_VIRTUALIZED_PAGE_GAP);
99929
+ }
99930
+ if (__privateGet$1(this, _layoutOptions).layoutMode === "horizontal") {
99931
+ return DEFAULT_HORIZONTAL_PAGE_GAP;
99932
+ }
99933
+ return DEFAULT_PAGE_GAP;
99934
+ };
99188
99935
  getBodyPageHeight_fn = function() {
99189
99936
  return __privateGet$1(this, _layoutState).layout?.pageSize?.h ?? __privateGet$1(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
99190
99937
  };
@@ -99208,7 +99955,7 @@ ${l}
99208
99955
  dy: domStart.y - layoutY
99209
99956
  };
99210
99957
  }
99211
- return rects.map((rect, idx) => {
99958
+ const corrected = rects.map((rect, idx) => {
99212
99959
  const delta = pageDelta[rect.pageIndex];
99213
99960
  let adjustedX = delta ? rect.x + delta.dx : rect.x;
99214
99961
  let adjustedY = delta ? rect.y + delta.dy : rect.y;
@@ -99223,6 +99970,7 @@ ${l}
99223
99970
  }
99224
99971
  if (isLastRect && domEnd && rect.pageIndex === domEnd.pageIndex) {
99225
99972
  const endX = domEnd.x;
99973
+ adjustedX = Math.min(adjustedX, endX);
99226
99974
  adjustedWidth = Math.max(1, endX - adjustedX);
99227
99975
  }
99228
99976
  return {
@@ -99232,6 +99980,29 @@ ${l}
99232
99980
  width: adjustedWidth
99233
99981
  };
99234
99982
  });
99983
+ const MAX_DELTA_PX = 12;
99984
+ let invalid2 = false;
99985
+ if (domStart && corrected[0]) {
99986
+ const dx = Math.abs(corrected[0].x - domStart.x);
99987
+ const dy = Math.abs(corrected[0].y - domStart.y);
99988
+ if (dx > MAX_DELTA_PX || dy > MAX_DELTA_PX) invalid2 = true;
99989
+ }
99990
+ if (domEnd && corrected[corrected.length - 1]) {
99991
+ const last = corrected[corrected.length - 1];
99992
+ const dx = Math.abs(last.x + last.width - domEnd.x);
99993
+ const dy = Math.abs(last.y - domEnd.y);
99994
+ if (dx > MAX_DELTA_PX || dy > MAX_DELTA_PX) invalid2 = true;
99995
+ }
99996
+ if (invalid2) {
99997
+ console.warn("[SelectionOverlay] Suppressing selection render due to large DOM/Layout mismatch", {
99998
+ domStart,
99999
+ domEnd,
100000
+ rectStart: corrected[0],
100001
+ rectEnd: corrected[corrected.length - 1]
100002
+ });
100003
+ return [];
100004
+ }
100005
+ return corrected;
99235
100006
  };
99236
100007
  renderCellSelectionOverlay_fn = function(selection, layout) {
99237
100008
  const localSelectionLayer = __privateGet$1(this, _localSelectionLayer);
@@ -99515,7 +100286,7 @@ ${l}
99515
100286
  return [];
99516
100287
  }
99517
100288
  if (!bodyLayout) return [];
99518
- const rects = selectionToRects(context.layout, context.blocks, context.measures, from2, to) ?? [];
100289
+ const rects = selectionToRects(context.layout, context.blocks, context.measures, from2, to, void 0) ?? [];
99519
100290
  const headerPageHeight = context.layout.pageSize?.h ?? context.region.height ?? 1;
99520
100291
  const bodyPageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
99521
100292
  return rects.map((rect) => {
@@ -99798,8 +100569,8 @@ ${l}
99798
100569
  const zoom2 = __privateGet$1(this, _layoutOptions).zoom ?? 1;
99799
100570
  let domCaretX2 = null;
99800
100571
  let domCaretY2 = null;
99801
- const spanEls2 = pageEl2?.querySelectorAll("span[data-pm-start][data-pm-end]") ?? [];
99802
- for (const spanEl of spanEls2) {
100572
+ const spanEls2 = pageEl2?.querySelectorAll("span[data-pm-start][data-pm-end]");
100573
+ for (const spanEl of Array.from(spanEls2 ?? [])) {
99803
100574
  const pmStart = Number(spanEl.dataset.pmStart);
99804
100575
  const pmEnd = Number(spanEl.dataset.pmEnd);
99805
100576
  if (pos >= pmStart && pos <= pmEnd && spanEl.firstChild?.nodeType === Node.TEXT_NODE) {
@@ -99851,8 +100622,8 @@ ${l}
99851
100622
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
99852
100623
  let domCaretX = null;
99853
100624
  let domCaretY = null;
99854
- const spanEls = pageEl?.querySelectorAll("span[data-pm-start][data-pm-end]") ?? [];
99855
- for (const spanEl of spanEls) {
100625
+ const spanEls = pageEl?.querySelectorAll("span[data-pm-start][data-pm-end]");
100626
+ for (const spanEl of Array.from(spanEls ?? [])) {
99856
100627
  const pmStart = Number(spanEl.dataset.pmStart);
99857
100628
  const pmEnd = Number(spanEl.dataset.pmEnd);
99858
100629
  if (pos >= pmStart && pos <= pmEnd && spanEl.firstChild?.nodeType === Node.TEXT_NODE) {
@@ -99982,7 +100753,14 @@ ${l}
99982
100753
  if (!layout || !selection) {
99983
100754
  return 0;
99984
100755
  }
99985
- const rects = selectionToRects(layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, selection.from, selection.to) ?? [];
100756
+ const rects = selectionToRects(
100757
+ layout,
100758
+ __privateGet$1(this, _layoutState).blocks,
100759
+ __privateGet$1(this, _layoutState).measures,
100760
+ selection.from,
100761
+ selection.to,
100762
+ __privateGet$1(this, _pageGeometryHelper) ?? void 0
100763
+ ) ?? [];
99986
100764
  if (rects.length > 0) {
99987
100765
  return rects[0]?.pageIndex ?? 0;
99988
100766
  }
@@ -105414,14 +106192,19 @@ ${l}
105414
106192
  }
105415
106193
  return cellType.createAndFill();
105416
106194
  };
105417
- const createTableBorders = ({ size: size2 = 0.66665, color: color2 = "#000000" } = {}) => {
106195
+ const createTableBorders = (borderSpec = {}) => {
106196
+ borderSpec = {
106197
+ size: 0.66665,
106198
+ color: "#000000",
106199
+ ...borderSpec
106200
+ };
105418
106201
  return {
105419
- top: { size: size2, color: color2 },
105420
- left: { size: size2, color: color2 },
105421
- bottom: { size: size2, color: color2 },
105422
- right: { size: size2, color: color2 },
105423
- insideH: { size: size2, color: color2 },
105424
- insideV: { size: size2, color: color2 }
106202
+ top: borderSpec,
106203
+ left: borderSpec,
106204
+ bottom: borderSpec,
106205
+ right: borderSpec,
106206
+ insideH: borderSpec,
106207
+ insideV: borderSpec
105425
106208
  };
105426
106209
  };
105427
106210
  const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellContent = null) => {
@@ -105549,12 +106332,17 @@ ${l}
105549
106332
  editor.commands.deleteTable();
105550
106333
  return true;
105551
106334
  };
105552
- const createCellBorders = ({ size: size2 = 0.66665, color: color2 = "#000000" } = {}) => {
106335
+ const createCellBorders = (borderSpec = {}) => {
106336
+ borderSpec = {
106337
+ size: 0.66665,
106338
+ color: "#000000",
106339
+ ...borderSpec
106340
+ };
105553
106341
  return {
105554
- top: { size: size2, color: color2 },
105555
- left: { size: size2, color: color2 },
105556
- bottom: { size: size2, color: color2 },
105557
- right: { size: size2, color: color2 }
106342
+ top: borderSpec,
106343
+ left: borderSpec,
106344
+ bottom: borderSpec,
106345
+ right: borderSpec
105558
106346
  };
105559
106347
  };
105560
106348
  function cellAround($pos) {
@@ -106321,13 +107109,20 @@ ${l}
106321
107109
  if (["tableCell", "tableHeader"].includes(node2.type.name)) {
106322
107110
  tr.setNodeMarkup(pos, void 0, {
106323
107111
  ...node2.attrs,
106324
- borders: createCellBorders({ size: 0 })
107112
+ borders: createCellBorders({ size: 0, space: 0, val: "none", color: "auto" })
106325
107113
  });
106326
107114
  }
106327
107115
  });
106328
107116
  tr.setNodeMarkup(table2.pos, void 0, {
106329
107117
  ...table2.node.attrs,
106330
- borders: createTableBorders({ size: 0 })
107118
+ borders: createTableBorders({ size: 0 }),
107119
+ // TODO: This works around the issue that table borders are duplicated between
107120
+ // the attributes of the table and the tableProperties attribute.
107121
+ // This can be removed when the redundancy is eliminated.
107122
+ tableProperties: {
107123
+ ...table2.node.attrs.tableProperties,
107124
+ borders: createTableBorders({ size: 0, space: 0, val: "none", color: "auto" })
107125
+ }
106331
107126
  });
106332
107127
  return true;
106333
107128
  }
@@ -130329,7 +131124,7 @@ ${style2}
130329
131124
  }
130330
131125
  },
130331
131126
  {
130332
- label: toolbarTexts2.transparentBorders,
131127
+ label: toolbarTexts2.removeBorders,
130333
131128
  command: "deleteCellAndTableBorders",
130334
131129
  icon: toolbarIcons2.deleteBorders,
130335
131130
  bottomBorder: true,
@@ -130910,7 +131705,7 @@ ${style2}
130910
131705
  deleteRow: "Delete row",
130911
131706
  deleteColumn: "Delete column",
130912
131707
  deleteTable: "Delete table",
130913
- transparentBorders: "Transparent borders",
131708
+ removeBorders: "Remove borders",
130914
131709
  mergeCells: "Merge cells",
130915
131710
  splitCell: "Split cell",
130916
131711
  fixTables: "Fix tables",
@@ -131948,7 +132743,7 @@ ${style2}
131948
132743
  deleteRow: "Delete row",
131949
132744
  deleteColumn: "Delete column",
131950
132745
  deleteTable: "Delete table",
131951
- transparentBorders: "Transparent borders",
132746
+ removeBorders: "Remove borders",
131952
132747
  mergeCells: "Merge cells",
131953
132748
  splitCell: "Split cell",
131954
132749
  fixTables: "Fix tables",
@@ -132031,7 +132826,7 @@ ${style2}
132031
132826
  }
132032
132827
  },
132033
132828
  {
132034
- label: TEXTS.transparentBorders,
132829
+ label: TEXTS.removeBorders,
132035
132830
  command: "deleteCellAndTableBorders",
132036
132831
  icon: ICONS.deleteBorders,
132037
132832
  bottomBorder: true,
@@ -152176,7 +152971,7 @@ ${style2}
152176
152971
  this.config.colors = shuffleArray(this.config.colors);
152177
152972
  this.userColorMap = /* @__PURE__ */ new Map();
152178
152973
  this.colorIndex = 0;
152179
- this.version = "1.0.0-beta.99";
152974
+ this.version = "1.0.0-next.1";
152180
152975
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
152181
152976
  this.superdocId = config2.superdocId || v4();
152182
152977
  this.colors = this.config.colors;
@@ -154648,7 +155443,7 @@ ${style2}
154648
155443
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
154649
155444
  );
154650
155445
  }
154651
- const indexBB0msI45 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
155446
+ const indexDlj3l0Hk = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
154652
155447
  __proto__: null,
154653
155448
  unified
154654
155449
  }, Symbol.toStringTag, { value: "Module" }));