superdoc 1.0.0-beta.65 → 1.0.0-beta.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/chunks/{PdfViewer-CqHxrRM3.es.js → PdfViewer-BgQnzisJ.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-CPtbSOs5.cjs → PdfViewer-CpRzjNks.cjs} +1 -1
  3. package/dist/chunks/{index-YSWS94Jr-C7xFStTB.cjs → index-Bjv0_slj-CIZ6x5_a.cjs} +1 -1
  4. package/dist/chunks/{index-YSWS94Jr-BeHINTZ9.es.js → index-Bjv0_slj-aY5T6UA7.es.js} +1 -1
  5. package/dist/chunks/{index-DWJXw-IX.cjs → index-Bw7VVDLD.cjs} +3 -3
  6. package/dist/chunks/{index-BUvQNe-T.es.js → index-k63Akk_i.es.js} +3 -3
  7. package/dist/chunks/{super-editor.es-BHjskxiY.cjs → super-editor.es-CLrhh2DY.cjs} +290 -157
  8. package/dist/chunks/{super-editor.es-DaC-R5gx.es.js → super-editor.es-PQo0jrvJ.es.js} +290 -157
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-DIAStmht.js → converter-Ybdn8aYC.js} +1 -1
  11. package/dist/super-editor/chunks/{docx-zipper-DK-wWQD9.js → docx-zipper-DkmZTQAw.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-CxKPNxhs.js → editor-pqbWS9yU.js} +345 -95
  13. package/dist/super-editor/chunks/{index-YSWS94Jr.js → index-Bjv0_slj.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-D7ZHiSKZ.js → toolbar-CSzCVKWZ.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +2 -2
  24. package/dist/superdoc.es.js +2 -2
  25. package/dist/superdoc.umd.js +292 -159
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -42326,7 +42326,7 @@ const _SuperConverter = class _SuperConverter2 {
42326
42326
  static getStoredSuperdocVersion(docx) {
42327
42327
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42328
42328
  }
42329
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.65") {
42329
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.66") {
42330
42330
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42331
42331
  }
42332
42332
  /**
@@ -45638,7 +45638,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
45638
45638
  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);
45639
45639
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
45640
45640
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
45641
- 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, _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, 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, 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, convertPageLocalToOverlayCoords_fn, normalizeClientPoint_fn, computeCaretLayoutRect_fn, computeCaretLayoutRectFromDOM_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;
45641
+ 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, _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, 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, 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, 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;
45642
45642
  var GOOD_LEAF_SIZE = 200;
45643
45643
  var RopeSequence = function RopeSequence2() {
45644
45644
  };
@@ -59515,7 +59515,7 @@ const isHeadless = (editor) => {
59515
59515
  const shouldSkipNodeView = (editor) => {
59516
59516
  return isHeadless(editor);
59517
59517
  };
59518
- const summaryVersion = "1.0.0-beta.65";
59518
+ const summaryVersion = "1.0.0-beta.66";
59519
59519
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
59520
59520
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
59521
59521
  function mapAttributes(attrs) {
@@ -60304,7 +60304,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
60304
60304
  { default: remarkStringify },
60305
60305
  { default: remarkGfm }
60306
60306
  ] = await Promise.all([
60307
- Promise.resolve().then(() => require("./index-YSWS94Jr-C7xFStTB.cjs")),
60307
+ Promise.resolve().then(() => require("./index-Bjv0_slj-CIZ6x5_a.cjs")),
60308
60308
  Promise.resolve().then(() => require("./index-DRCvimau-H4Ck3S9a.cjs")),
60309
60309
  Promise.resolve().then(() => require("./index-C_x_N6Uh-Db3CUJMX.cjs")),
60310
60310
  Promise.resolve().then(() => require("./index-D_sWOSiG-BtDZzJ6I.cjs")),
@@ -60509,7 +60509,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
60509
60509
  * Process collaboration migrations
60510
60510
  */
60511
60511
  processCollaborationMigrations() {
60512
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.65");
60512
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.66");
60513
60513
  if (!this.options.ydoc) return;
60514
60514
  const metaMap = this.options.ydoc.getMap("meta");
60515
60515
  let docVersion = metaMap.get("version");
@@ -68014,6 +68014,7 @@ function tableNodeToBlock(node, nextBlockId, positions, defaultFont, defaultSize
68014
68014
  let measurementCanvas = null;
68015
68015
  let measurementCtx = null;
68016
68016
  const TAB_CHAR_LENGTH = 1;
68017
+ const SPACE_CHARS = /* @__PURE__ */ new Set([" ", " "]);
68017
68018
  const isTabRun$1 = (run2) => run2?.kind === "tab";
68018
68019
  function getMeasurementContext() {
68019
68020
  if (measurementCtx) return measurementCtx;
@@ -68030,6 +68031,41 @@ function getMeasurementContext() {
68030
68031
  }
68031
68032
  return measurementCtx;
68032
68033
  }
68034
+ const countSpaces = (text) => {
68035
+ let spaces = 0;
68036
+ for (let i = 0; i < text.length; i += 1) {
68037
+ if (SPACE_CHARS.has(text[i])) {
68038
+ spaces += 1;
68039
+ }
68040
+ }
68041
+ return spaces;
68042
+ };
68043
+ const getJustifyAdjustment = (block, line, availableWidthOverride) => {
68044
+ if (block.kind !== "paragraph") {
68045
+ return { extraPerSpace: 0, totalSpaces: 0 };
68046
+ }
68047
+ const alignment2 = block.attrs?.alignment;
68048
+ const hasExplicitPositioning = line.segments?.some((seg) => seg.x !== void 0);
68049
+ const availableWidth = availableWidthOverride ?? line.maxWidth ?? line.width;
68050
+ const slack = Math.max(0, availableWidth - line.width);
68051
+ if (alignment2 !== "justify" || hasExplicitPositioning || slack <= 0) {
68052
+ return { extraPerSpace: 0, totalSpaces: 0 };
68053
+ }
68054
+ const runs = sliceRunsForLine$1(block, line);
68055
+ const totalSpaces = runs.reduce((sum, run2) => {
68056
+ if (isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation") {
68057
+ return sum;
68058
+ }
68059
+ return sum + countSpaces(run2.text ?? "");
68060
+ }, 0);
68061
+ if (totalSpaces <= 0) {
68062
+ return { extraPerSpace: 0, totalSpaces: 0 };
68063
+ }
68064
+ return {
68065
+ extraPerSpace: slack / totalSpaces,
68066
+ totalSpaces
68067
+ };
68068
+ };
68033
68069
  function getRunFontString(run2) {
68034
68070
  if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || "src" in run2) {
68035
68071
  return "normal normal 16px Arial";
@@ -68087,9 +68123,15 @@ function sliceRunsForLine$1(block, line) {
68087
68123
  }
68088
68124
  return result;
68089
68125
  }
68090
- function measureCharacterX(block, line, charOffset) {
68126
+ function measureCharacterX(block, line, charOffset, availableWidthOverride) {
68091
68127
  const ctx2 = getMeasurementContext();
68128
+ const availableWidth = availableWidthOverride ?? line.maxWidth ?? // Fallback: if no maxWidth, approximate available width as line width (no slack)
68129
+ line.width;
68130
+ const justify = getJustifyAdjustment(block, line, availableWidth);
68131
+ const renderedLineWidth = line.width + Math.max(0, availableWidth - line.width);
68132
+ const alignment2 = block.kind === "paragraph" ? block.attrs?.alignment : void 0;
68092
68133
  const hasExplicitPositioning = line.segments?.some((seg) => seg.x !== void 0);
68134
+ const alignmentOffset = !hasExplicitPositioning && alignment2 === "center" ? Math.max(0, (availableWidth - renderedLineWidth) / 2) : !hasExplicitPositioning && alignment2 === "right" ? Math.max(0, availableWidth - renderedLineWidth) : 0;
68093
68135
  if (hasExplicitPositioning && line.segments && ctx2) {
68094
68136
  return measureCharacterXSegmentBased(block, line, charOffset, ctx2);
68095
68137
  }
@@ -68104,11 +68146,12 @@ function measureCharacterX(block, line, charOffset) {
68104
68146
  return sum + (run2.text ?? "").length;
68105
68147
  }, 0)
68106
68148
  );
68107
- return charOffset / charsInLine * line.width;
68149
+ return charOffset / charsInLine * renderedLineWidth;
68108
68150
  }
68109
68151
  const runs = sliceRunsForLine$1(block, line);
68110
68152
  let currentX = 0;
68111
68153
  let currentCharOffset = 0;
68154
+ let spaceTally = 0;
68112
68155
  for (const run2 of runs) {
68113
68156
  if (isTabRun$1(run2)) {
68114
68157
  const runLength2 = TAB_CHAR_LENGTH;
@@ -68129,14 +68172,18 @@ function measureCharacterX(block, line, charOffset) {
68129
68172
  const textUpToTarget = text.slice(0, offsetInRun);
68130
68173
  const measured2 = ctx2.measureText(textUpToTarget);
68131
68174
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
68132
- return currentX + measured2.width + spacingWidth;
68175
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToTarget) : 0;
68176
+ return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
68133
68177
  }
68134
68178
  ctx2.font = getRunFontString(run2);
68135
68179
  const measured = ctx2.measureText(text);
68136
- currentX += measured.width + computeLetterSpacingWidth(run2, runLength, runLength);
68180
+ const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
68181
+ const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
68182
+ currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
68183
+ spaceTally += spacesInRun;
68137
68184
  currentCharOffset += runLength;
68138
68185
  }
68139
- return currentX;
68186
+ return alignmentOffset + currentX;
68140
68187
  }
68141
68188
  function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
68142
68189
  if (block.kind !== "paragraph" || !line.segments) return 0;
@@ -68211,8 +68258,15 @@ function charOffsetToPm(block, line, charOffset, fallbackPmStart) {
68211
68258
  }
68212
68259
  return lastPm;
68213
68260
  }
68214
- function findCharacterAtX(block, line, x2, pmStart) {
68261
+ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride) {
68215
68262
  const ctx2 = getMeasurementContext();
68263
+ const availableWidth = availableWidthOverride ?? line.maxWidth ?? // Fallback: approximate with line width when no maxWidth is present
68264
+ line.width;
68265
+ const justify = getJustifyAdjustment(block, line, availableWidth);
68266
+ const renderedLineWidth = line.width + Math.max(0, availableWidth - line.width);
68267
+ const alignment2 = block.kind === "paragraph" ? block.attrs?.alignment : void 0;
68268
+ const hasExplicitPositioning = line.segments?.some((seg) => seg.x !== void 0);
68269
+ const alignmentOffset = !hasExplicitPositioning && alignment2 === "center" ? Math.max(0, (availableWidth - renderedLineWidth) / 2) : !hasExplicitPositioning && alignment2 === "right" ? Math.max(0, availableWidth - renderedLineWidth) : 0;
68216
68270
  if (!ctx2) {
68217
68271
  const runs2 = sliceRunsForLine$1(block, line);
68218
68272
  const charsInLine = Math.max(
@@ -68224,7 +68278,7 @@ function findCharacterAtX(block, line, x2, pmStart) {
68224
68278
  return sum + (run2.text ?? "").length;
68225
68279
  }, 0)
68226
68280
  );
68227
- const ratio = Math.max(0, Math.min(1, x2 / line.width));
68281
+ const ratio = Math.max(0, Math.min(1, (x2 - alignmentOffset) / renderedLineWidth));
68228
68282
  const charOffset = Math.round(ratio * charsInLine);
68229
68283
  const pmPosition2 = charOffsetToPm(block, line, charOffset, pmStart);
68230
68284
  return {
@@ -68233,9 +68287,10 @@ function findCharacterAtX(block, line, x2, pmStart) {
68233
68287
  };
68234
68288
  }
68235
68289
  const runs = sliceRunsForLine$1(block, line);
68236
- const safeX = Math.max(0, Math.min(line.width, x2));
68290
+ const safeX = Math.max(0, Math.min(renderedLineWidth, x2 - alignmentOffset));
68237
68291
  let currentX = 0;
68238
68292
  let currentCharOffset = 0;
68293
+ let spaceTally = 0;
68239
68294
  for (const run2 of runs) {
68240
68295
  if (isTabRun$1(run2)) {
68241
68296
  const tabWidth = run2.width ?? 0;
@@ -68262,7 +68317,8 @@ function findCharacterAtX(block, line, x2, pmStart) {
68262
68317
  for (let i = 0; i <= runLength; i++) {
68263
68318
  const textUpToChar = text.slice(0, i);
68264
68319
  const measured2 = ctx2.measureText(textUpToChar);
68265
- const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i, runLength);
68320
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
68321
+ const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
68266
68322
  if (charX >= safeX) {
68267
68323
  if (i === 0) {
68268
68324
  const pmPosition3 = charOffsetToPm(block, line, currentCharOffset, pmStart);
@@ -68285,7 +68341,10 @@ function findCharacterAtX(block, line, x2, pmStart) {
68285
68341
  }
68286
68342
  }
68287
68343
  const measured = ctx2.measureText(text);
68288
- currentX += measured.width + computeLetterSpacingWidth(run2, runLength, runLength);
68344
+ const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
68345
+ const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
68346
+ currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
68347
+ spaceTally += spacesInRun;
68289
68348
  currentCharOffset += runLength;
68290
68349
  }
68291
68350
  const pmPosition = charOffsetToPm(block, line, currentCharOffset, pmStart);
@@ -80902,7 +80961,10 @@ function clickToPosition(layout, blocks, measures, containerPoint, domContainer,
80902
80961
  }
80903
80962
  const line = measure.lines[lineIndex];
80904
80963
  const isRTL = isRtlBlock(block);
80905
- const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL);
80964
+ const paraIndentLeft = block.attrs?.indent?.left ?? 0;
80965
+ const paraIndentRight = block.attrs?.indent?.right ?? 0;
80966
+ const availableWidth = Math.max(0, fragment.width - (paraIndentLeft + paraIndentRight));
80967
+ const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment.x, isRTL, availableWidth);
80906
80968
  if (pos == null) {
80907
80969
  logClickStage("warn", "no-position", {
80908
80970
  blockId: fragment.blockId
@@ -80933,7 +80995,10 @@ function clickToPosition(layout, blocks, measures, containerPoint, domContainer,
80933
80995
  if (lineIndex != null) {
80934
80996
  const line = cellMeasure.lines[lineIndex];
80935
80997
  const isRTL = isRtlBlock(cellBlock);
80936
- const pos = mapPointToPm(cellBlock, line, localX, isRTL);
80998
+ const paraIndentLeft = cellBlock.attrs?.indent?.left ?? 0;
80999
+ const paraIndentRight = cellBlock.attrs?.indent?.right ?? 0;
81000
+ const availableWidth = Math.max(0, tableHit.fragment.width - (paraIndentLeft + paraIndentRight));
81001
+ const pos = mapPointToPm(cellBlock, line, localX, isRTL, availableWidth);
80937
81002
  if (pos != null) {
80938
81003
  logClickStage("log", "success", {
80939
81004
  blockId: tableHit.fragment.blockId,
@@ -81092,7 +81157,15 @@ function selectionToRects(layout, blocks, measures, from2, to) {
81092
81157
  const startX = mapPmToX(block, line, charOffsetFrom, fragment.width);
81093
81158
  const endX = mapPmToX(block, line, charOffsetTo, fragment.width);
81094
81159
  const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
81095
- const rectX = fragment.x + markerWidth + Math.min(startX, endX);
81160
+ const paraIndentLeft = block.attrs?.indent?.left ?? 0;
81161
+ const firstLineOffset = (block.attrs?.indent?.firstLine ?? 0) - (block.attrs?.indent?.hanging ?? 0);
81162
+ const isFirstLine = index2 === fragment.fromLine;
81163
+ const isListFirstLine = isFirstLine && !fragment.continuesFromPrev && (fragment.markerWidth ?? 0) > 0;
81164
+ let indentAdjust = 0;
81165
+ if (!isListFirstLine) {
81166
+ indentAdjust = paraIndentLeft + (isFirstLine ? firstLineOffset : 0);
81167
+ }
81168
+ const rectX = fragment.x + markerWidth + indentAdjust + Math.min(startX, endX);
81096
81169
  const rectWidth = Math.max(1, Math.abs(endX - startX));
81097
81170
  const lineOffset = lineHeightBeforeIndex(measure, index2) - lineHeightBeforeIndex(measure, fragment.fromLine);
81098
81171
  const rectY = fragment.y + lineOffset;
@@ -81468,11 +81541,11 @@ const lineHeightBeforeIndex = (measure, absoluteLineIndex) => {
81468
81541
  }
81469
81542
  return height;
81470
81543
  };
81471
- const mapPointToPm = (block, line, x2, isRTL) => {
81544
+ const mapPointToPm = (block, line, x2, isRTL, availableWidthOverride) => {
81472
81545
  if (block.kind !== "paragraph") return null;
81473
81546
  const range2 = computeLinePmRange(block, line);
81474
81547
  if (range2.pmStart == null || range2.pmEnd == null) return null;
81475
- const result = findCharacterAtX(block, line, x2, range2.pmStart);
81548
+ const result = findCharacterAtX(block, line, x2, range2.pmStart, availableWidthOverride);
81476
81549
  if (isRTL) {
81477
81550
  const charOffset = result.charOffset;
81478
81551
  const charsInLine = Math.max(1, line.toChar - line.fromChar);
@@ -81483,7 +81556,10 @@ const mapPointToPm = (block, line, x2, isRTL) => {
81483
81556
  };
81484
81557
  const mapPmToX = (block, line, offset2, fragmentWidth) => {
81485
81558
  if (fragmentWidth <= 0 || line.width <= 0) return 0;
81486
- return measureCharacterX(block, line, offset2);
81559
+ const paraIndentLeft = block.kind === "paragraph" ? block.attrs?.indent?.left ?? 0 : 0;
81560
+ const paraIndentRight = block.kind === "paragraph" ? block.attrs?.indent?.right ?? 0 : 0;
81561
+ const availableWidth = Math.max(0, fragmentWidth - (paraIndentLeft + paraIndentRight));
81562
+ return measureCharacterX(block, line, offset2, availableWidth);
81487
81563
  };
81488
81564
  const isRtlBlock = (block) => {
81489
81565
  if (block.kind !== "paragraph") return false;
@@ -84148,29 +84224,16 @@ ensureEditorHost_fn = function(pageElement, kind, decorationContainer) {
84148
84224
  }
84149
84225
  return editorHost;
84150
84226
  };
84151
- positionEditorHost_fn = function(editorHost, region, decorationContainer, zoom) {
84227
+ positionEditorHost_fn = function(editorHost, region, decorationContainer, _zoom) {
84152
84228
  const pageElement = editorHost.parentElement;
84153
84229
  if (!pageElement) {
84154
84230
  console.error("[EditorOverlayManager] Editor host has no parent element");
84155
84231
  return;
84156
84232
  }
84157
- let top2;
84158
- let left2;
84159
- let width;
84160
- let height;
84161
- if (decorationContainer) {
84162
- const decorationRect = decorationContainer.getBoundingClientRect();
84163
- const pageRect = pageElement.getBoundingClientRect();
84164
- top2 = decorationRect.top - pageRect.top;
84165
- left2 = decorationRect.left - pageRect.left;
84166
- width = decorationRect.width;
84167
- height = decorationRect.height;
84168
- } else {
84169
- top2 = region.localY * zoom;
84170
- left2 = region.localX * zoom;
84171
- width = region.width * zoom;
84172
- height = region.height * zoom;
84173
- }
84233
+ const top2 = decorationContainer?.offsetTop ?? region.localY;
84234
+ const left2 = decorationContainer?.offsetLeft ?? region.localX;
84235
+ const width = decorationContainer?.offsetWidth ?? region.width;
84236
+ const height = decorationContainer?.offsetHeight ?? region.height;
84174
84237
  Object.assign(editorHost.style, {
84175
84238
  top: `${top2}px`,
84176
84239
  left: `${left2}px`,
@@ -84185,19 +84248,14 @@ positionEditorHost_fn = function(editorHost, region, decorationContainer, zoom)
84185
84248
  }
84186
84249
  }
84187
84250
  };
84188
- showHeaderFooterBorder_fn = function(pageElement, region, decorationContainer, zoom) {
84251
+ showHeaderFooterBorder_fn = function(pageElement, region, decorationContainer, _zoom) {
84189
84252
  __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
84190
84253
  __privateSet(this, _borderLine, document.createElement("div"));
84191
84254
  __privateGet$1(this, _borderLine).className = "superdoc-header-footer-border";
84192
- let topPosition;
84193
84255
  const isHeader = region.kind === "header";
84194
- if (decorationContainer) {
84195
- const decorationRect = decorationContainer.getBoundingClientRect();
84196
- const pageRect = pageElement.getBoundingClientRect();
84197
- topPosition = isHeader ? decorationRect.bottom - pageRect.top : decorationRect.top - pageRect.top;
84198
- } else {
84199
- topPosition = isHeader ? (region.localY + region.height) * zoom : region.localY * zoom;
84200
- }
84256
+ const decorationTop = decorationContainer?.offsetTop;
84257
+ const decorationHeight = decorationContainer?.offsetHeight;
84258
+ const topPosition = isHeader ? decorationTop != null && decorationHeight != null ? decorationTop + decorationHeight : region.localY + region.height : decorationTop ?? region.localY;
84201
84259
  Object.assign(__privateGet$1(this, _borderLine).style, {
84202
84260
  position: "absolute",
84203
84261
  left: "0",
@@ -85310,8 +85368,10 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
85310
85368
  const start2 = Math.min(from2, to);
85311
85369
  const end2 = Math.max(from2, to);
85312
85370
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
85313
- const overlayRect = __privateGet$1(this, _selectionOverlay2).getBoundingClientRect();
85314
85371
  const relativeRect = relativeTo?.getBoundingClientRect() ?? null;
85372
+ const containerRect = __privateGet$1(this, _visibleHost).getBoundingClientRect();
85373
+ const scrollLeft = __privateGet$1(this, _visibleHost).scrollLeft ?? 0;
85374
+ const scrollTop = __privateGet$1(this, _visibleHost).scrollTop ?? 0;
85315
85375
  const layoutRectSource = () => {
85316
85376
  if (__privateGet$1(this, _session).mode !== "body") {
85317
85377
  return __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterSelectionRects_fn).call(this, start2, end2);
@@ -85322,14 +85382,38 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
85322
85382
  };
85323
85383
  const rawRects = layoutRectSource();
85324
85384
  if (!rawRects.length) return [];
85385
+ const domCaretStart = __privateMethod$1(this, _PresentationEditor_instances, computeDomCaretPageLocal_fn).call(this, start2);
85386
+ const domCaretEnd = __privateMethod$1(this, _PresentationEditor_instances, computeDomCaretPageLocal_fn).call(this, end2);
85387
+ const layoutCaretStart = __privateMethod$1(this, _PresentationEditor_instances, computeCaretLayoutRectGeometry_fn).call(this, start2, false);
85388
+ __privateMethod$1(this, _PresentationEditor_instances, computeCaretLayoutRectGeometry_fn).call(this, end2, false);
85389
+ const pageDelta = {};
85390
+ if (domCaretStart && layoutCaretStart && domCaretStart.pageIndex === layoutCaretStart.pageIndex) {
85391
+ pageDelta[domCaretStart.pageIndex] = {
85392
+ dx: domCaretStart.x - layoutCaretStart.x,
85393
+ dy: domCaretStart.y - layoutCaretStart.y
85394
+ };
85395
+ }
85325
85396
  const pageHeight = __privateGet$1(this, _session).mode === "body" ? __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this) : __privateMethod$1(this, _PresentationEditor_instances, getHeaderFooterPageHeight_fn).call(this);
85326
85397
  const pageGap = __privateGet$1(this, _layoutState).layout?.pageGap ?? 0;
85327
- return rawRects.map((rect) => {
85328
- const pageLocalY = rect.y - rect.pageIndex * (pageHeight + pageGap);
85329
- const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, rect.pageIndex, rect.x, pageLocalY);
85398
+ const finalRects = rawRects.map((rect, idx, allRects) => {
85399
+ const delta = pageDelta[rect.pageIndex];
85400
+ let adjustedX = delta ? rect.x + delta.dx : rect.x;
85401
+ const adjustedY = delta ? rect.y + delta.dy : rect.y;
85402
+ const isFirstRect = idx === 0;
85403
+ const isLastRect = idx === allRects.length - 1;
85404
+ if (isFirstRect && domCaretStart && rect.pageIndex === domCaretStart.pageIndex) {
85405
+ adjustedX = domCaretStart.x;
85406
+ }
85407
+ if (isLastRect && domCaretEnd && rect.pageIndex === domCaretEnd.pageIndex) {
85408
+ const endX = domCaretEnd.x;
85409
+ const newWidth = Math.max(1, endX - adjustedX);
85410
+ rect = { ...rect, width: newWidth };
85411
+ }
85412
+ const pageLocalY = adjustedY - rect.pageIndex * (pageHeight + pageGap);
85413
+ const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, rect.pageIndex, adjustedX, pageLocalY);
85330
85414
  if (!coords) return null;
85331
- const absLeft = coords.x * zoom + overlayRect.left;
85332
- const absTop = coords.y * zoom + overlayRect.top;
85415
+ const absLeft = coords.x * zoom - scrollLeft + containerRect.left;
85416
+ const absTop = coords.y * zoom - scrollTop + containerRect.top;
85333
85417
  const left2 = relativeRect ? absLeft - relativeRect.left : absLeft;
85334
85418
  const top2 = relativeRect ? absTop - relativeRect.top : absTop;
85335
85419
  const width = Math.max(1, rect.width * zoom);
@@ -85344,6 +85428,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
85344
85428
  height
85345
85429
  };
85346
85430
  }).filter((rect) => Boolean(rect));
85431
+ return finalRects;
85347
85432
  }
85348
85433
  /**
85349
85434
  * Get selection bounds for a document range with aggregated bounding box.
@@ -85572,24 +85657,22 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
85572
85657
  return null;
85573
85658
  }
85574
85659
  const rect2 = rects2[0];
85575
- const overlayRect = __privateGet$1(this, _selectionOverlay2)?.getBoundingClientRect();
85576
- if (!overlayRect) {
85577
- return null;
85578
- }
85660
+ const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
85661
+ const containerRect = __privateGet$1(this, _visibleHost).getBoundingClientRect();
85662
+ const scrollLeft = __privateGet$1(this, _visibleHost).scrollLeft ?? 0;
85663
+ const scrollTop = __privateGet$1(this, _visibleHost).scrollTop ?? 0;
85579
85664
  const pageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
85580
85665
  const pageGap = __privateGet$1(this, _layoutState).layout?.pageGap ?? 0;
85581
85666
  const pageLocalY = rect2.y - rect2.pageIndex * (pageHeight + pageGap);
85582
85667
  const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, rect2.pageIndex, rect2.x, pageLocalY);
85583
- if (!coords) {
85584
- return null;
85585
- }
85668
+ if (!coords) return null;
85586
85669
  return {
85587
- top: coords.y + overlayRect.top,
85588
- bottom: coords.y + overlayRect.top + rect2.height,
85589
- left: coords.x + overlayRect.left,
85590
- right: coords.x + overlayRect.left + rect2.width,
85591
- width: rect2.width,
85592
- height: rect2.height
85670
+ top: coords.y * zoom - scrollTop + containerRect.top,
85671
+ bottom: coords.y * zoom - scrollTop + containerRect.top + rect2.height * zoom,
85672
+ left: coords.x * zoom - scrollLeft + containerRect.left,
85673
+ right: coords.x * zoom - scrollLeft + containerRect.left + rect2.width * zoom,
85674
+ width: rect2.width * zoom,
85675
+ height: rect2.height * zoom
85593
85676
  };
85594
85677
  }
85595
85678
  const rects = this.getRangeRects(pos, pos);
@@ -86955,7 +87038,7 @@ updateSelection_fn = function() {
86955
87038
  }
86956
87039
  try {
86957
87040
  __privateGet$1(this, _localSelectionLayer).innerHTML = "";
86958
- __privateMethod$1(this, _PresentationEditor_instances, renderCaretOverlay_fn).call(this, caretLayout);
87041
+ __privateMethod$1(this, _PresentationEditor_instances, renderCaretOverlay_fn).call(this, caretLayout, from2);
86959
87042
  } catch (error) {
86960
87043
  if (process$1$1.env.NODE_ENV === "development") {
86961
87044
  console.warn("[PresentationEditor] Failed to render caret overlay:", error);
@@ -86964,9 +87047,12 @@ updateSelection_fn = function() {
86964
87047
  return;
86965
87048
  }
86966
87049
  const rects = selectionToRects(layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, from2, to) ?? [];
87050
+ const domStart = __privateMethod$1(this, _PresentationEditor_instances, computeDomCaretPageLocal_fn).call(this, from2);
87051
+ const domEnd = __privateMethod$1(this, _PresentationEditor_instances, computeDomCaretPageLocal_fn).call(this, to);
87052
+ const correctedRects = __privateMethod$1(this, _PresentationEditor_instances, applyDomCorrectionToRects_fn).call(this, rects, domStart, domEnd);
86967
87053
  try {
86968
87054
  __privateGet$1(this, _localSelectionLayer).innerHTML = "";
86969
- __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, rects);
87055
+ __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, correctedRects);
86970
87056
  } catch (error) {
86971
87057
  if (process$1$1.env.NODE_ENV === "development") {
86972
87058
  console.warn("[PresentationEditor] Failed to render selection rects:", error);
@@ -87741,6 +87827,43 @@ getHeaderFooterPageHeight_fn = function() {
87741
87827
  }
87742
87828
  return context.layout.pageSize?.h ?? context.region.height ?? 1;
87743
87829
  };
87830
+ applyDomCorrectionToRects_fn = function(rects, domStart, domEnd) {
87831
+ if (rects.length === 0) return rects;
87832
+ const pageDelta = {};
87833
+ if (domStart && rects[0] && domStart.pageIndex === rects[0].pageIndex) {
87834
+ const pageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
87835
+ const pageGap = __privateGet$1(this, _layoutState).layout?.pageGap ?? 0;
87836
+ const layoutY = rects[0].y - rects[0].pageIndex * (pageHeight + pageGap);
87837
+ pageDelta[domStart.pageIndex] = {
87838
+ dx: domStart.x - rects[0].x,
87839
+ dy: domStart.y - layoutY
87840
+ };
87841
+ }
87842
+ return rects.map((rect, idx) => {
87843
+ const delta = pageDelta[rect.pageIndex];
87844
+ let adjustedX = delta ? rect.x + delta.dx : rect.x;
87845
+ let adjustedY = delta ? rect.y + delta.dy : rect.y;
87846
+ let adjustedWidth = rect.width;
87847
+ const isFirstRect = idx === 0;
87848
+ const isLastRect = idx === rects.length - 1;
87849
+ if (isFirstRect && domStart && rect.pageIndex === domStart.pageIndex) {
87850
+ const pageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
87851
+ const pageGap = __privateGet$1(this, _layoutState).layout?.pageGap ?? 0;
87852
+ adjustedX = domStart.x;
87853
+ adjustedY = domStart.y + rect.pageIndex * (pageHeight + pageGap);
87854
+ }
87855
+ if (isLastRect && domEnd && rect.pageIndex === domEnd.pageIndex) {
87856
+ const endX = domEnd.x;
87857
+ adjustedWidth = Math.max(1, endX - adjustedX);
87858
+ }
87859
+ return {
87860
+ ...rect,
87861
+ x: adjustedX,
87862
+ y: adjustedY,
87863
+ width: adjustedWidth
87864
+ };
87865
+ });
87866
+ };
87744
87867
  renderSelectionRects_fn = function(rects) {
87745
87868
  const localSelectionLayer = __privateGet$1(this, _localSelectionLayer);
87746
87869
  if (!localSelectionLayer) {
@@ -87748,7 +87871,7 @@ renderSelectionRects_fn = function(rects) {
87748
87871
  }
87749
87872
  const pageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
87750
87873
  const pageGap = __privateGet$1(this, _layoutState).layout?.pageGap ?? 0;
87751
- rects.forEach((rect, _index) => {
87874
+ rects.forEach((rect) => {
87752
87875
  const pageLocalY = rect.y - rect.pageIndex * (pageHeight + pageGap);
87753
87876
  const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, rect.pageIndex, rect.x, pageLocalY);
87754
87877
  if (!coords) {
@@ -87801,7 +87924,7 @@ clearHoverRegion_fn = function() {
87801
87924
  __privateGet$1(this, _hoverTooltip).style.display = "none";
87802
87925
  }
87803
87926
  };
87804
- renderCaretOverlay_fn = function(caretLayout) {
87927
+ renderCaretOverlay_fn = function(caretLayout, pos) {
87805
87928
  if (!__privateGet$1(this, _localSelectionLayer)) {
87806
87929
  return;
87807
87930
  }
@@ -88013,6 +88136,46 @@ convertPageLocalToOverlayCoords_fn = function(pageIndex, pageLocalX, pageLocalY)
88013
88136
  y: pageIndex * (pageHeight + pageGap) + pageLocalY
88014
88137
  };
88015
88138
  };
88139
+ computeDomCaretPageLocal_fn = function(pos) {
88140
+ __privateGet$1(this, _viewportHost).querySelector(`.superdoc-page span[data-pm-start][data-pm-end]`) ? __privateGet$1(this, _viewportHost).querySelector(`.superdoc-page`) : null;
88141
+ const spans = Array.from(__privateGet$1(this, _viewportHost).querySelectorAll("span[data-pm-start][data-pm-end]"));
88142
+ let targetSpan = null;
88143
+ for (const span of spans) {
88144
+ const pmStart2 = Number(span.dataset.pmStart ?? "NaN");
88145
+ const pmEnd = Number(span.dataset.pmEnd ?? "NaN");
88146
+ if (!Number.isFinite(pmStart2) || !Number.isFinite(pmEnd)) continue;
88147
+ if (pos < pmStart2 || pos > pmEnd) continue;
88148
+ targetSpan = span;
88149
+ break;
88150
+ }
88151
+ if (!targetSpan) return null;
88152
+ const page = targetSpan.closest(".superdoc-page");
88153
+ if (!page) return null;
88154
+ const pageRect = page.getBoundingClientRect();
88155
+ const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
88156
+ const textNode = targetSpan.firstChild;
88157
+ if (!textNode || textNode.nodeType !== Node.TEXT_NODE) {
88158
+ const spanRect = targetSpan.getBoundingClientRect();
88159
+ return {
88160
+ pageIndex: Number(page.dataset.pageIndex ?? "0"),
88161
+ x: (spanRect.left - pageRect.left) / zoom,
88162
+ y: (spanRect.top - pageRect.top) / zoom
88163
+ };
88164
+ }
88165
+ const pmStart = Number(targetSpan.dataset.pmStart ?? "NaN");
88166
+ const charIndex = Math.min(pos - pmStart, textNode.length);
88167
+ const range2 = document.createRange();
88168
+ range2.setStart(textNode, Math.max(0, charIndex));
88169
+ range2.setEnd(textNode, Math.max(0, charIndex));
88170
+ const rangeRect = range2.getBoundingClientRect();
88171
+ const lineEl = targetSpan.closest(".superdoc-line");
88172
+ const lineRect = lineEl?.getBoundingClientRect() ?? rangeRect;
88173
+ return {
88174
+ pageIndex: Number(page.dataset.pageIndex ?? "0"),
88175
+ x: (rangeRect.left - pageRect.left) / zoom,
88176
+ y: (lineRect.top - pageRect.top) / zoom
88177
+ };
88178
+ };
88016
88179
  normalizeClientPoint_fn = function(clientX, clientY) {
88017
88180
  if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
88018
88181
  return null;
@@ -88026,13 +88189,9 @@ normalizeClientPoint_fn = function(clientX, clientY) {
88026
88189
  y: (clientY - rect.top + scrollTop) / zoom
88027
88190
  };
88028
88191
  };
88029
- computeCaretLayoutRect_fn = function(pos) {
88192
+ computeCaretLayoutRectGeometry_fn = function(pos, includeDomFallback = true) {
88030
88193
  const layout = __privateGet$1(this, _layoutState).layout;
88031
88194
  if (!layout) return null;
88032
- const domResult = __privateMethod$1(this, _PresentationEditor_instances, computeCaretLayoutRectFromDOM_fn).call(this, pos);
88033
- if (domResult) {
88034
- return domResult;
88035
- }
88036
88195
  const hit = getFragmentAtPosition(layout, __privateGet$1(this, _layoutState).blocks, __privateGet$1(this, _layoutState).measures, pos);
88037
88196
  if (!hit) {
88038
88197
  return null;
@@ -88054,101 +88213,75 @@ computeCaretLayoutRect_fn = function(pos) {
88054
88213
  const { line, index: index2 } = lineInfo;
88055
88214
  const range2 = computeLinePmRange(block, line);
88056
88215
  if (range2.pmStart == null || range2.pmEnd == null) return null;
88057
- const pmCharsInLine = Math.max(1, range2.pmEnd - range2.pmStart);
88058
- const pmOffset = Math.max(0, Math.min(pmCharsInLine, pos - range2.pmStart));
88059
- const localX = fragment.x + measureCharacterX(block, line, pmOffset);
88216
+ const pmOffset = pmPosToCharOffset(block, line, pos);
88217
+ const markerWidth = fragment.markerWidth ?? measure.marker?.markerWidth ?? 0;
88218
+ const paraIndentLeft = block.attrs?.indent?.left ?? 0;
88219
+ const paraIndentRight = block.attrs?.indent?.right ?? 0;
88220
+ const availableWidth = Math.max(0, fragment.width - (paraIndentLeft + paraIndentRight));
88221
+ const charX = measureCharacterX(block, line, pmOffset, availableWidth);
88222
+ const firstLineOffset = (block.attrs?.indent?.firstLine ?? 0) - (block.attrs?.indent?.hanging ?? 0);
88223
+ const isFirstLine = index2 === fragment.fromLine;
88224
+ const isListFirstLine = isFirstLine && !fragment.continuesFromPrev && (fragment.markerWidth ?? 0) > 0;
88225
+ let indentAdjust = 0;
88226
+ if (!isListFirstLine) {
88227
+ indentAdjust = paraIndentLeft + (isFirstLine ? firstLineOffset : 0);
88228
+ }
88229
+ const localX = fragment.x + markerWidth + indentAdjust + charX;
88060
88230
  const lineOffset = __privateMethod$1(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, fragment.fromLine, index2);
88061
88231
  const localY = fragment.y + lineOffset;
88062
- return {
88232
+ const result = {
88063
88233
  pageIndex: hit.pageIndex,
88064
88234
  x: localX,
88065
88235
  y: localY,
88066
88236
  height: line.lineHeight
88067
88237
  };
88068
- };
88069
- computeCaretLayoutRectFromDOM_fn = function(pos) {
88070
- const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
88071
- let targetPageEl = null;
88072
- if (__privateGet$1(this, _layoutState).layout && __privateGet$1(this, _layoutState).blocks && __privateGet$1(this, _layoutState).measures) {
88073
- const fragmentHit = getFragmentAtPosition(
88074
- __privateGet$1(this, _layoutState).layout,
88075
- __privateGet$1(this, _layoutState).blocks,
88076
- __privateGet$1(this, _layoutState).measures,
88077
- pos
88078
- );
88079
- if (fragmentHit) {
88080
- const pageEl = __privateGet$1(this, _viewportHost).querySelector(
88081
- `.superdoc-page[data-page-index="${fragmentHit.pageIndex}"]`
88082
- );
88083
- if (pageEl) {
88084
- targetPageEl = pageEl;
88085
- }
88086
- }
88087
- }
88088
- const spanEls = Array.from(
88089
- targetPageEl ? targetPageEl.querySelectorAll(`span[data-pm-start][data-pm-end]:not(.${DOM_CLASS_NAMES.INLINE_SDT_WRAPPER})`) : __privateGet$1(this, _viewportHost).querySelectorAll(
88090
- `span[data-pm-start][data-pm-end]:not(.${DOM_CLASS_NAMES.INLINE_SDT_WRAPPER})`
88091
- )
88238
+ const pageEl = __privateGet$1(this, _painterHost)?.querySelector(
88239
+ `.superdoc-page[data-page-index="${hit.pageIndex}"]`
88092
88240
  );
88241
+ const pageRect = pageEl?.getBoundingClientRect();
88242
+ const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
88243
+ let domCaretX = null;
88244
+ let domCaretY = null;
88245
+ const spanEls = pageEl?.querySelectorAll("span[data-pm-start][data-pm-end]") ?? [];
88093
88246
  for (const spanEl of spanEls) {
88094
- const pmStart = Number(spanEl.dataset.pmStart ?? "NaN");
88095
- const pmEnd = Number(spanEl.dataset.pmEnd ?? "NaN");
88096
- if (!Number.isFinite(pmStart) || !Number.isFinite(pmEnd)) continue;
88097
- if (pos < pmStart || pos > pmEnd) continue;
88098
- const pageEl = spanEl.closest(".superdoc-page");
88099
- if (!pageEl) continue;
88100
- const pageIndex = Number(pageEl.dataset.pageIndex ?? "0");
88101
- const pageRect = pageEl.getBoundingClientRect();
88102
- const textNode = spanEl.firstChild;
88103
- if (!textNode || textNode.nodeType !== Node.TEXT_NODE) {
88104
- const spanRect2 = spanEl.getBoundingClientRect();
88105
- return {
88106
- pageIndex,
88107
- x: (spanRect2.left - pageRect.left) / zoom,
88108
- y: (spanRect2.top - pageRect.top) / zoom,
88109
- height: spanRect2.height / zoom
88110
- };
88111
- }
88112
- const text = textNode.textContent ?? "";
88113
- const charOffset = Math.max(0, Math.min(text.length, pos - pmStart));
88114
- const range2 = document.createRange();
88115
- try {
88116
- range2.setStart(textNode, charOffset);
88117
- range2.setEnd(textNode, charOffset);
88118
- } catch (error) {
88119
- if (process$1$1.env.NODE_ENV === "development") {
88120
- console.warn("[PresentationEditor] Range.setStart/setEnd failed:", {
88121
- error: error instanceof Error ? error.message : String(error),
88122
- charOffset,
88123
- textLength: text.length,
88124
- pos,
88125
- pmStart,
88126
- pmEnd
88127
- });
88247
+ const pmStart = Number(spanEl.dataset.pmStart);
88248
+ const pmEnd = Number(spanEl.dataset.pmEnd);
88249
+ if (pos >= pmStart && pos <= pmEnd && spanEl.firstChild?.nodeType === Node.TEXT_NODE) {
88250
+ const textNode = spanEl.firstChild;
88251
+ const charIndex = Math.min(pos - pmStart, textNode.length);
88252
+ const rangeObj = document.createRange();
88253
+ rangeObj.setStart(textNode, charIndex);
88254
+ rangeObj.setEnd(textNode, charIndex);
88255
+ const rangeRect = rangeObj.getBoundingClientRect();
88256
+ if (pageRect) {
88257
+ domCaretX = (rangeRect.left - pageRect.left) / zoom;
88258
+ domCaretY = (rangeRect.top - pageRect.top) / zoom;
88128
88259
  }
88129
- const spanRect2 = spanEl.getBoundingClientRect();
88130
- return {
88131
- pageIndex,
88132
- x: (spanRect2.left - pageRect.left) / zoom,
88133
- y: (spanRect2.top - pageRect.top) / zoom,
88134
- height: spanRect2.height / zoom
88135
- };
88260
+ break;
88136
88261
  }
88137
- const rangeRect = range2.getBoundingClientRect();
88138
- const spanRect = spanEl.getBoundingClientRect();
88139
- const lineEl = spanEl.closest(".superdoc-line");
88140
- const lineRect = lineEl ? lineEl.getBoundingClientRect() : spanRect;
88141
- const caretHeight = spanRect.height;
88142
- const verticalOffset = (lineRect.height - caretHeight) / 2;
88143
- const caretY = lineRect.top + verticalOffset;
88262
+ }
88263
+ if (includeDomFallback && domCaretX != null && domCaretY != null) {
88144
88264
  return {
88145
- pageIndex,
88146
- x: (rangeRect.left - pageRect.left) / zoom,
88147
- y: (caretY - pageRect.top) / zoom,
88148
- height: caretHeight / zoom
88265
+ pageIndex: hit.pageIndex,
88266
+ x: domCaretX,
88267
+ y: domCaretY,
88268
+ height: line.lineHeight
88149
88269
  };
88150
88270
  }
88151
- return null;
88271
+ return result;
88272
+ };
88273
+ computeCaretLayoutRect_fn = function(pos) {
88274
+ const geometry = __privateMethod$1(this, _PresentationEditor_instances, computeCaretLayoutRectGeometry_fn).call(this, pos, true);
88275
+ const dom = __privateMethod$1(this, _PresentationEditor_instances, computeDomCaretPageLocal_fn).call(this, pos);
88276
+ if (dom && geometry) {
88277
+ return {
88278
+ pageIndex: dom.pageIndex,
88279
+ x: dom.x,
88280
+ y: dom.y,
88281
+ height: geometry.height
88282
+ };
88283
+ }
88284
+ return geometry;
88152
88285
  };
88153
88286
  computeTableCaretLayoutRect_fn = function(pos, _fragment, _tableBlock, _tableMeasure, pageIndex) {
88154
88287
  const lineEls = Array.from(__privateGet$1(this, _viewportHost).querySelectorAll(".superdoc-line"));