superdoc 1.0.0-beta.2 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/chunks/{PdfViewer-saAhozRR.es.js → PdfViewer-CKzs9Ct5.es.js} +2 -2
  2. package/dist/chunks/{PdfViewer-CeuX3gOe.cjs → PdfViewer-CxHbcDGx.cjs} +1 -1
  3. package/dist/chunks/{eventemitter3-BZXKb7j7.es.js → eventemitter3-ByBH0NYV.es.js} +1 -1
  4. package/dist/chunks/{index-Sn-JVHIg-BxOp3gSx.cjs → index-CJUy3fVi-BGLfCP5B.cjs} +1 -1
  5. package/dist/chunks/{index-Sn-JVHIg-BCItIT88.es.js → index-CJUy3fVi-D8zt9F3Z.es.js} +1 -1
  6. package/dist/chunks/{index-Dh5oVJua.cjs → index-Dp3rVMnX.cjs} +3 -3
  7. package/dist/chunks/{index-C0OeGje6.es.js → index-DukSDI8_.es.js} +6 -6
  8. package/dist/chunks/{jszip-Duxs2YMV.es.js → jszip-BwsONqK5.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-Dcz39nKY.es.js → super-editor.es-BRKZG90h.es.js} +593 -200
  10. package/dist/chunks/{super-editor.es-BKljkYUU.cjs → super-editor.es-CDiTp9Fe.cjs} +592 -199
  11. package/dist/chunks/{vue-B5QAf5pA.es.js → vue-CztqUvm1.es.js} +17 -17
  12. package/dist/chunks/xml-js-BZPSMmVo.es.js +2 -0
  13. package/dist/packages/superdoc/src/core/SuperDoc.d.ts +35 -2
  14. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  15. package/dist/super-editor/ai-writer.es.js +2 -2
  16. package/dist/super-editor/chunks/{converter-BFGB7hqj.js → converter-B9YfBdcc.js} +1 -1
  17. package/dist/super-editor/chunks/{docx-zipper-OPbzIk16.js → docx-zipper-V16OzZ7a.js} +1 -1
  18. package/dist/super-editor/chunks/{editor-CtI4XnMw.js → editor-DlvlVSbc.js} +409 -165
  19. package/dist/super-editor/chunks/{index-Sn-JVHIg.js → index-CJUy3fVi.js} +1 -1
  20. package/dist/super-editor/chunks/{toolbar-BydALv4o.js → toolbar-cNDvtryE.js} +2 -2
  21. package/dist/super-editor/converter.es.js +1 -1
  22. package/dist/super-editor/docx-zipper.es.js +2 -2
  23. package/dist/super-editor/editor.es.js +3 -3
  24. package/dist/super-editor/file-zipper.es.js +1 -1
  25. package/dist/super-editor/super-editor.es.js +217 -41
  26. package/dist/super-editor/toolbar.es.js +2 -2
  27. package/dist/super-editor.cjs +1 -1
  28. package/dist/super-editor.es.js +2 -2
  29. package/dist/superdoc.cjs +2 -2
  30. package/dist/superdoc.es.js +2 -2
  31. package/dist/superdoc.umd.js +594 -201
  32. package/dist/superdoc.umd.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunks/xml-js-CVyfrKaV.es.js +0 -2
@@ -35581,7 +35581,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35581
35581
  static getStoredSuperdocVersion(docx) {
35582
35582
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
35583
35583
  }
35584
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.2") {
35584
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.3") {
35585
35585
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
35586
35586
  }
35587
35587
  /**
@@ -46562,7 +46562,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
46562
46562
  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);
46563
46563
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
46564
46564
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
46565
- 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, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _headerLayoutResults, _footerLayoutResults, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _remoteCursorState, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _remoteCursorRafHandle, _scrollTimeout, _PresentationEditor_instances, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_fn, setupPointerHandlers_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, selectWordAt_fn, selectParagraphAt_fn, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, updateDecorationProviders_fn, createDecorationProvider_fn, computeDecorationBox_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, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, computeHeaderFooterCaretRect_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, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _visibleHost2, _getTargetDom, _onTargetChanged, _listeners, _currentTarget, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, updateHTMLAttributes_fn, updateDOMStyles_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;
46565
+ 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, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _headerLayoutResults, _footerLayoutResults, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _remoteCursorState, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _remoteCursorRafHandle, _scrollTimeout, _PresentationEditor_instances, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_fn, setupPointerHandlers_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, selectWordAt_fn, selectParagraphAt_fn, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, updateDecorationProviders_fn, createDecorationProvider_fn, computeDecorationBox_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, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, computeHeaderFooterCaretRect_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, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _visibleHost2, _getTargetDom, _onTargetChanged, _listeners, _currentTarget, _destroyed, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, updateHTMLAttributes_fn, updateDOMStyles_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;
46566
46566
  var GOOD_LEAF_SIZE = 200;
46567
46567
  var RopeSequence = function RopeSequence2() {
46568
46568
  };
@@ -60069,7 +60069,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60069
60069
  const shouldSkipNodeView = (editor) => {
60070
60070
  return isHeadless(editor);
60071
60071
  };
60072
- const summaryVersion = "1.0.0-beta.2";
60072
+ const summaryVersion = "1.0.0-beta.3";
60073
60073
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
60074
60074
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
60075
60075
  function mapAttributes(attrs) {
@@ -60848,7 +60848,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60848
60848
  { default: remarkStringify2 },
60849
60849
  { default: remarkGfm2 }
60850
60850
  ] = await Promise.all([
60851
- Promise.resolve().then(() => indexSnJVHIg),
60851
+ Promise.resolve().then(() => indexCJUy3fVi),
60852
60852
  Promise.resolve().then(() => indexDRCvimau),
60853
60853
  Promise.resolve().then(() => indexC_x_N6Uh),
60854
60854
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -61053,7 +61053,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61053
61053
  * Process collaboration migrations
61054
61054
  */
61055
61055
  processCollaborationMigrations() {
61056
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.2");
61056
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.3");
61057
61057
  if (!this.options.ydoc) return;
61058
61058
  const metaMap = this.options.ydoc.getMap("meta");
61059
61059
  let docVersion = metaMap.get("version");
@@ -62672,6 +62672,50 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62672
62672
  }
62673
62673
  return void 0;
62674
62674
  };
62675
+ const MAX_DATA_ATTR_COUNT = 50;
62676
+ const MAX_DATA_ATTR_VALUE_LENGTH = 1e3;
62677
+ const MAX_DATA_ATTR_NAME_LENGTH = 100;
62678
+ const extractDataAttributes = (attrs) => {
62679
+ if (!attrs) return void 0;
62680
+ const result = {};
62681
+ let attrCount = 0;
62682
+ for (const [key2, value] of Object.entries(attrs)) {
62683
+ if (typeof key2 !== "string" || !key2.toLowerCase().startsWith("data-")) {
62684
+ continue;
62685
+ }
62686
+ if (attrCount >= MAX_DATA_ATTR_COUNT) {
62687
+ if (process$1$1.env.NODE_ENV === "development") {
62688
+ console.warn(`[PM-Adapter] Rejecting data attributes exceeding ${MAX_DATA_ATTR_COUNT} limit`);
62689
+ }
62690
+ break;
62691
+ }
62692
+ if (key2.length > MAX_DATA_ATTR_NAME_LENGTH) {
62693
+ if (process$1$1.env.NODE_ENV === "development") {
62694
+ console.warn(
62695
+ `[PM-Adapter] Rejecting data attribute name exceeding ${MAX_DATA_ATTR_NAME_LENGTH} chars: ${key2.substring(0, 50)}...`
62696
+ );
62697
+ }
62698
+ continue;
62699
+ }
62700
+ if (value == null) {
62701
+ continue;
62702
+ }
62703
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
62704
+ const stringValue = String(value);
62705
+ if (stringValue.length > MAX_DATA_ATTR_VALUE_LENGTH) {
62706
+ if (process$1$1.env.NODE_ENV === "development") {
62707
+ console.warn(
62708
+ `[PM-Adapter] Rejecting data attribute value exceeding ${MAX_DATA_ATTR_VALUE_LENGTH} chars for key: ${key2}`
62709
+ );
62710
+ }
62711
+ continue;
62712
+ }
62713
+ result[key2] = stringValue;
62714
+ attrCount++;
62715
+ }
62716
+ }
62717
+ return Object.keys(result).length > 0 ? result : void 0;
62718
+ };
62675
62719
  const normalizeRunMarkList = (value) => {
62676
62720
  if (!value) return void 0;
62677
62721
  let entries = value;
@@ -62851,11 +62895,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62851
62895
  run2.fontFamily = sanitized;
62852
62896
  }
62853
62897
  }
62854
- if (isFiniteNumber(attrs.fontSize)) {
62855
- const size2 = Number(attrs.fontSize);
62856
- if (size2 >= 1 && size2 <= 1e3) {
62857
- run2.fontSize = size2;
62858
- }
62898
+ const fontSizeValue = pickNumber(attrs.fontSize);
62899
+ if (fontSizeValue !== void 0 && fontSizeValue >= 1 && fontSizeValue <= 1e3) {
62900
+ run2.fontSize = fontSizeValue;
62859
62901
  }
62860
62902
  if (isFiniteNumber(attrs.letterSpacing)) {
62861
62903
  const spacing = Number(attrs.letterSpacing);
@@ -62869,6 +62911,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62869
62911
  };
62870
62912
  const applyMarksToRun = (run2, marks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG, themeColors) => {
62871
62913
  marks.forEach((mark2) => {
62914
+ const forwardedDataAttrs = extractDataAttributes(mark2.attrs);
62872
62915
  try {
62873
62916
  switch (mark2.type) {
62874
62917
  case TRACK_INSERT_MARK:
@@ -62963,6 +63006,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62963
63006
  console.warn(`[PM-Adapter] Failed to apply mark ${mark2.type}:`, error);
62964
63007
  }
62965
63008
  }
63009
+ if (forwardedDataAttrs) {
63010
+ run2.dataAttrs = { ...run2.dataAttrs ?? {}, ...forwardedDataAttrs };
63011
+ }
62966
63012
  });
62967
63013
  };
62968
63014
  function textNodeToRun(textNode, positions, defaultFont, defaultSize, inheritedMarks = [], sdtMetadata, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG$1, themeColors) {
@@ -62986,8 +63032,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62986
63032
  const pos = positions.get(node2);
62987
63033
  if (!pos) return null;
62988
63034
  const paragraphAttrs = paragraph2.attrs ?? {};
62989
- const tabStops = Array.isArray(paragraphAttrs.tabStops) ? paragraphAttrs.tabStops : void 0;
62990
- const indent2 = paragraphAttrs.indent;
63035
+ const paragraphProps = typeof paragraphAttrs.paragraphProperties === "object" && paragraphAttrs.paragraphProperties !== null ? paragraphAttrs.paragraphProperties : {};
63036
+ const tabStops = Array.isArray(paragraphAttrs.tabStops) && paragraphAttrs.tabStops.length ? paragraphAttrs.tabStops : Array.isArray(paragraphProps.tabStops) ? paragraphProps.tabStops : void 0;
63037
+ const indent2 = paragraphAttrs.indent ?? paragraphProps.indent ?? void 0;
62991
63038
  return {
62992
63039
  kind: "tab",
62993
63040
  text: " ",
@@ -63301,6 +63348,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63301
63348
  const afterRaw = pickNumber(source.after);
63302
63349
  const lineRaw = pickNumber(source.line);
63303
63350
  const lineRule = normalizeLineRule(source.lineRule);
63351
+ const beforeAutospacing = toBooleanFlag(source.beforeAutospacing ?? source.beforeAutoSpacing);
63352
+ const afterAutospacing = toBooleanFlag(source.afterAutospacing ?? source.afterAutoSpacing);
63353
+ const contextualSpacing = toBooleanFlag(source.contextualSpacing);
63304
63354
  const before = beforeRaw != null ? twipsToPx$1(beforeRaw) : pickNumber(source.lineSpaceBefore);
63305
63355
  const after = afterRaw != null ? twipsToPx$1(afterRaw) : pickNumber(source.lineSpaceAfter);
63306
63356
  const line = normalizeLineValue(lineRaw, lineRule);
@@ -63308,8 +63358,24 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63308
63358
  if (after != null) spacing.after = after;
63309
63359
  if (line != null) spacing.line = line;
63310
63360
  if (lineRule) spacing.lineRule = lineRule;
63361
+ if (beforeAutospacing != null) spacing.beforeAutospacing = beforeAutospacing;
63362
+ if (afterAutospacing != null) spacing.afterAutospacing = afterAutospacing;
63363
+ if (contextualSpacing != null) spacing.contextualSpacing = contextualSpacing;
63311
63364
  return Object.keys(spacing).length > 0 ? spacing : void 0;
63312
63365
  };
63366
+ const toBooleanFlag = (value) => {
63367
+ if (value === true || value === false) return value;
63368
+ if (typeof value === "string") {
63369
+ const normalized = value.trim().toLowerCase();
63370
+ if (["true", "1", "on", "yes"].includes(normalized)) return true;
63371
+ if (["false", "0", "off", "no"].includes(normalized)) return false;
63372
+ }
63373
+ if (typeof value === "number") {
63374
+ if (value === 1) return true;
63375
+ if (value === 0) return false;
63376
+ }
63377
+ return void 0;
63378
+ };
63313
63379
  const normalizeLineValue = (value, lineRule) => {
63314
63380
  if (value == null) return void 0;
63315
63381
  if (lineRule === "auto") {
@@ -64682,15 +64748,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64682
64748
  return null;
64683
64749
  }
64684
64750
  const attrs = para.attrs ?? {};
64685
- const styleId = typeof attrs.styleId === "string" && attrs.styleId.trim() ? attrs.styleId : null;
64751
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
64752
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
64753
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
64686
64754
  if (!styleId) {
64687
64755
  return null;
64688
64756
  }
64689
64757
  const inlineProps = {
64690
64758
  styleId,
64691
- numberingProperties: cloneIfObject(attrs.numberingProperties),
64692
- indent: cloneIfObject(attrs.indent),
64693
- spacing: cloneIfObject(attrs.spacing)
64759
+ numberingProperties: cloneIfObject(attrs.numberingProperties ?? paragraphProps.numberingProperties),
64760
+ indent: cloneIfObject(attrs.indent ?? paragraphProps.indent),
64761
+ spacing: cloneIfObject(attrs.spacing ?? paragraphProps.spacing)
64694
64762
  };
64695
64763
  const resolverParams = {
64696
64764
  docx: context.docx,
@@ -64968,13 +65036,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64968
65036
  };
64969
65037
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
64970
65038
  const attrs = para.attrs ?? {};
65039
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
64971
65040
  const hydrated = hydrationOverride ?? hydrateParagraphStyleAttrs(para, converterContext);
64972
- const spacingSource = attrs.spacing !== void 0 ? attrs.spacing : hydrated?.spacing;
65041
+ const spacingSource = attrs.spacing !== void 0 ? attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : hydrated?.spacing;
64973
65042
  const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
64974
- const indentSource = attrs.indent ?? hydrated?.indent;
65043
+ const indentSource = attrs.indent ?? paragraphProps.indent ?? hydrated?.indent;
64975
65044
  const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? attrs.textIndent);
64976
- const styleNodeAttrs = hydrated?.tabStops && !attrs.tabStops && !attrs.tabs ? { ...attrs, tabStops: hydrated.tabStops } : attrs;
65045
+ const styleNodeAttrs = hydrated?.tabStops && !attrs.tabStops && !attrs.tabs ? { ...attrs, tabStops: hydrated.tabStops } : !attrs.tabStops && paragraphProps.tabStops ? { ...attrs, tabStops: paragraphProps.tabStops } : attrs;
64977
65046
  const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
65047
+ if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
65048
+ styleNode.styleId = paragraphProps.styleId;
65049
+ }
64978
65050
  const computed2 = resolveStyle(styleNode, styleContext);
64979
65051
  const { spacing, indent: indent2 } = resolveSpacingIndent(computed2.paragraph, computed2.numbering);
64980
65052
  const paragraphAttrs = {};
@@ -64999,6 +65071,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64999
65071
  }
65000
65072
  const spacingPx = spacingPtToPx(spacing, normalizedSpacing);
65001
65073
  if (spacingPx) paragraphAttrs.spacing = spacingPx;
65074
+ if (normalizedSpacing?.beforeAutospacing != null || normalizedSpacing?.afterAutospacing != null) {
65075
+ paragraphAttrs.spacing = paragraphAttrs.spacing ?? {};
65076
+ if (normalizedSpacing?.beforeAutospacing != null) {
65077
+ paragraphAttrs.spacing.beforeAutospacing = normalizedSpacing.beforeAutospacing;
65078
+ }
65079
+ if (normalizedSpacing?.afterAutospacing != null) {
65080
+ paragraphAttrs.spacing.afterAutospacing = normalizedSpacing.afterAutospacing;
65081
+ }
65082
+ }
65083
+ if (normalizedSpacing?.contextualSpacing != null) {
65084
+ paragraphAttrs.contextualSpacing = normalizedSpacing.contextualSpacing;
65085
+ }
65002
65086
  const hasExplicitIndent = Boolean(normalizedIndent);
65003
65087
  const hasNumberingIndent = Boolean(computed2.numbering?.indent?.left || computed2.numbering?.indent?.hanging);
65004
65088
  if (hasExplicitIndent || hasNumberingIndent || bidi && adjustRightInd) {
@@ -65017,10 +65101,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65017
65101
  if (borders) paragraphAttrs.borders = borders;
65018
65102
  const shading = normalizeParagraphShading(attrs.shading ?? hydrated?.shading);
65019
65103
  if (shading) paragraphAttrs.shading = shading;
65104
+ const keepNext = paragraphProps.keepNext ?? hydrated?.keepNext ?? attrs.keepNext;
65105
+ if (keepNext === true) paragraphAttrs.keepNext = true;
65106
+ const keepLines = paragraphProps.keepLines ?? hydrated?.keepLines ?? attrs.keepLines;
65107
+ if (keepLines === true) paragraphAttrs.keepLines = true;
65020
65108
  const paragraphDecimalSeparator = styleContext.defaults?.decimalSeparator ?? DEFAULT_DECIMAL_SEPARATOR$2;
65021
65109
  if (paragraphDecimalSeparator !== DEFAULT_DECIMAL_SEPARATOR$2) {
65022
65110
  paragraphAttrs.decimalSeparator = paragraphDecimalSeparator;
65023
65111
  }
65112
+ const styleIdAttr = typeof attrs.styleId === "string" ? attrs.styleId : void 0;
65113
+ if (styleIdAttr) {
65114
+ paragraphAttrs.styleId = styleIdAttr;
65115
+ } else if (paragraphProps.styleId) {
65116
+ paragraphAttrs.styleId = paragraphProps.styleId;
65117
+ }
65024
65118
  const paraIntervalTwips = pickNumber(attrs.tabIntervalTwips) ?? (() => {
65025
65119
  const px = pickNumber(attrs.tabIntervalPx);
65026
65120
  return px != null ? Math.round(px * 15) : void 0;
@@ -65057,7 +65151,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65057
65151
  paragraphAttrs.floatAlignment = xAlign;
65058
65152
  }
65059
65153
  }
65060
- const numberingSource = attrs.numberingProperties ?? hydrated?.numberingProperties;
65154
+ const numberingSource = attrs.numberingProperties ?? paragraphProps.numberingProperties ?? hydrated?.numberingProperties;
65061
65155
  const rawNumberingProps = toAdapterNumberingProps(numberingSource);
65062
65156
  if (rawNumberingProps) {
65063
65157
  const numberingProps = rawNumberingProps;
@@ -65710,13 +65804,29 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65710
65804
  return null;
65711
65805
  };
65712
65806
  const isTextRun$1 = (run2) => run2.kind !== "tab";
65807
+ const dataAttrsCompatible = (a2, b2) => {
65808
+ const aAttrs = a2.dataAttrs;
65809
+ const bAttrs = b2.dataAttrs;
65810
+ if (!aAttrs && !bAttrs) return true;
65811
+ if (!aAttrs || !bAttrs) return false;
65812
+ const aKeys = Object.keys(aAttrs).sort();
65813
+ const bKeys = Object.keys(bAttrs).sort();
65814
+ if (aKeys.length !== bKeys.length) return false;
65815
+ for (let i2 = 0; i2 < aKeys.length; i2++) {
65816
+ const key2 = aKeys[i2];
65817
+ if (key2 !== bKeys[i2] || aAttrs[key2] !== bAttrs[key2]) {
65818
+ return false;
65819
+ }
65820
+ }
65821
+ return true;
65822
+ };
65713
65823
  function mergeAdjacentRuns(runs2) {
65714
65824
  if (runs2.length <= 1) return runs2;
65715
65825
  const merged = [];
65716
65826
  let current = runs2[0];
65717
65827
  for (let i2 = 1; i2 < runs2.length; i2++) {
65718
65828
  const next2 = runs2[i2];
65719
- const canMerge = isTextRun$1(current) && isTextRun$1(next2) && !current.token && !next2.token && current.pmStart != null && current.pmEnd != null && next2.pmStart != null && next2.pmEnd != null && current.pmEnd === next2.pmStart && current.fontFamily === next2.fontFamily && current.fontSize === next2.fontSize && current.bold === next2.bold && current.italic === next2.italic && current.underline === next2.underline && current.strike === next2.strike && current.color === next2.color && current.highlight === next2.highlight && (current.letterSpacing ?? 0) === (next2.letterSpacing ?? 0) && trackedChangesCompatible(current, next2);
65829
+ const canMerge = isTextRun$1(current) && isTextRun$1(next2) && !current.token && !next2.token && current.pmStart != null && current.pmEnd != null && next2.pmStart != null && next2.pmEnd != null && current.pmEnd === next2.pmStart && current.fontFamily === next2.fontFamily && current.fontSize === next2.fontSize && current.bold === next2.bold && current.italic === next2.italic && current.underline === next2.underline && current.strike === next2.strike && current.color === next2.color && current.highlight === next2.highlight && (current.letterSpacing ?? 0) === (next2.letterSpacing ?? 0) && trackedChangesCompatible(current, next2) && dataAttrsCompatible(current, next2);
65720
65830
  if (canMerge) {
65721
65831
  const currText = current.text ?? "";
65722
65832
  const nextText = next2.text ?? "";
@@ -65733,10 +65843,62 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65733
65843
  merged.push(current);
65734
65844
  return merged;
65735
65845
  }
65846
+ const applyBaseRunDefaults = (run2, defaults2, fallbackFont, fallbackSize) => {
65847
+ if (!run2) return;
65848
+ if (defaults2.fontFamily && run2.fontFamily === fallbackFont) {
65849
+ run2.fontFamily = defaults2.fontFamily;
65850
+ }
65851
+ if (defaults2.fontSizePx != null && run2.fontSize === fallbackSize) {
65852
+ run2.fontSize = defaults2.fontSizePx;
65853
+ }
65854
+ if (defaults2.color && !run2.color) {
65855
+ run2.color = defaults2.color;
65856
+ }
65857
+ if (defaults2.letterSpacing != null && run2.letterSpacing == null) {
65858
+ run2.letterSpacing = defaults2.letterSpacing;
65859
+ }
65860
+ if (defaults2.bold && run2.bold === void 0) {
65861
+ run2.bold = true;
65862
+ }
65863
+ if (defaults2.italic && run2.italic === void 0) {
65864
+ run2.italic = true;
65865
+ }
65866
+ if (defaults2.underline && !run2.underline) {
65867
+ run2.underline = defaults2.underline;
65868
+ }
65869
+ };
65736
65870
  function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defaultSize, styleContext, listCounterContext, trackedChanges, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG$1, themeColors, converters, converterContext) {
65737
65871
  const baseBlockId = nextBlockId("paragraph");
65738
- const paragraphStyleId = typeof para.attrs?.styleId === "string" ? para.attrs.styleId : null;
65872
+ const paragraphProps = typeof para.attrs?.paragraphProperties === "object" && para.attrs.paragraphProperties !== null ? para.attrs.paragraphProperties : {};
65873
+ const paragraphStyleId = typeof para.attrs?.styleId === "string" && para.attrs.styleId.trim() ? para.attrs.styleId : typeof paragraphProps.styleId === "string" && paragraphProps.styleId.trim() ? paragraphProps.styleId : null;
65739
65874
  const paragraphHydration = converterContext ? hydrateParagraphStyleAttrs(para, converterContext) : null;
65875
+ let baseRunDefaults = {};
65876
+ try {
65877
+ const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
65878
+ const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
65879
+ const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
65880
+ const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
65881
+ const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
65882
+ const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
65883
+ if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
65884
+ styleNode.styleId = paragraphProps.styleId;
65885
+ }
65886
+ const resolved = resolveStyle(styleNode, styleContext);
65887
+ baseRunDefaults = {
65888
+ fontFamily: resolved.character.font?.family,
65889
+ fontSizePx: ptToPx(resolved.character.font?.size),
65890
+ color: resolved.character.color,
65891
+ bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
65892
+ italic: resolved.character.font?.italic,
65893
+ underline: resolved.character.underline ? {
65894
+ style: resolved.character.underline.style,
65895
+ color: resolved.character.underline.color
65896
+ } : void 0,
65897
+ letterSpacing: ptToPx(resolved.character.letterSpacing)
65898
+ };
65899
+ } catch {
65900
+ baseRunDefaults = {};
65901
+ }
65740
65902
  const paragraphAttrs = computeParagraphAttrs(
65741
65903
  para,
65742
65904
  styleContext,
@@ -65744,6 +65906,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65744
65906
  converterContext,
65745
65907
  paragraphHydration
65746
65908
  );
65909
+ if (paragraphAttrs?.spacing) {
65910
+ const spacing = { ...paragraphAttrs.spacing };
65911
+ const effectiveFontSize = baseRunDefaults.fontSizePx ?? defaultSize;
65912
+ const isList2 = Boolean(paragraphAttrs.numberingProperties);
65913
+ if (spacing.beforeAutospacing) {
65914
+ spacing.before = isList2 ? 0 : Math.max(0, Number(spacing.before ?? 0) + effectiveFontSize * 0.5);
65915
+ }
65916
+ if (spacing.afterAutospacing) {
65917
+ spacing.after = isList2 ? 0 : Math.max(0, Number(spacing.after ?? 0) + effectiveFontSize * 0.5);
65918
+ }
65919
+ paragraphAttrs.spacing = spacing;
65920
+ }
65747
65921
  const linkedStyleResolver = createLinkedStyleResolver(converterContext?.linkedStyles);
65748
65922
  const blocks2 = [];
65749
65923
  if (hasPageBreakBefore(para)) {
@@ -65821,6 +65995,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65821
65995
  );
65822
65996
  const inlineStyleId = getInlineStyleId(inheritedMarks);
65823
65997
  applyRunStyles2(run2, inlineStyleId, activeRunStyleId);
65998
+ applyBaseRunDefaults(run2, baseRunDefaults, defaultFont, defaultSize);
65824
65999
  currentRuns.push(run2);
65825
66000
  return;
65826
66001
  }
@@ -65856,6 +66031,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65856
66031
  );
65857
66032
  const inlineStyleId = getInlineStyleId(inheritedMarks);
65858
66033
  applyRunStyles2(run2, inlineStyleId, activeRunStyleId);
66034
+ applyBaseRunDefaults(run2, baseRunDefaults, defaultFont, defaultSize);
65859
66035
  currentRuns.push(run2);
65860
66036
  }
65861
66037
  }
@@ -65893,6 +66069,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65893
66069
  );
65894
66070
  const inlineStyleId = getInlineStyleId(mergedMarks);
65895
66071
  applyRunStyles2(tokenRun, inlineStyleId, activeRunStyleId);
66072
+ applyBaseRunDefaults(tokenRun, baseRunDefaults, defaultFont, defaultSize);
65896
66073
  if (pageRefPos) {
65897
66074
  tokenRun.pmStart = pageRefPos.start;
65898
66075
  tokenRun.pmEnd = pageRefPos.end;
@@ -65951,6 +66128,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
65951
66128
  }
65952
66129
  const inlineStyleId = getInlineStyleId(inheritedMarks);
65953
66130
  applyRunStyles2(tokenRun, inlineStyleId, activeRunStyleId);
66131
+ applyBaseRunDefaults(tokenRun, baseRunDefaults, defaultFont, defaultSize);
65954
66132
  currentRuns.push(tokenRun);
65955
66133
  }
65956
66134
  return;
@@ -67979,7 +68157,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67979
68157
  let lines = normalizeLines(measure);
67980
68158
  let fromLine = 0;
67981
68159
  const spacing = block.attrs?.spacing ?? {};
67982
- const spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
68160
+ const styleId = block.attrs?.styleId;
68161
+ const contextualSpacing = Boolean(block.attrs?.contextualSpacing);
68162
+ let spacingBefore = Math.max(0, Number(spacing.before ?? spacing.lineSpaceBefore ?? 0));
67983
68163
  const spacingAfter = Math.max(0, Number(spacing.after ?? spacing.lineSpaceAfter ?? 0));
67984
68164
  let appliedSpacingBefore = spacingBefore === 0;
67985
68165
  let lastState = null;
@@ -67995,6 +68175,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67995
68175
  while (fromLine < lines.length) {
67996
68176
  let state2 = ensurePage();
67997
68177
  if (state2.trailingSpacing == null) state2.trailingSpacing = 0;
68178
+ if (contextualSpacing) {
68179
+ const prevStyle = state2.lastParagraphStyleId;
68180
+ if (styleId && prevStyle && prevStyle === styleId) {
68181
+ spacingBefore = 0;
68182
+ }
68183
+ }
68184
+ if (contextualSpacing && state2.lastParagraphStyleId && styleId && state2.lastParagraphStyleId === styleId) {
68185
+ spacingBefore = 0;
68186
+ }
67998
68187
  if (!appliedSpacingBefore && spacingBefore > 0) {
67999
68188
  while (!appliedSpacingBefore) {
68000
68189
  const prevTrailing = state2.trailingSpacing ?? 0;
@@ -68163,6 +68352,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68163
68352
  } else {
68164
68353
  lastState.trailingSpacing = 0;
68165
68354
  }
68355
+ lastState.lastParagraphStyleId = styleId;
68166
68356
  }
68167
68357
  }
68168
68358
  function layoutImageBlock({
@@ -68401,7 +68591,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68401
68591
  contentBottom,
68402
68592
  constraintBoundaries: [],
68403
68593
  activeConstraintIndex: -1,
68404
- trailingSpacing: 0
68594
+ trailingSpacing: 0,
68595
+ lastParagraphStyleId: void 0
68405
68596
  };
68406
68597
  states.push(state2);
68407
68598
  pages.push(state2.page);
@@ -68423,6 +68614,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
68423
68614
  state2.cursorY = state2.topMargin;
68424
68615
  }
68425
68616
  state2.trailingSpacing = 0;
68617
+ state2.lastParagraphStyleId = void 0;
68426
68618
  return state2;
68427
68619
  }
68428
68620
  return startNewPage();
@@ -73574,147 +73766,162 @@ ${l}
73574
73766
  return el;
73575
73767
  }
73576
73768
  renderListItemFragment(fragment, context) {
73577
- const lookup2 = this.blockLookup.get(fragment.blockId);
73578
- if (!lookup2 || lookup2.block.kind !== "list" || lookup2.measure.kind !== "list") {
73579
- throw new Error(`DomPainter: missing list data for fragment ${fragment.blockId}`);
73580
- }
73581
- if (!this.doc) {
73582
- throw new Error("DomPainter: document is not available");
73769
+ try {
73770
+ const lookup2 = this.blockLookup.get(fragment.blockId);
73771
+ if (!lookup2 || lookup2.block.kind !== "list" || lookup2.measure.kind !== "list") {
73772
+ throw new Error(`DomPainter: missing list data for fragment ${fragment.blockId}`);
73773
+ }
73774
+ if (!this.doc) {
73775
+ throw new Error("DomPainter: document is not available");
73776
+ }
73777
+ const block = lookup2.block;
73778
+ const measure = lookup2.measure;
73779
+ const item = block.items.find((entry) => entry.id === fragment.itemId);
73780
+ const itemMeasure = measure.items.find((entry) => entry.itemId === fragment.itemId);
73781
+ if (!item || !itemMeasure) {
73782
+ throw new Error(`DomPainter: missing list item ${fragment.itemId}`);
73783
+ }
73784
+ const fragmentEl = this.doc.createElement("div");
73785
+ fragmentEl.classList.add(CLASS_NAMES.fragment, `${CLASS_NAMES.fragment}-list-item`);
73786
+ applyStyles$2(fragmentEl, fragmentStyles);
73787
+ fragmentEl.style.left = `${fragment.x - fragment.markerWidth}px`;
73788
+ fragmentEl.style.top = `${fragment.y}px`;
73789
+ fragmentEl.style.width = `${fragment.markerWidth + fragment.width}px`;
73790
+ fragmentEl.dataset.blockId = fragment.blockId;
73791
+ fragmentEl.dataset.itemId = fragment.itemId;
73792
+ const paragraphMetadata = item.paragraph.attrs?.sdt;
73793
+ this.applySdtDataset(fragmentEl, paragraphMetadata);
73794
+ if (fragment.continuesFromPrev) {
73795
+ fragmentEl.dataset.continuesFromPrev = "true";
73796
+ }
73797
+ if (fragment.continuesOnNext) {
73798
+ fragmentEl.dataset.continuesOnNext = "true";
73799
+ }
73800
+ const markerEl = this.doc.createElement("span");
73801
+ markerEl.classList.add("superdoc-list-marker");
73802
+ const wordLayout = item.paragraph.attrs?.wordLayout;
73803
+ if (wordLayout?.marker) {
73804
+ const marker = wordLayout.marker;
73805
+ markerEl.textContent = marker.markerText;
73806
+ markerEl.style.display = "inline-block";
73807
+ markerEl.style.width = `${Math.max(0, fragment.markerWidth - LIST_MARKER_GAP$1)}px`;
73808
+ markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
73809
+ markerEl.style.textAlign = marker.justification;
73810
+ markerEl.style.fontFamily = marker.run.fontFamily;
73811
+ markerEl.style.fontSize = `${marker.run.fontSize}px`;
73812
+ if (marker.run.bold) markerEl.style.fontWeight = "bold";
73813
+ if (marker.run.italic) markerEl.style.fontStyle = "italic";
73814
+ if (marker.run.color) markerEl.style.color = marker.run.color;
73815
+ if (marker.run.letterSpacing) markerEl.style.letterSpacing = `${marker.run.letterSpacing}px`;
73816
+ } else {
73817
+ markerEl.textContent = item.marker.text;
73818
+ markerEl.style.display = "inline-block";
73819
+ markerEl.style.width = `${Math.max(0, fragment.markerWidth - LIST_MARKER_GAP$1)}px`;
73820
+ markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
73821
+ if (item.marker.align) {
73822
+ markerEl.style.textAlign = item.marker.align;
73823
+ }
73824
+ }
73825
+ fragmentEl.appendChild(markerEl);
73826
+ const contentEl = this.doc.createElement("div");
73827
+ contentEl.classList.add("superdoc-list-content");
73828
+ this.applySdtDataset(contentEl, paragraphMetadata);
73829
+ contentEl.style.display = "inline-block";
73830
+ contentEl.style.width = `${fragment.width}px`;
73831
+ const lines = itemMeasure.paragraph.lines.slice(fragment.fromLine, fragment.toLine);
73832
+ const contentAttrs = wordLayout ? item.paragraph.attrs : stripListIndent(item.paragraph.attrs);
73833
+ applyParagraphBlockStyles(contentEl, contentAttrs);
73834
+ lines.forEach((line) => {
73835
+ const lineEl = this.renderLine(item.paragraph, line, context);
73836
+ contentEl.appendChild(lineEl);
73837
+ });
73838
+ fragmentEl.appendChild(contentEl);
73839
+ return fragmentEl;
73840
+ } catch (error) {
73841
+ console.error("[DomPainter] List item fragment rendering failed:", { fragment, error });
73842
+ return this.createErrorPlaceholder(fragment.blockId, error);
73583
73843
  }
73584
- const block = lookup2.block;
73585
- const measure = lookup2.measure;
73586
- const item = block.items.find((entry) => entry.id === fragment.itemId);
73587
- const itemMeasure = measure.items.find((entry) => entry.itemId === fragment.itemId);
73588
- if (!item || !itemMeasure) {
73589
- throw new Error(`DomPainter: missing list item ${fragment.itemId}`);
73590
- }
73591
- const fragmentEl = this.doc.createElement("div");
73592
- fragmentEl.classList.add(CLASS_NAMES.fragment, `${CLASS_NAMES.fragment}-list-item`);
73593
- applyStyles$2(fragmentEl, fragmentStyles);
73594
- fragmentEl.style.left = `${fragment.x - fragment.markerWidth}px`;
73595
- fragmentEl.style.top = `${fragment.y}px`;
73596
- fragmentEl.style.width = `${fragment.markerWidth + fragment.width}px`;
73597
- fragmentEl.dataset.blockId = fragment.blockId;
73598
- fragmentEl.dataset.itemId = fragment.itemId;
73599
- const paragraphMetadata = item.paragraph.attrs?.sdt;
73600
- this.applySdtDataset(fragmentEl, paragraphMetadata);
73601
- if (fragment.continuesFromPrev) {
73602
- fragmentEl.dataset.continuesFromPrev = "true";
73603
- }
73604
- if (fragment.continuesOnNext) {
73605
- fragmentEl.dataset.continuesOnNext = "true";
73606
- }
73607
- const markerEl = this.doc.createElement("span");
73608
- markerEl.classList.add("superdoc-list-marker");
73609
- const wordLayout = item.paragraph.attrs?.wordLayout;
73610
- if (wordLayout?.marker) {
73611
- const marker = wordLayout.marker;
73612
- markerEl.textContent = marker.markerText;
73613
- markerEl.style.display = "inline-block";
73614
- markerEl.style.width = `${Math.max(0, fragment.markerWidth - LIST_MARKER_GAP$1)}px`;
73615
- markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
73616
- markerEl.style.textAlign = marker.justification;
73617
- markerEl.style.fontFamily = marker.run.fontFamily;
73618
- markerEl.style.fontSize = `${marker.run.fontSize}px`;
73619
- if (marker.run.bold) markerEl.style.fontWeight = "bold";
73620
- if (marker.run.italic) markerEl.style.fontStyle = "italic";
73621
- if (marker.run.color) markerEl.style.color = marker.run.color;
73622
- if (marker.run.letterSpacing) markerEl.style.letterSpacing = `${marker.run.letterSpacing}px`;
73623
- } else {
73624
- markerEl.textContent = item.marker.text;
73625
- markerEl.style.display = "inline-block";
73626
- markerEl.style.width = `${Math.max(0, fragment.markerWidth - LIST_MARKER_GAP$1)}px`;
73627
- markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
73628
- if (item.marker.align) {
73629
- markerEl.style.textAlign = item.marker.align;
73630
- }
73631
- }
73632
- fragmentEl.appendChild(markerEl);
73633
- const contentEl = this.doc.createElement("div");
73634
- contentEl.classList.add("superdoc-list-content");
73635
- this.applySdtDataset(contentEl, paragraphMetadata);
73636
- contentEl.style.display = "inline-block";
73637
- contentEl.style.width = `${fragment.width}px`;
73638
- const lines = itemMeasure.paragraph.lines.slice(fragment.fromLine, fragment.toLine);
73639
- const contentAttrs = wordLayout ? item.paragraph.attrs : stripListIndent(item.paragraph.attrs);
73640
- applyParagraphBlockStyles(contentEl, contentAttrs);
73641
- lines.forEach((line) => {
73642
- const lineEl = this.renderLine(item.paragraph, line, context);
73643
- contentEl.appendChild(lineEl);
73644
- });
73645
- fragmentEl.appendChild(contentEl);
73646
- return fragmentEl;
73647
73844
  }
73648
73845
  renderImageFragment(fragment) {
73649
- const lookup2 = this.blockLookup.get(fragment.blockId);
73650
- if (!lookup2 || lookup2.block.kind !== "image" || lookup2.measure.kind !== "image") {
73651
- throw new Error(`DomPainter: missing image block for fragment ${fragment.blockId}`);
73652
- }
73653
- if (!this.doc) {
73654
- throw new Error("DomPainter: document is not available");
73655
- }
73656
- const block = lookup2.block;
73657
- const fragmentEl = this.doc.createElement("div");
73658
- fragmentEl.classList.add(CLASS_NAMES.fragment);
73659
- applyStyles$2(fragmentEl, fragmentStyles);
73660
- this.applyFragmentFrame(fragmentEl, fragment);
73661
- fragmentEl.style.height = `${fragment.height}px`;
73662
- this.applySdtDataset(fragmentEl, block.attrs?.sdt);
73663
- this.applyContainerSdtDataset(fragmentEl, block.attrs?.containerSdt);
73664
- if (fragment.isAnchored && fragment.zIndex != null) {
73665
- fragmentEl.style.zIndex = String(fragment.zIndex);
73666
- }
73667
- const img2 = this.doc.createElement("img");
73668
- if (block.src) {
73669
- img2.src = block.src;
73846
+ try {
73847
+ const lookup2 = this.blockLookup.get(fragment.blockId);
73848
+ if (!lookup2 || lookup2.block.kind !== "image" || lookup2.measure.kind !== "image") {
73849
+ throw new Error(`DomPainter: missing image block for fragment ${fragment.blockId}`);
73850
+ }
73851
+ if (!this.doc) {
73852
+ throw new Error("DomPainter: document is not available");
73853
+ }
73854
+ const block = lookup2.block;
73855
+ const fragmentEl = this.doc.createElement("div");
73856
+ fragmentEl.classList.add(CLASS_NAMES.fragment);
73857
+ applyStyles$2(fragmentEl, fragmentStyles);
73858
+ this.applyFragmentFrame(fragmentEl, fragment);
73859
+ fragmentEl.style.height = `${fragment.height}px`;
73860
+ this.applySdtDataset(fragmentEl, block.attrs?.sdt);
73861
+ this.applyContainerSdtDataset(fragmentEl, block.attrs?.containerSdt);
73862
+ if (fragment.isAnchored && fragment.zIndex != null) {
73863
+ fragmentEl.style.zIndex = String(fragment.zIndex);
73864
+ }
73865
+ const img2 = this.doc.createElement("img");
73866
+ if (block.src) {
73867
+ img2.src = block.src;
73868
+ }
73869
+ img2.alt = block.alt ?? "";
73870
+ img2.style.width = "100%";
73871
+ img2.style.height = "100%";
73872
+ img2.style.objectFit = block.objectFit ?? "contain";
73873
+ img2.style.display = block.display === "inline" ? "inline-block" : "block";
73874
+ fragmentEl.appendChild(img2);
73875
+ return fragmentEl;
73876
+ } catch (error) {
73877
+ console.error("[DomPainter] Image fragment rendering failed:", { fragment, error });
73878
+ return this.createErrorPlaceholder(fragment.blockId, error);
73670
73879
  }
73671
- img2.alt = block.alt ?? "";
73672
- img2.style.width = "100%";
73673
- img2.style.height = "100%";
73674
- img2.style.objectFit = block.objectFit ?? "contain";
73675
- img2.style.display = block.display === "inline" ? "inline-block" : "block";
73676
- fragmentEl.appendChild(img2);
73677
- return fragmentEl;
73678
73880
  }
73679
73881
  renderDrawingFragment(fragment) {
73680
- const lookup2 = this.blockLookup.get(fragment.blockId);
73681
- if (!lookup2 || lookup2.block.kind !== "drawing" || lookup2.measure.kind !== "drawing") {
73682
- throw new Error(`DomPainter: missing drawing block for fragment ${fragment.blockId}`);
73683
- }
73684
- if (!this.doc) {
73685
- throw new Error("DomPainter: document is not available");
73882
+ try {
73883
+ const lookup2 = this.blockLookup.get(fragment.blockId);
73884
+ if (!lookup2 || lookup2.block.kind !== "drawing" || lookup2.measure.kind !== "drawing") {
73885
+ throw new Error(`DomPainter: missing drawing block for fragment ${fragment.blockId}`);
73886
+ }
73887
+ if (!this.doc) {
73888
+ throw new Error("DomPainter: document is not available");
73889
+ }
73890
+ const block = lookup2.block;
73891
+ const isVectorShapeBlock = block.kind === "drawing" && block.drawingKind === "vectorShape";
73892
+ const fragmentEl = this.doc.createElement("div");
73893
+ fragmentEl.classList.add(CLASS_NAMES.fragment, "superdoc-drawing-fragment");
73894
+ applyStyles$2(fragmentEl, fragmentStyles);
73895
+ this.applyFragmentFrame(fragmentEl, fragment);
73896
+ fragmentEl.style.height = `${fragment.height}px`;
73897
+ fragmentEl.style.position = "absolute";
73898
+ if (fragment.isAnchored && fragment.zIndex != null) {
73899
+ fragmentEl.style.zIndex = String(fragment.zIndex);
73900
+ }
73901
+ const innerWrapper = this.doc.createElement("div");
73902
+ innerWrapper.classList.add("superdoc-drawing-inner");
73903
+ innerWrapper.style.position = "absolute";
73904
+ innerWrapper.style.left = "50%";
73905
+ innerWrapper.style.top = "50%";
73906
+ innerWrapper.style.width = `${fragment.geometry.width}px`;
73907
+ innerWrapper.style.height = `${fragment.geometry.height}px`;
73908
+ innerWrapper.style.transformOrigin = "center";
73909
+ const scale = fragment.scale ?? 1;
73910
+ const transforms = ["translate(-50%, -50%)"];
73911
+ if (!isVectorShapeBlock) {
73912
+ transforms.push(`rotate(${fragment.geometry.rotation ?? 0}deg)`);
73913
+ transforms.push(`scaleX(${fragment.geometry.flipH ? -1 : 1})`);
73914
+ transforms.push(`scaleY(${fragment.geometry.flipV ? -1 : 1})`);
73915
+ }
73916
+ transforms.push(`scale(${scale})`);
73917
+ innerWrapper.style.transform = transforms.join(" ");
73918
+ innerWrapper.appendChild(this.renderDrawingContent(block, fragment));
73919
+ fragmentEl.appendChild(innerWrapper);
73920
+ return fragmentEl;
73921
+ } catch (error) {
73922
+ console.error("[DomPainter] Drawing fragment rendering failed:", { fragment, error });
73923
+ return this.createErrorPlaceholder(fragment.blockId, error);
73686
73924
  }
73687
- const block = lookup2.block;
73688
- const isVectorShapeBlock = block.kind === "drawing" && block.drawingKind === "vectorShape";
73689
- const fragmentEl = this.doc.createElement("div");
73690
- fragmentEl.classList.add(CLASS_NAMES.fragment, "superdoc-drawing-fragment");
73691
- applyStyles$2(fragmentEl, fragmentStyles);
73692
- this.applyFragmentFrame(fragmentEl, fragment);
73693
- fragmentEl.style.height = `${fragment.height}px`;
73694
- fragmentEl.style.position = "absolute";
73695
- if (fragment.isAnchored && fragment.zIndex != null) {
73696
- fragmentEl.style.zIndex = String(fragment.zIndex);
73697
- }
73698
- const innerWrapper = this.doc.createElement("div");
73699
- innerWrapper.classList.add("superdoc-drawing-inner");
73700
- innerWrapper.style.position = "absolute";
73701
- innerWrapper.style.left = "50%";
73702
- innerWrapper.style.top = "50%";
73703
- innerWrapper.style.width = `${fragment.geometry.width}px`;
73704
- innerWrapper.style.height = `${fragment.geometry.height}px`;
73705
- innerWrapper.style.transformOrigin = "center";
73706
- const scale = fragment.scale ?? 1;
73707
- const transforms = ["translate(-50%, -50%)"];
73708
- if (!isVectorShapeBlock) {
73709
- transforms.push(`rotate(${fragment.geometry.rotation ?? 0}deg)`);
73710
- transforms.push(`scaleX(${fragment.geometry.flipH ? -1 : 1})`);
73711
- transforms.push(`scaleY(${fragment.geometry.flipV ? -1 : 1})`);
73712
- }
73713
- transforms.push(`scale(${scale})`);
73714
- innerWrapper.style.transform = transforms.join(" ");
73715
- innerWrapper.appendChild(this.renderDrawingContent(block, fragment));
73716
- fragmentEl.appendChild(innerWrapper);
73717
- return fragmentEl;
73718
73925
  }
73719
73926
  renderDrawingContent(block, fragment) {
73720
73927
  if (!this.doc) {
@@ -74149,6 +74356,7 @@ ${l}
74149
74356
  }
74150
74357
  applyRunStyles(elem, run2, isActiveLink);
74151
74358
  elem.style.zIndex = "1";
74359
+ applyRunDataAttributes(elem, run2.dataAttrs);
74152
74360
  if (run2.pmStart != null) elem.dataset.pmStart = String(run2.pmStart);
74153
74361
  if (run2.pmEnd != null) elem.dataset.pmEnd = String(run2.pmEnd);
74154
74362
  if (trackedConfig) {
@@ -74529,6 +74737,12 @@ ${l}
74529
74737
  run2.kind !== "tab" && run2.bold ? 1 : 0,
74530
74738
  run2.kind !== "tab" && run2.italic ? 1 : 0,
74531
74739
  run2.kind !== "tab" ? run2.color ?? "" : "",
74740
+ // Text decorations - ensures DOM updates when decoration properties change.
74741
+ run2.kind !== "tab" ? run2.underline?.style ?? "" : "",
74742
+ run2.kind !== "tab" ? run2.underline?.color ?? "" : "",
74743
+ run2.kind !== "tab" && run2.strike ? 1 : 0,
74744
+ run2.kind !== "tab" ? run2.highlight ?? "" : "",
74745
+ run2.kind !== "tab" && run2.letterSpacing != null ? run2.letterSpacing : "",
74532
74746
  run2.pmStart ?? "",
74533
74747
  run2.pmEnd ?? "",
74534
74748
  run2.kind !== "tab" ? run2.token ?? "" : ""
@@ -74623,6 +74837,20 @@ ${l}
74623
74837
  element2.style.textDecorationLine = decorations.join(" ");
74624
74838
  }
74625
74839
  };
74840
+ const applyRunDataAttributes = (element2, dataAttrs) => {
74841
+ if (!dataAttrs) return;
74842
+ Object.entries(dataAttrs).forEach(([key2, value]) => {
74843
+ if (typeof key2 !== "string" || !key2.toLowerCase().startsWith("data-")) return;
74844
+ if (typeof value !== "string") return;
74845
+ try {
74846
+ element2.setAttribute(key2, value);
74847
+ } catch (error) {
74848
+ if (process$1$1.env.NODE_ENV === "development") {
74849
+ console.warn(`[DomPainter] Failed to set data attribute "${key2}":`, error);
74850
+ }
74851
+ }
74852
+ });
74853
+ };
74626
74854
  const applyParagraphBlockStyles = (element2, attrs) => {
74627
74855
  if (!attrs) return;
74628
74856
  if (attrs.alignment) {
@@ -78610,7 +78838,8 @@ ${l}
78610
78838
  return context.layout.pageSize?.h ?? context.region.height ?? 1;
78611
78839
  };
78612
78840
  renderSelectionRects_fn = function(rects) {
78613
- if (!__privateGet$1(this, _selectionOverlay)) {
78841
+ const localSelectionLayer = __privateGet$1(this, _localSelectionLayer);
78842
+ if (!localSelectionLayer) {
78614
78843
  return;
78615
78844
  }
78616
78845
  const pageHeight = __privateMethod$1(this, _PresentationEditor_instances, getBodyPageHeight_fn).call(this);
@@ -78621,7 +78850,7 @@ ${l}
78621
78850
  if (!coords) {
78622
78851
  return;
78623
78852
  }
78624
- const highlight = __privateGet$1(this, _selectionOverlay).ownerDocument?.createElement("div");
78853
+ const highlight = localSelectionLayer.ownerDocument?.createElement("div");
78625
78854
  if (!highlight) {
78626
78855
  return;
78627
78856
  }
@@ -78634,7 +78863,7 @@ ${l}
78634
78863
  highlight.style.backgroundColor = "rgba(51, 132, 255, 0.35)";
78635
78864
  highlight.style.borderRadius = "2px";
78636
78865
  highlight.style.pointerEvents = "none";
78637
- __privateGet$1(this, _selectionOverlay).appendChild(highlight);
78866
+ localSelectionLayer.appendChild(highlight);
78638
78867
  });
78639
78868
  };
78640
78869
  renderHoverRegion_fn = function(region) {
@@ -79084,6 +79313,7 @@ ${l}
79084
79313
  __privateAdd$1(this, _onTargetChanged);
79085
79314
  __privateAdd$1(this, _listeners);
79086
79315
  __privateAdd$1(this, _currentTarget, null);
79316
+ __privateAdd$1(this, _destroyed, false);
79087
79317
  __privateSet(this, _windowRoot, windowRoot);
79088
79318
  __privateSet(this, _visibleHost2, visibleHost);
79089
79319
  __privateSet(this, _getTargetDom, getTargetDom);
@@ -79111,9 +79341,13 @@ ${l}
79111
79341
  });
79112
79342
  __privateSet(this, _listeners, []);
79113
79343
  __privateSet(this, _currentTarget, null);
79344
+ __privateSet(this, _destroyed, true);
79114
79345
  }
79115
79346
  notifyTargetChanged() {
79116
79347
  var _a2;
79348
+ if (__privateGet$1(this, _destroyed)) {
79349
+ return;
79350
+ }
79117
79351
  const nextTarget = __privateGet$1(this, _getTargetDom).call(this);
79118
79352
  if (nextTarget === __privateGet$1(this, _currentTarget)) {
79119
79353
  return;
@@ -79143,6 +79377,7 @@ ${l}
79143
79377
  _onTargetChanged = /* @__PURE__ */ new WeakMap();
79144
79378
  _listeners = /* @__PURE__ */ new WeakMap();
79145
79379
  _currentTarget = /* @__PURE__ */ new WeakMap();
79380
+ _destroyed = /* @__PURE__ */ new WeakMap();
79146
79381
  _PresentationInputBridge_instances = /* @__PURE__ */ new WeakSet();
79147
79382
  addListener_fn = function(type2, handler2, target) {
79148
79383
  const bound = handler2.bind(this);
@@ -79150,12 +79385,21 @@ ${l}
79150
79385
  target.addEventListener(type2, bound, true);
79151
79386
  };
79152
79387
  dispatchToTarget_fn = function(originalEvent, synthetic) {
79388
+ if (__privateGet$1(this, _destroyed)) return;
79153
79389
  const target = __privateGet$1(this, _getTargetDom).call(this);
79154
79390
  __privateSet(this, _currentTarget, target);
79155
79391
  if (!target) return;
79156
- const canceled = !target.dispatchEvent(synthetic) || synthetic.defaultPrevented;
79157
- if (canceled) {
79158
- originalEvent.preventDefault();
79392
+ const isConnected = target.isConnected;
79393
+ if (isConnected === false) return;
79394
+ try {
79395
+ const canceled = !target.dispatchEvent(synthetic) || synthetic.defaultPrevented;
79396
+ if (canceled) {
79397
+ originalEvent.preventDefault();
79398
+ }
79399
+ } catch (error) {
79400
+ if (process$1$1.env.NODE_ENV === "development") {
79401
+ console.warn("[PresentationEditor] Failed to dispatch event to target:", error);
79402
+ }
79159
79403
  }
79160
79404
  };
79161
79405
  forwardKeyboardEvent_fn = function(event) {
@@ -108045,7 +108289,7 @@ ${style2}
108045
108289
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
108046
108290
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
108047
108291
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
108048
- var _SuperToolbar_instances, initToolbarGroups_fn, _interceptedCommands, makeToolbarItems_fn, initDefaultFonts_fn, updateHighlightColors_fn, deactivateAll_fn, updateToolbarHistory_fn, enrichTrackedChanges_fn, runCommandWithArgumentOnly_fn;
108292
+ var _MARK_TOGGLE_NAMES, _SuperToolbar_instances, initToolbarGroups_fn, _interceptedCommands, makeToolbarItems_fn, initDefaultFonts_fn, updateHighlightColors_fn, deactivateAll_fn, updateToolbarHistory_fn, enrichTrackedChanges_fn, runCommandWithArgumentOnly_fn, syncStickyMarksFromState_fn, restoreStickyMarksIfNeeded_fn, ensureStoredMarksForMarkToggle_fn;
108049
108293
  var eventemitter3$1 = { exports: {} };
108050
108294
  var hasRequiredEventemitter3$1;
108051
108295
  function requireEventemitter3$1() {
@@ -108264,7 +108508,7 @@ ${style2}
108264
108508
  if (!Array.isArray(options.options)) throw new Error("Invalid toolbar item options - " + options.options);
108265
108509
  nestedOptions.value?.push(...options.options);
108266
108510
  }
108267
- const activate = (attrs, ...args) => {
108511
+ const activate = (attrs = {}, ...args) => {
108268
108512
  onActivate(attrs, ...args);
108269
108513
  if (suppressActiveHighlight.value) return;
108270
108514
  active.value = true;
@@ -110536,7 +110780,7 @@ ${style2}
110536
110780
  if (typeof checker !== "function") return false;
110537
110781
  return Boolean(checker(attrs));
110538
110782
  };
110539
- class SuperToolbar extends EventEmitter$1 {
110783
+ const _SuperToolbar = class _SuperToolbar2 extends EventEmitter$1 {
110540
110784
  /**
110541
110785
  * Creates a new SuperToolbar instance
110542
110786
  * @param {ToolbarConfig} config - The configuration for the toolbar
@@ -110580,11 +110824,11 @@ ${style2}
110580
110824
  const isSmallScreen = window.matchMedia("(max-width: 834px)").matches;
110581
110825
  if (isMobileDevice && isSmallScreen) {
110582
110826
  layers.style.transformOrigin = "0 0";
110583
- layers.style.transform = `scale(${parseInt(argument) / 100})`;
110827
+ layers.style.transform = `scale(${parseInt(argument, 10) / 100})`;
110584
110828
  } else {
110585
- layers.style.zoom = parseInt(argument) / 100;
110829
+ layers.style.zoom = parseInt(argument, 10) / 100;
110586
110830
  }
110587
- this.superdoc.superdocStore.activeZoom = parseInt(argument);
110831
+ this.superdoc.superdocStore.activeZoom = parseInt(argument, 10);
110588
110832
  },
110589
110833
  /**
110590
110834
  * Sets the document mode
@@ -110666,31 +110910,37 @@ ${style2}
110666
110910
  * @returns {Promise<void>}
110667
110911
  */
110668
110912
  startImageUpload: async () => {
110669
- let open = getFileOpener();
110670
- let result = await open();
110671
- if (!result?.file) {
110672
- return;
110673
- }
110674
- const { size: size2, file } = await checkAndProcessImage({
110675
- file: result.file,
110676
- getMaxContentSize: () => this.activeEditor.getMaxContentSize()
110677
- });
110678
- if (!file) {
110679
- return;
110913
+ try {
110914
+ let open = getFileOpener();
110915
+ let result = await open();
110916
+ if (!result?.file) {
110917
+ return;
110918
+ }
110919
+ const { size: size2, file } = await checkAndProcessImage({
110920
+ file: result.file,
110921
+ getMaxContentSize: () => this.activeEditor.getMaxContentSize()
110922
+ });
110923
+ if (!file) {
110924
+ return;
110925
+ }
110926
+ const id = {};
110927
+ replaceSelectionWithImagePlaceholder({
110928
+ view: this.activeEditor.view,
110929
+ editorOptions: this.activeEditor.options,
110930
+ id
110931
+ });
110932
+ await uploadAndInsertImage({
110933
+ editor: this.activeEditor,
110934
+ view: this.activeEditor.view,
110935
+ file,
110936
+ size: size2,
110937
+ id
110938
+ });
110939
+ } catch (error) {
110940
+ const err = new Error("[super-toolbar 🎨] Image upload failed");
110941
+ this.emit("exception", { error: err, editor: this.activeEditor, originalError: error });
110942
+ console.error(err, error);
110680
110943
  }
110681
- const id = {};
110682
- replaceSelectionWithImagePlaceholder({
110683
- view: this.activeEditor.view,
110684
- editorOptions: this.activeEditor.options,
110685
- id
110686
- });
110687
- await uploadAndInsertImage({
110688
- editor: this.activeEditor,
110689
- view: this.activeEditor.view,
110690
- file,
110691
- size: size2,
110692
- id
110693
- });
110694
110944
  },
110695
110945
  /**
110696
110946
  * Increases text indentation or list level
@@ -110859,6 +111109,13 @@ ${style2}
110859
111109
  };
110860
111110
  this.config.hideButtons = config2.hideButtons ?? true;
110861
111111
  this.config.responsiveToContainer = config2.responsiveToContainer ?? false;
111112
+ this.pendingMarkCommands = [];
111113
+ this.stickyStoredMarks = null;
111114
+ this._boundEditorHandlers = {
111115
+ transaction: null,
111116
+ selectionUpdate: null,
111117
+ focus: null
111118
+ };
110862
111119
  if (!this.config.selector && this.config.element) {
110863
111120
  this.config.selector = this.config.element;
110864
111121
  }
@@ -110918,12 +111175,28 @@ ${style2}
110918
111175
  }
110919
111176
  /**
110920
111177
  * The toolbar expects an active Super Editor instance.
110921
- * @param {Object} editor - The editor instance to attach to the toolbar
111178
+ * Removes listeners from the previous editor (if any) before attaching to the new one.
111179
+ * @param {Object|null} editor - The editor instance to attach to the toolbar, or null to detach
110922
111180
  * @returns {void}
110923
111181
  */
110924
111182
  setActiveEditor(editor) {
111183
+ if (this.activeEditor && this._boundEditorHandlers.transaction) {
111184
+ this.activeEditor.off("transaction", this._boundEditorHandlers.transaction);
111185
+ this.activeEditor.off("selectionUpdate", this._boundEditorHandlers.selectionUpdate);
111186
+ this.activeEditor.off("focus", this._boundEditorHandlers.focus);
111187
+ this._boundEditorHandlers.transaction = null;
111188
+ this._boundEditorHandlers.selectionUpdate = null;
111189
+ this._boundEditorHandlers.focus = null;
111190
+ }
110925
111191
  this.activeEditor = editor;
110926
- this.activeEditor.on("transaction", this.onEditorTransaction.bind(this));
111192
+ if (editor) {
111193
+ this._boundEditorHandlers.transaction = this.onEditorTransaction.bind(this);
111194
+ this._boundEditorHandlers.selectionUpdate = this.onEditorSelectionUpdate.bind(this);
111195
+ this._boundEditorHandlers.focus = this.onEditorFocus.bind(this);
111196
+ this.activeEditor.on("transaction", this._boundEditorHandlers.transaction);
111197
+ this.activeEditor.on("selectionUpdate", this._boundEditorHandlers.selectionUpdate);
111198
+ this.activeEditor.on("focus", this._boundEditorHandlers.focus);
111199
+ }
110927
111200
  }
110928
111201
  /**
110929
111202
  * Get toolbar items by group name
@@ -111071,15 +111344,28 @@ ${style2}
111071
111344
  * @returns {*} The result of the executed command, undefined if no result is returned
111072
111345
  */
111073
111346
  emitCommand({ item, argument, option }) {
111347
+ const hasFocusFn = this.activeEditor?.view?.hasFocus;
111348
+ const wasFocused = Boolean(typeof hasFocusFn === "function" && hasFocusFn.call(this.activeEditor.view));
111349
+ const { command: command2 } = item;
111350
+ const isMarkToggle = this.isMarkToggle(item);
111351
+ if (!wasFocused && isMarkToggle) {
111352
+ this.pendingMarkCommands.push({ command: command2, argument, item });
111353
+ item?.activate?.();
111354
+ if (this.activeEditor && !this.activeEditor.options.isHeaderOrFooter) {
111355
+ this.activeEditor.focus();
111356
+ }
111357
+ return;
111358
+ }
111074
111359
  if (this.activeEditor && !this.activeEditor.options.isHeaderOrFooter) {
111075
111360
  this.activeEditor.focus();
111076
111361
  }
111077
- const { command: command2 } = item;
111078
111362
  if (!command2) {
111079
111363
  return;
111080
111364
  }
111081
111365
  if (command2 in __privateGet(this, _interceptedCommands)) {
111082
- return __privateGet(this, _interceptedCommands)[command2]({ item, argument });
111366
+ const result = __privateGet(this, _interceptedCommands)[command2]({ item, argument });
111367
+ if (isMarkToggle) __privateMethod(this, _SuperToolbar_instances, syncStickyMarksFromState_fn).call(this);
111368
+ return result;
111083
111369
  }
111084
111370
  if (this.activeEditor && this.activeEditor.commands && command2 in this.activeEditor.commands) {
111085
111371
  this.activeEditor.commands[command2](argument);
@@ -111090,9 +111376,67 @@ ${style2}
111090
111376
  this.emit("exception", { error, editor: this.activeEditor });
111091
111377
  throw error;
111092
111378
  }
111379
+ if (isMarkToggle) __privateMethod(this, _SuperToolbar_instances, syncStickyMarksFromState_fn).call(this);
111093
111380
  this.updateToolbarState();
111094
111381
  }
111095
- }
111382
+ /**
111383
+ * Processes and executes pending mark commands when editor selection updates.
111384
+ * This is triggered by the editor's 'selectionUpdate' event after focus is restored.
111385
+ * Clears the pending queue after execution.
111386
+ * @returns {void}
111387
+ */
111388
+ onEditorSelectionUpdate() {
111389
+ if (!this.activeEditor) return;
111390
+ if (this.pendingMarkCommands.length) {
111391
+ const pending = this.pendingMarkCommands;
111392
+ this.pendingMarkCommands = [];
111393
+ pending.forEach(({ command: command2, argument, item }) => {
111394
+ if (!command2) return;
111395
+ try {
111396
+ if (command2 in __privateGet(this, _interceptedCommands)) {
111397
+ __privateGet(this, _interceptedCommands)[command2]({ item, argument });
111398
+ } else if (this.activeEditor.commands && command2 in this.activeEditor.commands) {
111399
+ this.activeEditor.commands[command2](argument);
111400
+ }
111401
+ __privateMethod(this, _SuperToolbar_instances, ensureStoredMarksForMarkToggle_fn).call(this, { command: command2, argument });
111402
+ } catch (error) {
111403
+ const err = new Error(`[super-toolbar 🎨] Failed to execute pending command: ${command2}`);
111404
+ this.emit("exception", { error: err, editor: this.activeEditor, originalError: error });
111405
+ console.error(err, error);
111406
+ }
111407
+ });
111408
+ __privateMethod(this, _SuperToolbar_instances, syncStickyMarksFromState_fn).call(this);
111409
+ this.updateToolbarState();
111410
+ return;
111411
+ }
111412
+ const restored = __privateMethod(this, _SuperToolbar_instances, restoreStickyMarksIfNeeded_fn).call(this);
111413
+ if (restored) this.updateToolbarState();
111414
+ }
111415
+ /**
111416
+ * Handles editor focus events by flushing any pending mark commands.
111417
+ * This is triggered by the editor's 'focus' event.
111418
+ * @returns {void}
111419
+ */
111420
+ onEditorFocus() {
111421
+ if (this.pendingMarkCommands.length) {
111422
+ this.onEditorSelectionUpdate();
111423
+ return;
111424
+ }
111425
+ const restored = __privateMethod(this, _SuperToolbar_instances, restoreStickyMarksIfNeeded_fn).call(this);
111426
+ if (restored) this.updateToolbarState();
111427
+ }
111428
+ /**
111429
+ * Determines if a toolbar item represents a mark toggle command.
111430
+ * Mark toggles include text formatting commands like bold, italic, underline, etc.
111431
+ * @param {ToolbarItem} item - The toolbar item to check
111432
+ * @returns {boolean} True if the item is a mark toggle, false otherwise
111433
+ */
111434
+ isMarkToggle(item) {
111435
+ const name = item?.name?.value;
111436
+ return __privateGet(_SuperToolbar2, _MARK_TOGGLE_NAMES).has(name);
111437
+ }
111438
+ };
111439
+ _MARK_TOGGLE_NAMES = /* @__PURE__ */ new WeakMap();
111096
111440
  _SuperToolbar_instances = /* @__PURE__ */ new WeakSet();
111097
111441
  initToolbarGroups_fn = function() {
111098
111442
  if (this.config.groups && !Array.isArray(this.config.groups) && Object.keys(this.config.groups).length) {
@@ -111205,6 +111549,55 @@ ${style2}
111205
111549
  this.updateToolbarState();
111206
111550
  }
111207
111551
  };
111552
+ syncStickyMarksFromState_fn = function() {
111553
+ if (!this.activeEditor) return;
111554
+ const { selection, storedMarks } = this.activeEditor.state || {};
111555
+ if (!selection?.empty) return;
111556
+ this.stickyStoredMarks = storedMarks?.length ? [...storedMarks] : null;
111557
+ };
111558
+ restoreStickyMarksIfNeeded_fn = function() {
111559
+ if (!this.activeEditor) return false;
111560
+ if (!this.stickyStoredMarks?.length) return false;
111561
+ const { state: state2, view } = this.activeEditor;
111562
+ const { selection, storedMarks } = state2 || {};
111563
+ if (!selection?.empty) return false;
111564
+ if (storedMarks?.length) return false;
111565
+ if (!view?.dispatch || !state2?.tr) return false;
111566
+ const hasActiveMarkToggle = getActiveFormatting(this.activeEditor).some(
111567
+ (mark2) => __privateGet(_SuperToolbar, _MARK_TOGGLE_NAMES).has(mark2.name)
111568
+ );
111569
+ if (hasActiveMarkToggle) return false;
111570
+ const tr = state2.tr.setStoredMarks(this.stickyStoredMarks);
111571
+ view.dispatch(tr);
111572
+ return true;
111573
+ };
111574
+ ensureStoredMarksForMarkToggle_fn = function({ command: command2, argument }) {
111575
+ if (!this.activeEditor) return;
111576
+ if (!this.activeEditor.state?.selection?.empty) return;
111577
+ if (this.activeEditor.state?.storedMarks?.length) return;
111578
+ if (command2 !== "setFontSize") return;
111579
+ const { state: state2, view } = this.activeEditor;
111580
+ const textStyleMark = state2.schema?.marks?.textStyle;
111581
+ if (!textStyleMark || !view?.dispatch || !state2?.tr) return;
111582
+ const [value, unit] = parseSizeUnit(argument ?? "");
111583
+ if (Number.isNaN(value)) return;
111584
+ const clamped = Math.min(96, Math.max(8, Number(value)));
111585
+ const resolvedUnit = unit || "pt";
111586
+ const mark2 = textStyleMark.create({ fontSize: `${clamped}${resolvedUnit}` });
111587
+ const tr = state2.tr.setStoredMarks([mark2]);
111588
+ view.dispatch(tr);
111589
+ };
111590
+ __privateAdd(_SuperToolbar, _MARK_TOGGLE_NAMES, /* @__PURE__ */ new Set([
111591
+ "bold",
111592
+ "italic",
111593
+ "underline",
111594
+ "strike",
111595
+ "highlight",
111596
+ "color",
111597
+ "fontSize",
111598
+ "fontFamily"
111599
+ ]));
111600
+ let SuperToolbar = _SuperToolbar;
111208
111601
  const onMarginClickCursorChange = (event, editor) => {
111209
111602
  const y2 = event.clientY;
111210
111603
  const x2 = event.clientX;
@@ -130653,7 +131046,7 @@ ${style2}
130653
131046
  this.config.colors = shuffleArray(this.config.colors);
130654
131047
  this.userColorMap = /* @__PURE__ */ new Map();
130655
131048
  this.colorIndex = 0;
130656
- this.version = "1.0.0-beta.2";
131049
+ this.version = "1.0.0-beta.3";
130657
131050
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
130658
131051
  this.superdocId = config2.superdocId || v4();
130659
131052
  this.colors = this.config.colors;
@@ -133096,7 +133489,7 @@ ${style2}
133096
133489
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
133097
133490
  );
133098
133491
  }
133099
- const indexSnJVHIg = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
133492
+ const indexCJUy3fVi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
133100
133493
  __proto__: null,
133101
133494
  unified
133102
133495
  }, Symbol.toStringTag, { value: "Module" }));