superdoc 1.0.0-beta.31 → 1.0.0-beta.32

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-C8iiBtQt.cjs → PdfViewer-CTKbqDWv.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-jGctuklH.es.js → PdfViewer-edjIRb_p.es.js} +1 -1
  3. package/dist/chunks/{index-ELjoBC86.cjs → index-Cajp7-Xa.cjs} +3 -3
  4. package/dist/chunks/{index-Bu5UUj9S.es.js → index-Pwv0a9G5.es.js} +3 -3
  5. package/dist/chunks/{index-eG-VYUeN-CIuOnW8W.es.js → index-SGV4U12y-BPGxOtvI.es.js} +1 -1
  6. package/dist/chunks/{index-eG-VYUeN-CG3M1n5T.cjs → index-SGV4U12y-Dh5jaROA.cjs} +1 -1
  7. package/dist/chunks/{super-editor.es-DatOA_vA.cjs → super-editor.es-BbbbKgEs.cjs} +1314 -62
  8. package/dist/chunks/{super-editor.es-BAKZgAuj.es.js → super-editor.es-CdGsYGU1.es.js} +1314 -62
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-CRKt1TG_.js → converter-CpuOoAUa.js} +1 -1
  11. package/dist/super-editor/chunks/{docx-zipper-CgVw58T-.js → docx-zipper-Dk99r397.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-COQCS1pn.js → editor-CFv-RJI-.js} +1363 -63
  13. package/dist/super-editor/chunks/{index-eG-VYUeN.js → index-SGV4U12y.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-B3CSV2yT.js → toolbar-CQr3Xnx9.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 +1316 -64
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -41858,7 +41858,7 @@ const _SuperConverter = class _SuperConverter2 {
41858
41858
  static getStoredSuperdocVersion(docx) {
41859
41859
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
41860
41860
  }
41861
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.31") {
41861
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.32") {
41862
41862
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
41863
41863
  }
41864
41864
  /**
@@ -45164,7 +45164,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
45164
45164
  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);
45165
45165
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
45166
45166
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
45167
- 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, _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, _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, calculateExtendedSelection_fn, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _handlePointerUp, _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, 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, 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;
45167
+ 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, _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, setupDragHandlers_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, 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, 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;
45168
45168
  var GOOD_LEAF_SIZE = 200;
45169
45169
  var RopeSequence = function RopeSequence2() {
45170
45170
  };
@@ -59031,7 +59031,7 @@ const isHeadless = (editor) => {
59031
59031
  const shouldSkipNodeView = (editor) => {
59032
59032
  return isHeadless(editor);
59033
59033
  };
59034
- const summaryVersion = "1.0.0-beta.31";
59034
+ const summaryVersion = "1.0.0-beta.32";
59035
59035
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
59036
59036
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
59037
59037
  function mapAttributes(attrs) {
@@ -59820,7 +59820,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
59820
59820
  { default: remarkStringify },
59821
59821
  { default: remarkGfm }
59822
59822
  ] = await Promise.all([
59823
- Promise.resolve().then(() => require("./index-eG-VYUeN-CG3M1n5T.cjs")),
59823
+ Promise.resolve().then(() => require("./index-SGV4U12y-Dh5jaROA.cjs")),
59824
59824
  Promise.resolve().then(() => require("./index-DRCvimau-H4Ck3S9a.cjs")),
59825
59825
  Promise.resolve().then(() => require("./index-C_x_N6Uh-Db3CUJMX.cjs")),
59826
59826
  Promise.resolve().then(() => require("./index-D_sWOSiG-BtDZzJ6I.cjs")),
@@ -60025,7 +60025,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
60025
60025
  * Process collaboration migrations
60026
60026
  */
60027
60027
  processCollaborationMigrations() {
60028
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.31");
60028
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.32");
60029
60029
  if (!this.options.ydoc) return;
60030
60030
  const metaMap = this.options.ydoc.getMap("meta");
60031
60031
  let docVersion = metaMap.get("version");
@@ -65167,7 +65167,27 @@ function handleStructuredContentBlockNode(node, context) {
65167
65167
  blocks.push(block);
65168
65168
  recordBlockKind(block.kind);
65169
65169
  });
65170
- } else if (child.type === "table") ;
65170
+ } else if (child.type === "table") {
65171
+ const tableNodeToBlock2 = converters?.tableNodeToBlock;
65172
+ if (tableNodeToBlock2) {
65173
+ const tableBlock = tableNodeToBlock2(
65174
+ child,
65175
+ nextBlockId,
65176
+ positions,
65177
+ defaultFont,
65178
+ defaultSize,
65179
+ styleContext,
65180
+ trackedChangesConfig,
65181
+ bookmarks,
65182
+ hyperlinkConfig
65183
+ );
65184
+ if (tableBlock) {
65185
+ applySdtMetadataToTableBlock(tableBlock, structuredContentMetadata);
65186
+ blocks.push(tableBlock);
65187
+ recordBlockKind(tableBlock.kind);
65188
+ }
65189
+ }
65190
+ }
65171
65191
  });
65172
65192
  }
65173
65193
  function processParagraphChild(child, sectionMetadata, context, output, converters) {
@@ -65637,6 +65657,65 @@ function imageNodeToRun(node, positions, activeSdt) {
65637
65657
  }
65638
65658
  return run2;
65639
65659
  }
65660
+ function fieldAnnotationNodeToRun(node, positions, fieldMetadata) {
65661
+ const attrs = node.attrs ?? {};
65662
+ const rawVariant = attrs.type ?? fieldMetadata?.variant ?? "text";
65663
+ const validVariants = ["text", "image", "signature", "checkbox", "html", "link"];
65664
+ const variant = validVariants.includes(rawVariant) ? rawVariant : "text";
65665
+ const displayLabel = (typeof attrs.displayLabel === "string" ? attrs.displayLabel : void 0) || (typeof attrs.defaultDisplayLabel === "string" ? attrs.defaultDisplayLabel : void 0) || (typeof fieldMetadata?.displayLabel === "string" ? fieldMetadata.displayLabel : void 0) || (typeof fieldMetadata?.defaultDisplayLabel === "string" ? fieldMetadata.defaultDisplayLabel : void 0) || (typeof attrs.alias === "string" ? attrs.alias : void 0) || (typeof fieldMetadata?.alias === "string" ? fieldMetadata.alias : void 0) || "";
65666
+ const run2 = {
65667
+ kind: "fieldAnnotation",
65668
+ variant,
65669
+ displayLabel
65670
+ };
65671
+ const fieldId = typeof attrs.fieldId === "string" ? attrs.fieldId : fieldMetadata?.fieldId;
65672
+ if (fieldId) run2.fieldId = fieldId;
65673
+ const fieldType = typeof attrs.fieldType === "string" ? attrs.fieldType : fieldMetadata?.fieldType;
65674
+ if (fieldType) run2.fieldType = fieldType;
65675
+ const fieldColor = typeof attrs.fieldColor === "string" ? attrs.fieldColor : fieldMetadata?.fieldColor;
65676
+ if (fieldColor) run2.fieldColor = fieldColor;
65677
+ const borderColor = typeof attrs.borderColor === "string" ? attrs.borderColor : fieldMetadata?.borderColor;
65678
+ if (borderColor) run2.borderColor = borderColor;
65679
+ const highlighted = attrs.highlighted ?? fieldMetadata?.highlighted;
65680
+ if (highlighted === false) run2.highlighted = false;
65681
+ if (attrs.hidden === true || fieldMetadata?.hidden === true) run2.hidden = true;
65682
+ const visibility = attrs.visibility ?? fieldMetadata?.visibility;
65683
+ if (visibility === "hidden") run2.visibility = "hidden";
65684
+ const imageSrc = typeof attrs.imageSrc === "string" ? attrs.imageSrc : fieldMetadata?.imageSrc;
65685
+ if (imageSrc) run2.imageSrc = imageSrc;
65686
+ const linkUrl = typeof attrs.linkUrl === "string" ? attrs.linkUrl : fieldMetadata?.linkUrl;
65687
+ if (linkUrl) run2.linkUrl = linkUrl;
65688
+ const rawHtml = attrs.rawHtml ?? fieldMetadata?.rawHtml;
65689
+ if (typeof rawHtml === "string") run2.rawHtml = rawHtml;
65690
+ const size2 = attrs.size ?? fieldMetadata?.size;
65691
+ if (size2 && (typeof size2.width === "number" || typeof size2.height === "number")) {
65692
+ run2.size = {
65693
+ width: typeof size2.width === "number" ? size2.width : void 0,
65694
+ height: typeof size2.height === "number" ? size2.height : void 0
65695
+ };
65696
+ }
65697
+ const fontFamily2 = attrs.fontFamily ?? fieldMetadata?.fontFamily;
65698
+ if (typeof fontFamily2 === "string") run2.fontFamily = fontFamily2;
65699
+ const fontSize2 = attrs.fontSize ?? fieldMetadata?.fontSize;
65700
+ if (typeof fontSize2 === "string" || typeof fontSize2 === "number") run2.fontSize = fontSize2;
65701
+ const textColor = attrs.textColor ?? fieldMetadata?.textColor;
65702
+ if (typeof textColor === "string") run2.textColor = textColor;
65703
+ const textHighlight = attrs.textHighlight ?? fieldMetadata?.textHighlight;
65704
+ if (typeof textHighlight === "string") run2.textHighlight = textHighlight;
65705
+ const formatting = fieldMetadata?.formatting;
65706
+ if (attrs.bold === true || formatting?.bold === true) run2.bold = true;
65707
+ if (attrs.italic === true || formatting?.italic === true) run2.italic = true;
65708
+ if (attrs.underline === true || formatting?.underline === true) run2.underline = true;
65709
+ const pos = positions.get(node);
65710
+ if (pos) {
65711
+ run2.pmStart = pos.start;
65712
+ run2.pmEnd = pos.end;
65713
+ }
65714
+ if (fieldMetadata) {
65715
+ run2.sdt = fieldMetadata;
65716
+ }
65717
+ return run2;
65718
+ }
65640
65719
  const isTextRun$1 = (run2) => run2.kind !== "tab";
65641
65720
  const dataAttrsCompatible = (a, b2) => {
65642
65721
  const aAttrs = a.dataAttrs;
@@ -65932,28 +66011,20 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
65932
66011
  }
65933
66012
  if (node.type === "fieldAnnotation") {
65934
66013
  const fieldMetadata = resolveNodeSdtMetadata(node, "fieldAnnotation");
66014
+ let contentText;
65935
66015
  if (Array.isArray(node.content) && node.content.length > 0) {
65936
- node.content.forEach((child) => visitNode(child, inheritedMarks, fieldMetadata ?? activeSdt, activeRunStyleId));
65937
- } else {
65938
- const nodeAttrs = typeof node.attrs === "object" && node.attrs !== null ? node.attrs : {};
65939
- const label = (typeof nodeAttrs.displayLabel === "string" ? nodeAttrs.displayLabel : void 0) || (typeof nodeAttrs.defaultDisplayLabel === "string" ? nodeAttrs.defaultDisplayLabel : void 0) || (typeof nodeAttrs.alias === "string" ? nodeAttrs.alias : void 0) || "";
65940
- if (label && typeof label === "string") {
65941
- const run2 = textNodeToRun(
65942
- { type: "text", text: label },
65943
- positions,
65944
- defaultFont,
65945
- defaultSize,
65946
- inheritedMarks,
65947
- fieldMetadata ?? activeSdt,
65948
- hyperlinkConfig,
65949
- themeColors
65950
- );
65951
- const inlineStyleId = getInlineStyleId(inheritedMarks);
65952
- applyRunStyles2(run2, inlineStyleId, activeRunStyleId);
65953
- applyBaseRunDefaults(run2, baseRunDefaults, defaultFont, defaultSize);
65954
- currentRuns.push(run2);
65955
- }
66016
+ const extractText = (n) => {
66017
+ if (n.type === "text" && typeof n.text === "string") return n.text;
66018
+ if (Array.isArray(n.content)) {
66019
+ return n.content.map(extractText).join("");
66020
+ }
66021
+ return "";
66022
+ };
66023
+ contentText = node.content.map(extractText).join("");
65956
66024
  }
66025
+ const nodeForRun = contentText && contentText.length > 0 ? { ...node, attrs: { ...node.attrs ?? {}, displayLabel: contentText } } : node;
66026
+ const run2 = fieldAnnotationNodeToRun(nodeForRun, positions, fieldMetadata);
66027
+ currentRuns.push(run2);
65957
66028
  return;
65958
66029
  }
65959
66030
  if (node.type === "pageReference") {
@@ -66790,9 +66861,9 @@ const extractTableStyleParagraphProps = (styleId, docx) => {
66790
66861
  }
66791
66862
  const attrs = spacingEl.attributes;
66792
66863
  const spacing = {};
66793
- const before = parseIntSafe(attrs["w:before"]);
66794
- const after = parseIntSafe(attrs["w:after"]);
66795
- const line = parseIntSafe(attrs["w:line"]);
66864
+ const before = parseIntSafe$1(attrs["w:before"]);
66865
+ const after = parseIntSafe$1(attrs["w:after"]);
66866
+ const line = parseIntSafe$1(attrs["w:line"]);
66796
66867
  const rawLineRule = attrs["w:lineRule"];
66797
66868
  const lineRule = rawLineRule === "auto" || rawLineRule === "exact" || rawLineRule === "atLeast" ? rawLineRule : void 0;
66798
66869
  if (before != null) spacing.before = twipsToPx$1(before);
@@ -66807,11 +66878,11 @@ const extractTableStyleParagraphProps = (styleId, docx) => {
66807
66878
  if (lineRule) spacing.lineRule = lineRule;
66808
66879
  const result = Object.keys(spacing).length > 0 ? { spacing } : void 0;
66809
66880
  return result;
66810
- } catch (err) {
66881
+ } catch {
66811
66882
  return void 0;
66812
66883
  }
66813
66884
  };
66814
- const parseIntSafe = (value) => {
66885
+ const parseIntSafe$1 = (value) => {
66815
66886
  if (value == null) return void 0;
66816
66887
  const num = typeof value === "number" ? value : parseInt(String(value), 10);
66817
66888
  return Number.isFinite(num) ? num : void 0;
@@ -67463,7 +67534,7 @@ function getMeasurementContext() {
67463
67534
  return measurementCtx;
67464
67535
  }
67465
67536
  function getRunFontString(run2) {
67466
- if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || "src" in run2) {
67537
+ if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || "src" in run2) {
67467
67538
  return "normal normal 16px Arial";
67468
67539
  }
67469
67540
  const style2 = run2.italic ? "italic" : "normal";
@@ -67494,6 +67565,10 @@ function sliceRunsForLine$1(block, line) {
67494
67565
  result.push(run2);
67495
67566
  continue;
67496
67567
  }
67568
+ if (run2.kind === "fieldAnnotation") {
67569
+ result.push(run2);
67570
+ continue;
67571
+ }
67497
67572
  const text = run2.text ?? "";
67498
67573
  const isFirstRun = runIndex === line.fromRun;
67499
67574
  const isLastRun = runIndex === line.toRun;
@@ -67527,7 +67602,8 @@ function measureCharacterX(block, line, charOffset) {
67527
67602
  1,
67528
67603
  runs2.reduce((sum, run2) => {
67529
67604
  if (isTabRun$1(run2)) return sum + TAB_CHAR_LENGTH;
67530
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") return sum;
67605
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
67606
+ return sum;
67531
67607
  return sum + (run2.text ?? "").length;
67532
67608
  }, 0)
67533
67609
  );
@@ -67548,7 +67624,7 @@ function measureCharacterX(block, line, charOffset) {
67548
67624
  currentCharOffset += runLength2;
67549
67625
  continue;
67550
67626
  }
67551
- const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
67627
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
67552
67628
  const runLength = text.length;
67553
67629
  if (currentCharOffset + runLength >= charOffset) {
67554
67630
  const offsetInRun = charOffset - currentCharOffset;
@@ -67591,7 +67667,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
67591
67667
  if (isTabRun$1(run2)) {
67592
67668
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
67593
67669
  }
67594
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") {
67670
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation") {
67595
67671
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
67596
67672
  }
67597
67673
  const text = run2.text ?? "";
@@ -67620,7 +67696,7 @@ function charOffsetToPm(block, line, charOffset, fallbackPmStart) {
67620
67696
  let lastPm = fallbackPmStart;
67621
67697
  for (const run2 of runs) {
67622
67698
  const isTab = isTabRun$1(run2);
67623
- const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
67699
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
67624
67700
  const runLength = isTab ? TAB_CHAR_LENGTH : text.length;
67625
67701
  const runPmStart = typeof run2.pmStart === "number" ? run2.pmStart : null;
67626
67702
  const runPmEnd = typeof run2.pmEnd === "number" ? run2.pmEnd : runPmStart != null ? runPmStart + runLength : null;
@@ -67646,7 +67722,8 @@ function findCharacterAtX(block, line, x2, pmStart) {
67646
67722
  1,
67647
67723
  runs2.reduce((sum, run2) => {
67648
67724
  if (isTabRun$1(run2)) return sum + TAB_CHAR_LENGTH;
67649
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") return sum;
67725
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
67726
+ return sum;
67650
67727
  return sum + (run2.text ?? "").length;
67651
67728
  }, 0)
67652
67729
  );
@@ -67681,7 +67758,7 @@ function findCharacterAtX(block, line, x2, pmStart) {
67681
67758
  currentCharOffset += TAB_CHAR_LENGTH;
67682
67759
  continue;
67683
67760
  }
67684
- const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
67761
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
67685
67762
  const runLength = text.length;
67686
67763
  if (runLength === 0) continue;
67687
67764
  ctx2.font = getRunFontString(run2);
@@ -67721,7 +67798,7 @@ function findCharacterAtX(block, line, x2, pmStart) {
67721
67798
  };
67722
67799
  }
67723
67800
  const computeLetterSpacingWidth = (run2, precedingChars, runLength) => {
67724
- if (isTabRun$1(run2) || "src" in run2 || !("letterSpacing" in run2) || !run2.letterSpacing) {
67801
+ if (isTabRun$1(run2) || "src" in run2 || run2.kind === "fieldAnnotation" || !("letterSpacing" in run2) || !run2.letterSpacing) {
67725
67802
  return 0;
67726
67803
  }
67727
67804
  const maxGaps = Math.max(runLength - 1, 0);
@@ -67818,6 +67895,17 @@ function clickToPositionDom(domContainer, clientX, clientY) {
67818
67895
  pmStart: fragmentEl.dataset.pmStart,
67819
67896
  pmEnd: fragmentEl.dataset.pmEnd
67820
67897
  });
67898
+ const hitChainLine = hitChain.find(
67899
+ (el) => el.classList?.contains?.(CLASS_NAMES$1.line) && el.dataset?.pmStart !== void 0 && el.dataset?.pmEnd !== void 0
67900
+ );
67901
+ if (hitChainLine) {
67902
+ log("Using hit chain line directly:", {
67903
+ pmStart: hitChainLine.dataset.pmStart,
67904
+ pmEnd: hitChainLine.dataset.pmEnd
67905
+ });
67906
+ const result2 = processLineElement(hitChainLine, viewX);
67907
+ return result2;
67908
+ }
67821
67909
  const result = processFragment(fragmentEl, viewX, viewY);
67822
67910
  return result;
67823
67911
  }
@@ -67883,7 +67971,9 @@ function processFragment(fragmentEl, viewX, viewY) {
67883
67971
  if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
67884
67972
  return null;
67885
67973
  }
67886
- const spanEls = Array.from(lineEl.querySelectorAll("span, a"));
67974
+ const spanEls = Array.from(lineEl.querySelectorAll("span, a")).filter(
67975
+ (el) => el.dataset.pmStart !== void 0 && el.dataset.pmEnd !== void 0
67976
+ );
67887
67977
  log(
67888
67978
  "Spans/anchors in line:",
67889
67979
  spanEls.map((el, i) => {
@@ -67942,6 +68032,77 @@ function processFragment(fragmentEl, viewX, viewY) {
67942
68032
  const pos = spanStart + charIndex;
67943
68033
  return pos;
67944
68034
  }
68035
+ function processLineElement(lineEl, viewX) {
68036
+ const lineStart = Number(lineEl.dataset.pmStart ?? "NaN");
68037
+ const lineEnd = Number(lineEl.dataset.pmEnd ?? "NaN");
68038
+ const lineRect = lineEl.getBoundingClientRect();
68039
+ log("processLineElement:", {
68040
+ pmStart: lineStart,
68041
+ pmEnd: lineEnd,
68042
+ rect: { top: lineRect.top, bottom: lineRect.bottom, left: lineRect.left, right: lineRect.right }
68043
+ });
68044
+ if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
68045
+ return null;
68046
+ }
68047
+ const spanEls = Array.from(lineEl.querySelectorAll("span, a")).filter(
68048
+ (el) => el.dataset.pmStart !== void 0 && el.dataset.pmEnd !== void 0
68049
+ );
68050
+ log(
68051
+ "Spans/anchors in line:",
68052
+ spanEls.map((el, i) => {
68053
+ const rect = el.getBoundingClientRect();
68054
+ return {
68055
+ index: i,
68056
+ tag: el.tagName,
68057
+ pmStart: el.dataset.pmStart,
68058
+ pmEnd: el.dataset.pmEnd,
68059
+ text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
68060
+ visibility: el.style.visibility,
68061
+ rect: { left: rect.left, right: rect.right, width: rect.width }
68062
+ };
68063
+ })
68064
+ );
68065
+ if (spanEls.length === 0) {
68066
+ return lineStart;
68067
+ }
68068
+ const firstRect = spanEls[0].getBoundingClientRect();
68069
+ if (viewX <= firstRect.left) {
68070
+ return lineStart;
68071
+ }
68072
+ const lastRect = spanEls[spanEls.length - 1].getBoundingClientRect();
68073
+ if (viewX >= lastRect.right) {
68074
+ return lineEnd;
68075
+ }
68076
+ const targetEl = findSpanAtX(spanEls, viewX);
68077
+ if (!targetEl) {
68078
+ return lineStart;
68079
+ }
68080
+ const spanStart = Number(targetEl.dataset.pmStart ?? "NaN");
68081
+ const spanEnd = Number(targetEl.dataset.pmEnd ?? "NaN");
68082
+ const targetRect = targetEl.getBoundingClientRect();
68083
+ log("Target element:", {
68084
+ tag: targetEl.tagName,
68085
+ pmStart: spanStart,
68086
+ pmEnd: spanEnd,
68087
+ text: targetEl.textContent?.substring(0, 30),
68088
+ visibility: targetEl.style.visibility,
68089
+ rect: { left: targetRect.left, right: targetRect.right, width: targetRect.width }
68090
+ });
68091
+ if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) {
68092
+ return null;
68093
+ }
68094
+ const firstChild = targetEl.firstChild;
68095
+ if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
68096
+ const elRect = targetEl.getBoundingClientRect();
68097
+ const closerToLeft = Math.abs(viewX - elRect.left) <= Math.abs(viewX - elRect.right);
68098
+ const snapPos = closerToLeft ? spanStart : spanEnd;
68099
+ return snapPos;
68100
+ }
68101
+ const textNode = firstChild;
68102
+ const charIndex = findCharIndexAtX(textNode, targetEl, viewX);
68103
+ const pos = spanStart + charIndex;
68104
+ return pos;
68105
+ }
67945
68106
  function findLineAtY(lineEls, viewY) {
67946
68107
  if (lineEls.length === 0) {
67947
68108
  return null;
@@ -70832,7 +70993,7 @@ const hashRuns = (block) => {
70832
70993
  return `img:${srcHash}:${imgRun.width}x${imgRun.height}`;
70833
70994
  }
70834
70995
  const text = normalizeText(
70835
- "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? ""
70996
+ "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? ""
70836
70997
  );
70837
70998
  const bold = "bold" in run2 ? run2.bold : false;
70838
70999
  const italic = "italic" in run2 ? run2.italic : false;
@@ -71544,7 +71705,7 @@ function extractBlockText(block) {
71544
71705
  let pmStart = Infinity;
71545
71706
  let pmEnd = 0;
71546
71707
  for (const run2 of block.runs) {
71547
- text += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text;
71708
+ text += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text;
71548
71709
  if (run2.pmStart !== void 0) {
71549
71710
  pmStart = Math.min(pmStart, run2.pmStart);
71550
71711
  }
@@ -71594,7 +71755,7 @@ function fontString(run2) {
71594
71755
  return `${italic}${bold}${size2}px ${family}`.trim();
71595
71756
  }
71596
71757
  function runText(run2) {
71597
- return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
71758
+ return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
71598
71759
  }
71599
71760
  function measureRunSliceWidth(run2, fromChar, toChar) {
71600
71761
  const context = getCtx();
@@ -71756,7 +71917,7 @@ const paragraphBlocksEqual = (a, b2) => {
71756
71917
  for (let i = 0; i < a.runs.length; i += 1) {
71757
71918
  const runA = a.runs[i];
71758
71919
  const runB = b2.runs[i];
71759
- if (("src" in runA || runA.kind === "lineBreak" || runA.kind === "break" ? "" : runA.text) !== ("src" in runB || runB.kind === "lineBreak" || runB.kind === "break" ? "" : runB.text) || ("bold" in runA ? runA.bold : false) !== ("bold" in runB ? runB.bold : false) || ("italic" in runA ? runA.italic : false) !== ("italic" in runB ? runB.italic : false) || ("color" in runA ? runA.color : void 0) !== ("color" in runB ? runB.color : void 0) || getTrackedChangeKey(runA) !== getTrackedChangeKey(runB)) {
71920
+ if (("src" in runA || runA.kind === "lineBreak" || runA.kind === "break" || runA.kind === "fieldAnnotation" ? "" : runA.text) !== ("src" in runB || runB.kind === "lineBreak" || runB.kind === "break" || runB.kind === "fieldAnnotation" ? "" : runB.text) || ("bold" in runA ? runA.bold : false) !== ("bold" in runB ? runB.bold : false) || ("italic" in runA ? runA.italic : false) !== ("italic" in runB ? runB.italic : false) || ("color" in runA ? runA.color : void 0) !== ("color" in runB ? runB.color : void 0) || getTrackedChangeKey(runA) !== getTrackedChangeKey(runB)) {
71760
71921
  return false;
71761
71922
  }
71762
71923
  }
@@ -71876,7 +72037,7 @@ function computeHeaderFooterContentHash(blocks) {
71876
72037
  parts.push(block.id);
71877
72038
  if (block.kind === "paragraph") {
71878
72039
  for (const run2 of block.runs) {
71879
- if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break") {
72040
+ if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break" && run2.kind !== "fieldAnnotation") {
71880
72041
  parts.push(run2.text ?? "");
71881
72042
  }
71882
72043
  if ("bold" in run2 && run2.bold) parts.push("b");
@@ -72361,6 +72522,255 @@ var Priority = /* @__PURE__ */ ((Priority2) => {
72361
72522
  /** P3: Heavy debounce for full document layout */
72362
72523
  [Priority.P3]: 150
72363
72524
  });
72525
+ const DEFAULT_MIME_TYPE$1 = "application/x-field-annotation";
72526
+ const LEGACY_MIME_TYPE = "fieldAnnotation";
72527
+ function parseIntSafe(value) {
72528
+ if (!value) return void 0;
72529
+ const parsed = parseInt(value, 10);
72530
+ return Number.isFinite(parsed) ? parsed : void 0;
72531
+ }
72532
+ function extractFieldAnnotationData(element) {
72533
+ const dataset = element.dataset;
72534
+ const attributes = {};
72535
+ for (const key2 in dataset) {
72536
+ const value = dataset[key2];
72537
+ if (value !== void 0) {
72538
+ attributes[key2] = value;
72539
+ }
72540
+ }
72541
+ return {
72542
+ fieldId: dataset.fieldId,
72543
+ fieldType: dataset.fieldType,
72544
+ variant: dataset.variant ?? dataset.type,
72545
+ displayLabel: dataset.displayLabel,
72546
+ pmStart: parseIntSafe(dataset.pmStart),
72547
+ pmEnd: parseIntSafe(dataset.pmEnd),
72548
+ attributes
72549
+ };
72550
+ }
72551
+ class DragHandler {
72552
+ /**
72553
+ * Creates a new DragHandler instance.
72554
+ *
72555
+ * @param container - The DOM container element (typically .superdoc-layout)
72556
+ * @param config - Configuration options and callbacks
72557
+ */
72558
+ constructor(container, config2 = {}) {
72559
+ this.container = container;
72560
+ this.config = config2;
72561
+ this.mimeType = config2.mimeType ?? DEFAULT_MIME_TYPE$1;
72562
+ this.boundHandlers = {
72563
+ dragstart: this.handleDragStart.bind(this),
72564
+ dragover: this.handleDragOver.bind(this),
72565
+ drop: this.handleDrop.bind(this),
72566
+ dragend: this.handleDragEnd.bind(this),
72567
+ dragleave: this.handleDragLeave.bind(this)
72568
+ };
72569
+ this.windowDragoverHandler = this.handleWindowDragOver.bind(this);
72570
+ this.windowDropHandler = this.handleWindowDrop.bind(this);
72571
+ this.attachListeners();
72572
+ }
72573
+ /**
72574
+ * Attaches event listeners to the container and window.
72575
+ */
72576
+ attachListeners() {
72577
+ this.container.addEventListener("dragstart", this.boundHandlers.dragstart);
72578
+ this.container.addEventListener("dragover", this.boundHandlers.dragover);
72579
+ this.container.addEventListener("drop", this.boundHandlers.drop);
72580
+ this.container.addEventListener("dragend", this.boundHandlers.dragend);
72581
+ this.container.addEventListener("dragleave", this.boundHandlers.dragleave);
72582
+ window.addEventListener("dragover", this.windowDragoverHandler, false);
72583
+ window.addEventListener("drop", this.windowDropHandler, false);
72584
+ }
72585
+ /**
72586
+ * Removes event listeners from the container and window.
72587
+ */
72588
+ removeListeners() {
72589
+ this.container.removeEventListener("dragstart", this.boundHandlers.dragstart);
72590
+ this.container.removeEventListener("dragover", this.boundHandlers.dragover);
72591
+ this.container.removeEventListener("drop", this.boundHandlers.drop);
72592
+ this.container.removeEventListener("dragend", this.boundHandlers.dragend);
72593
+ this.container.removeEventListener("dragleave", this.boundHandlers.dragleave);
72594
+ window.removeEventListener("dragover", this.windowDragoverHandler, false);
72595
+ window.removeEventListener("drop", this.windowDropHandler, false);
72596
+ }
72597
+ /**
72598
+ * Handles dragover at window level to allow drops on overlay elements.
72599
+ * This ensures preventDefault is called even when dragging over selection
72600
+ * highlights or other UI elements that sit on top of the layout content.
72601
+ */
72602
+ handleWindowDragOver(event) {
72603
+ if (this.hasFieldAnnotationData(event)) {
72604
+ event.preventDefault();
72605
+ if (event.dataTransfer) {
72606
+ event.dataTransfer.dropEffect = "move";
72607
+ }
72608
+ const target = event.target;
72609
+ if (!this.container.contains(target)) {
72610
+ this.config.onDragOver?.({
72611
+ event,
72612
+ clientX: event.clientX,
72613
+ clientY: event.clientY,
72614
+ hasFieldAnnotation: true
72615
+ });
72616
+ }
72617
+ }
72618
+ }
72619
+ /**
72620
+ * Handles drop at window level to catch drops on overlay elements.
72621
+ * If the drop target is outside the container, we process it here.
72622
+ */
72623
+ handleWindowDrop(event) {
72624
+ if (this.hasFieldAnnotationData(event)) {
72625
+ const target = event.target;
72626
+ if (!this.container.contains(target)) {
72627
+ this.handleDrop(event);
72628
+ }
72629
+ }
72630
+ }
72631
+ /**
72632
+ * Handles the dragstart event.
72633
+ * Sets up dataTransfer with field annotation data and drag image.
72634
+ */
72635
+ handleDragStart(event) {
72636
+ const target = event.target;
72637
+ if (!target?.dataset?.draggable || target.dataset.draggable !== "true") {
72638
+ return;
72639
+ }
72640
+ const data = extractFieldAnnotationData(target);
72641
+ if (event.dataTransfer) {
72642
+ const jsonData = JSON.stringify({
72643
+ attributes: data.attributes,
72644
+ sourceField: data
72645
+ });
72646
+ event.dataTransfer.setData(this.mimeType, jsonData);
72647
+ event.dataTransfer.setData(LEGACY_MIME_TYPE, jsonData);
72648
+ event.dataTransfer.setData("text/plain", data.displayLabel ?? "Field Annotation");
72649
+ event.dataTransfer.setDragImage(target, 0, 0);
72650
+ event.dataTransfer.effectAllowed = "move";
72651
+ }
72652
+ this.config.onDragStart?.({
72653
+ event,
72654
+ element: target,
72655
+ data
72656
+ });
72657
+ }
72658
+ /**
72659
+ * Handles the dragover event.
72660
+ * Provides visual feedback and determines if drop is allowed.
72661
+ */
72662
+ handleDragOver(event) {
72663
+ const hasFieldAnnotation = this.hasFieldAnnotationData(event);
72664
+ if (hasFieldAnnotation) {
72665
+ event.preventDefault();
72666
+ if (event.dataTransfer) {
72667
+ event.dataTransfer.dropEffect = "move";
72668
+ }
72669
+ this.container.classList.add("drag-over");
72670
+ }
72671
+ this.config.onDragOver?.({
72672
+ event,
72673
+ clientX: event.clientX,
72674
+ clientY: event.clientY,
72675
+ hasFieldAnnotation
72676
+ });
72677
+ }
72678
+ /**
72679
+ * Handles the dragleave event.
72680
+ * Removes visual feedback when drag leaves the container.
72681
+ */
72682
+ handleDragLeave(event) {
72683
+ const relatedTarget = event.relatedTarget;
72684
+ if (!relatedTarget || !this.container.contains(relatedTarget)) {
72685
+ this.container.classList.remove("drag-over");
72686
+ }
72687
+ }
72688
+ /**
72689
+ * Handles the drop event.
72690
+ * Maps drop coordinates to ProseMirror position and emits drop event.
72691
+ */
72692
+ handleDrop(event) {
72693
+ this.container.classList.remove("drag-over");
72694
+ if (!this.hasFieldAnnotationData(event)) {
72695
+ return;
72696
+ }
72697
+ event.preventDefault();
72698
+ const data = this.extractDragData(event);
72699
+ if (!data) {
72700
+ return;
72701
+ }
72702
+ const pmPosition = clickToPositionDom(this.container, event.clientX, event.clientY);
72703
+ this.config.onDrop?.({
72704
+ event,
72705
+ data,
72706
+ pmPosition,
72707
+ clientX: event.clientX,
72708
+ clientY: event.clientY
72709
+ });
72710
+ }
72711
+ /**
72712
+ * Handles the dragend event.
72713
+ * Cleans up drag state.
72714
+ */
72715
+ handleDragEnd(event) {
72716
+ this.container.classList.remove("drag-over");
72717
+ this.config.onDragEnd?.(event);
72718
+ }
72719
+ /**
72720
+ * Checks if a drag event contains field annotation data.
72721
+ */
72722
+ hasFieldAnnotationData(event) {
72723
+ if (!event.dataTransfer) {
72724
+ return false;
72725
+ }
72726
+ const types2 = event.dataTransfer.types;
72727
+ return types2.includes(this.mimeType) || types2.includes(LEGACY_MIME_TYPE);
72728
+ }
72729
+ /**
72730
+ * Extracts field annotation data from a drag event's dataTransfer.
72731
+ */
72732
+ extractDragData(event) {
72733
+ if (!event.dataTransfer) {
72734
+ return null;
72735
+ }
72736
+ let jsonData = event.dataTransfer.getData(this.mimeType);
72737
+ if (!jsonData) {
72738
+ jsonData = event.dataTransfer.getData(LEGACY_MIME_TYPE);
72739
+ }
72740
+ if (!jsonData) {
72741
+ return null;
72742
+ }
72743
+ try {
72744
+ const parsed = JSON.parse(jsonData);
72745
+ return parsed.sourceField ?? parsed.attributes ?? parsed;
72746
+ } catch {
72747
+ return null;
72748
+ }
72749
+ }
72750
+ /**
72751
+ * Updates the configuration options.
72752
+ *
72753
+ * @param config - New configuration options to merge
72754
+ */
72755
+ updateConfig(config2) {
72756
+ this.config = { ...this.config, ...config2 };
72757
+ if (config2.mimeType) {
72758
+ this.mimeType = config2.mimeType;
72759
+ }
72760
+ }
72761
+ /**
72762
+ * Destroys the drag handler and removes all event listeners.
72763
+ * Call this when the layout engine is unmounted or the container is removed.
72764
+ */
72765
+ destroy() {
72766
+ this.removeListeners();
72767
+ this.container.classList.remove("drag-over");
72768
+ }
72769
+ }
72770
+ function createDragHandler(container, config2 = {}) {
72771
+ const handler2 = new DragHandler(container, config2);
72772
+ return () => handler2.destroy();
72773
+ }
72364
72774
  const isAtomicFragment = (fragment) => {
72365
72775
  return fragment.kind === "drawing" || fragment.kind === "image";
72366
72776
  };
@@ -72899,7 +73309,7 @@ function computeLinePmRange$1(block, line) {
72899
73309
  for (let runIndex = line.fromRun; runIndex <= line.toRun; runIndex += 1) {
72900
73310
  const run2 = block.runs[runIndex];
72901
73311
  if (!run2) continue;
72902
- const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
73312
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
72903
73313
  const runLength = text.length;
72904
73314
  const runPmStart = run2.pmStart ?? null;
72905
73315
  const runPmEnd = run2.pmEnd ?? (runPmStart != null ? runPmStart + runLength : null);
@@ -72923,7 +73333,7 @@ function pmPosToCharOffset(block, line, pmPos) {
72923
73333
  for (let runIndex = line.fromRun; runIndex <= line.toRun; runIndex += 1) {
72924
73334
  const run2 = block.runs[runIndex];
72925
73335
  if (!run2) continue;
72926
- const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
73336
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
72927
73337
  const runTextLength = text.length;
72928
73338
  const runPmStart = run2.pmStart ?? null;
72929
73339
  const runPmEnd = run2.pmEnd ?? (runPmStart != null ? runPmStart + runTextLength : null);
@@ -75456,9 +75866,227 @@ const TRACK_CHANGE_STYLES = `
75456
75866
  border-bottom: 2px solid gold;
75457
75867
  }
75458
75868
  `;
75869
+ const SDT_CONTAINER_STYLES = `
75870
+ /* Document Section - Block-level container with gray border and hover tooltip */
75871
+ .superdoc-document-section {
75872
+ background-color: #fafafa;
75873
+ border: 1px solid #ababab;
75874
+ border-radius: 4px;
75875
+ position: relative;
75876
+ box-sizing: border-box;
75877
+ }
75878
+
75879
+ /* Document section tooltip - positioned above the fragment */
75880
+ .superdoc-document-section__tooltip {
75881
+ position: absolute;
75882
+ top: -19px;
75883
+ left: -1px;
75884
+ max-width: 100px;
75885
+ min-width: 0;
75886
+ height: 18px;
75887
+ border: 1px solid #ababab;
75888
+ border-bottom: none;
75889
+ border-radius: 6px 6px 0 0;
75890
+ padding: 0 8px;
75891
+ align-items: center;
75892
+ font-size: 10px;
75893
+ display: none;
75894
+ z-index: 100;
75895
+ background-color: #fafafa;
75896
+ pointer-events: none;
75897
+ }
75898
+
75899
+ .superdoc-document-section__tooltip span {
75900
+ max-width: 100%;
75901
+ overflow: hidden;
75902
+ white-space: nowrap;
75903
+ text-overflow: ellipsis;
75904
+ }
75905
+
75906
+ /* Show tooltip on hover - adjust border radius to connect with tooltip tab */
75907
+ .superdoc-document-section:hover {
75908
+ border-radius: 0 4px 4px 4px;
75909
+ }
75910
+
75911
+ .superdoc-document-section:hover .superdoc-document-section__tooltip {
75912
+ display: flex;
75913
+ align-items: center;
75914
+ }
75915
+
75916
+ /* Continuation styling: first fragment has top corners, last has bottom corners */
75917
+ .superdoc-document-section[data-sdt-container-start="true"] {
75918
+ border-radius: 4px 4px 0 0;
75919
+ }
75920
+
75921
+ .superdoc-document-section[data-sdt-container-end="true"] {
75922
+ border-radius: 0 0 4px 4px;
75923
+ }
75924
+
75925
+ .superdoc-document-section[data-sdt-container-start="true"][data-sdt-container-end="true"] {
75926
+ border-radius: 4px;
75927
+ }
75928
+
75929
+ .superdoc-document-section[data-sdt-container-start="true"]:hover {
75930
+ border-radius: 0 4px 0 0;
75931
+ }
75932
+
75933
+ /* Middle fragments have no border radius */
75934
+ .superdoc-document-section:not([data-sdt-container-start="true"]):not([data-sdt-container-end="true"]) {
75935
+ border-radius: 0;
75936
+ border-top: none;
75937
+ }
75938
+
75939
+ /* Structured Content Block - Blue border container */
75940
+ .superdoc-structured-content-block {
75941
+ padding: 1px;
75942
+ box-sizing: border-box;
75943
+ border-radius: 4px;
75944
+ border: 1px solid #629be7;
75945
+ position: relative;
75946
+ }
75947
+
75948
+ /* Structured content drag handle/label - positioned above */
75949
+ .superdoc-structured-content__label {
75950
+ font-size: 10px;
75951
+ align-items: center;
75952
+ justify-content: center;
75953
+ position: absolute;
75954
+ left: 2px;
75955
+ top: -19px;
75956
+ width: calc(100% - 4px);
75957
+ max-width: 110px;
75958
+ min-width: 0;
75959
+ height: 18px;
75960
+ padding: 0 4px;
75961
+ border: 1px solid #629be7;
75962
+ border-bottom: none;
75963
+ border-radius: 6px 6px 0 0;
75964
+ background-color: #629be7dd;
75965
+ box-sizing: border-box;
75966
+ z-index: 10;
75967
+ display: none;
75968
+ pointer-events: none;
75969
+ }
75970
+
75971
+ .superdoc-structured-content__label span {
75972
+ max-width: 100%;
75973
+ overflow: hidden;
75974
+ white-space: nowrap;
75975
+ text-overflow: ellipsis;
75976
+ }
75977
+
75978
+ .superdoc-structured-content-block:hover .superdoc-structured-content__label {
75979
+ display: inline-flex;
75980
+ }
75981
+
75982
+ /* Continuation styling for structured content blocks */
75983
+ .superdoc-structured-content-block[data-sdt-container-start="true"] {
75984
+ border-radius: 4px 4px 0 0;
75985
+ }
75986
+
75987
+ .superdoc-structured-content-block[data-sdt-container-end="true"] {
75988
+ border-radius: 0 0 4px 4px;
75989
+ }
75990
+
75991
+ .superdoc-structured-content-block[data-sdt-container-start="true"][data-sdt-container-end="true"] {
75992
+ border-radius: 4px;
75993
+ }
75994
+
75995
+ .superdoc-structured-content-block:not([data-sdt-container-start="true"]):not([data-sdt-container-end="true"]) {
75996
+ border-radius: 0;
75997
+ border-top: none;
75998
+ }
75999
+
76000
+ /* Structured Content Inline - Inline wrapper with blue border */
76001
+ .superdoc-structured-content-inline {
76002
+ padding: 1px;
76003
+ box-sizing: border-box;
76004
+ border-radius: 4px;
76005
+ border: 1px solid #629be7;
76006
+ position: relative;
76007
+ display: inline;
76008
+ }
76009
+
76010
+ /* Hover effect for inline structured content */
76011
+ .superdoc-structured-content-inline:hover {
76012
+ background-color: rgba(98, 155, 231, 0.15);
76013
+ border-color: #4a8ad9;
76014
+ }
76015
+
76016
+ /* Inline structured content label - shown on hover */
76017
+ .superdoc-structured-content-inline__label {
76018
+ position: absolute;
76019
+ bottom: calc(100% + 2px);
76020
+ left: 50%;
76021
+ transform: translateX(-50%);
76022
+ font-size: 10px;
76023
+ padding: 2px 6px;
76024
+ background-color: #629be7dd;
76025
+ color: white;
76026
+ border-radius: 4px;
76027
+ white-space: nowrap;
76028
+ z-index: 100;
76029
+ display: none;
76030
+ pointer-events: none;
76031
+ }
76032
+
76033
+ .superdoc-structured-content-inline:hover .superdoc-structured-content-inline__label {
76034
+ display: block;
76035
+ }
76036
+
76037
+ /* Print mode: hide visual styling for SDT containers */
76038
+ @media print {
76039
+ .superdoc-document-section,
76040
+ .superdoc-structured-content-block,
76041
+ .superdoc-structured-content-inline {
76042
+ background: none;
76043
+ border: none;
76044
+ padding: 0;
76045
+ }
76046
+
76047
+ .superdoc-document-section__tooltip,
76048
+ .superdoc-structured-content__label,
76049
+ .superdoc-structured-content-inline__label {
76050
+ display: none !important;
76051
+ }
76052
+ }
76053
+ `;
76054
+ const FIELD_ANNOTATION_STYLES = `
76055
+ /* Field annotation draggable styles */
76056
+ .superdoc-layout .annotation[data-draggable="true"] {
76057
+ cursor: grab;
76058
+ user-select: none;
76059
+ -webkit-user-select: none;
76060
+ }
76061
+
76062
+ .superdoc-layout .annotation[data-draggable="true"]:hover {
76063
+ opacity: 0.9;
76064
+ }
76065
+
76066
+ .superdoc-layout .annotation[data-draggable="true"]:active {
76067
+ cursor: grabbing;
76068
+ }
76069
+
76070
+ /* Drag over indicator for drop targets */
76071
+ .superdoc-layout.drag-over {
76072
+ outline: 2px dashed #b015b3;
76073
+ outline-offset: -2px;
76074
+ }
76075
+
76076
+ /* Drop zone indicator */
76077
+ .superdoc-layout .superdoc-drop-indicator {
76078
+ position: absolute;
76079
+ width: 2px;
76080
+ background-color: #b015b3;
76081
+ pointer-events: none;
76082
+ z-index: 1000;
76083
+ }
76084
+ `;
75459
76085
  let printStylesInjected = false;
75460
76086
  let linkStylesInjected = false;
75461
76087
  let trackChangeStylesInjected = false;
76088
+ let sdtContainerStylesInjected = false;
76089
+ let fieldAnnotationStylesInjected = false;
75462
76090
  const ensurePrintStyles = (doc2) => {
75463
76091
  if (printStylesInjected || !doc2) return;
75464
76092
  const styleEl = doc2.createElement("style");
@@ -75483,6 +76111,22 @@ const ensureTrackChangeStyles = (doc2) => {
75483
76111
  doc2.head?.appendChild(styleEl);
75484
76112
  trackChangeStylesInjected = true;
75485
76113
  };
76114
+ const ensureSdtContainerStyles = (doc2) => {
76115
+ if (sdtContainerStylesInjected || !doc2) return;
76116
+ const styleEl = doc2.createElement("style");
76117
+ styleEl.setAttribute("data-superdoc-sdt-container-styles", "true");
76118
+ styleEl.textContent = SDT_CONTAINER_STYLES;
76119
+ doc2.head?.appendChild(styleEl);
76120
+ sdtContainerStylesInjected = true;
76121
+ };
76122
+ const ensureFieldAnnotationStyles = (doc2) => {
76123
+ if (fieldAnnotationStylesInjected || !doc2) return;
76124
+ const styleEl = doc2.createElement("style");
76125
+ styleEl.setAttribute("data-superdoc-field-annotation-styles", "true");
76126
+ styleEl.textContent = FIELD_ANNOTATION_STYLES;
76127
+ doc2.head?.appendChild(styleEl);
76128
+ fieldAnnotationStylesInjected = true;
76129
+ };
75486
76130
  const ALLOWED_BORDER_STYLES = /* @__PURE__ */ new Set([
75487
76131
  "none",
75488
76132
  "single",
@@ -75812,6 +76456,50 @@ const renderTableRow = (deps) => {
75812
76456
  container.appendChild(cellElement);
75813
76457
  }
75814
76458
  };
76459
+ function isStructuredContentMetadata(sdt) {
76460
+ return sdt !== null && sdt !== void 0 && typeof sdt === "object" && "type" in sdt && sdt.type === "structuredContent";
76461
+ }
76462
+ function isDocumentSectionMetadata(sdt) {
76463
+ return sdt !== null && sdt !== void 0 && typeof sdt === "object" && "type" in sdt && sdt.type === "documentSection";
76464
+ }
76465
+ function getSdtContainerConfig(sdt) {
76466
+ if (isDocumentSectionMetadata(sdt)) {
76467
+ return {
76468
+ className: "superdoc-document-section",
76469
+ labelText: sdt.title ?? "Document section",
76470
+ labelClassName: "superdoc-document-section__tooltip",
76471
+ isStart: true,
76472
+ isEnd: true
76473
+ };
76474
+ }
76475
+ if (isStructuredContentMetadata(sdt) && sdt.scope === "block") {
76476
+ return {
76477
+ className: "superdoc-structured-content-block",
76478
+ labelText: sdt.alias ?? "Structured content",
76479
+ labelClassName: "superdoc-structured-content__label",
76480
+ isStart: true,
76481
+ isEnd: true
76482
+ };
76483
+ }
76484
+ return null;
76485
+ }
76486
+ function applySdtContainerStyling(doc2, container, sdt, containerSdt) {
76487
+ let config2 = getSdtContainerConfig(sdt);
76488
+ if (!config2 && containerSdt) {
76489
+ config2 = getSdtContainerConfig(containerSdt);
76490
+ }
76491
+ if (!config2) return;
76492
+ container.classList.add(config2.className);
76493
+ container.dataset.sdtContainerStart = String(config2.isStart);
76494
+ container.dataset.sdtContainerEnd = String(config2.isEnd);
76495
+ container.style.overflow = "visible";
76496
+ const labelEl = doc2.createElement("div");
76497
+ labelEl.className = config2.labelClassName;
76498
+ const labelText = doc2.createElement("span");
76499
+ labelText.textContent = config2.labelText;
76500
+ labelEl.appendChild(labelText);
76501
+ container.appendChild(labelEl);
76502
+ }
75815
76503
  const renderTableFragment = (deps) => {
75816
76504
  const { doc: doc2, fragment, blockLookup, context, renderLine, applyFragmentFrame, applySdtDataset, applyStyles: applyStyles2 } = deps;
75817
76505
  if (!doc2) {
@@ -75848,6 +76536,7 @@ const renderTableFragment = (deps) => {
75848
76536
  applyFragmentFrame(container, fragment);
75849
76537
  container.style.height = `${fragment.height}px`;
75850
76538
  applySdtDataset(container, block.attrs?.sdt);
76539
+ applySdtContainerStyling(doc2, container, block.attrs?.sdt);
75851
76540
  container.classList.add("superdoc-table-fragment");
75852
76541
  if (fragment.metadata?.columnBoundaries) {
75853
76542
  const columnCount = measure.columnWidths.length;
@@ -76314,6 +77003,8 @@ const _DomPainter = class _DomPainter2 {
76314
77003
  ensurePrintStyles(doc2);
76315
77004
  ensureLinkStyles(doc2);
76316
77005
  ensureTrackChangeStyles(doc2);
77006
+ ensureFieldAnnotationStyles(doc2);
77007
+ ensureSdtContainerStyles(doc2);
76317
77008
  mount2.classList.add(CLASS_NAMES.container);
76318
77009
  if (this.mount && this.mount !== mount2) {
76319
77010
  this.resetState();
@@ -76836,7 +77527,8 @@ const _DomPainter = class _DomPainter2 {
76836
77527
  fragmentEl.classList.add(CLASS_NAMES.fragment);
76837
77528
  const isTocEntry = block.attrs?.isTocEntry;
76838
77529
  const hasMarker = !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker;
76839
- const styles = isTocEntry ? { ...fragmentStyles, whiteSpace: "nowrap" } : hasMarker ? { ...fragmentStyles, overflow: "visible" } : fragmentStyles;
77530
+ const hasSdtContainer = block.attrs?.sdt?.type === "documentSection" || block.attrs?.sdt?.type === "structuredContent" || block.attrs?.containerSdt?.type === "documentSection" || block.attrs?.containerSdt?.type === "structuredContent";
77531
+ const styles = isTocEntry ? { ...fragmentStyles, whiteSpace: "nowrap" } : hasMarker || hasSdtContainer ? { ...fragmentStyles, overflow: "visible" } : fragmentStyles;
76840
77532
  applyStyles$2(fragmentEl, styles);
76841
77533
  this.applyFragmentFrame(fragmentEl, fragment, context.section);
76842
77534
  if (isTocEntry) {
@@ -76856,6 +77548,7 @@ const _DomPainter = class _DomPainter2 {
76856
77548
  }
76857
77549
  this.applySdtDataset(fragmentEl, block.attrs?.sdt);
76858
77550
  this.applyContainerSdtDataset(fragmentEl, block.attrs?.containerSdt);
77551
+ applySdtContainerStyling(this.doc, fragmentEl, block.attrs?.sdt, block.attrs?.containerSdt);
76859
77552
  const dropCapDescriptor = block.attrs?.dropCapDescriptor;
76860
77553
  const dropCapMeasure = measure.dropCap;
76861
77554
  if (dropCapDescriptor && dropCapMeasure && !fragment.continuesFromPrev) {
@@ -77074,6 +77767,7 @@ const _DomPainter = class _DomPainter2 {
77074
77767
  fragmentEl.dataset.itemId = fragment.itemId;
77075
77768
  const paragraphMetadata = item.paragraph.attrs?.sdt;
77076
77769
  this.applySdtDataset(fragmentEl, paragraphMetadata);
77770
+ applySdtContainerStyling(this.doc, fragmentEl, paragraphMetadata, item.paragraph.attrs?.containerSdt);
77077
77771
  if (fragment.continuesFromPrev) {
77078
77772
  fragmentEl.dataset.continuesFromPrev = "true";
77079
77773
  }
@@ -77845,10 +78539,19 @@ const _DomPainter = class _DomPainter2 {
77845
78539
  isBreakRun(run2) {
77846
78540
  return run2.kind === "break";
77847
78541
  }
78542
+ /**
78543
+ * Type guard to check if a run is a field annotation run.
78544
+ */
78545
+ isFieldAnnotationRun(run2) {
78546
+ return run2.kind === "fieldAnnotation";
78547
+ }
77848
78548
  renderRun(run2, context, trackedConfig) {
77849
78549
  if (this.isImageRun(run2)) {
77850
78550
  return this.renderImageRun(run2);
77851
78551
  }
78552
+ if (this.isFieldAnnotationRun(run2)) {
78553
+ return this.renderFieldAnnotationRun(run2);
78554
+ }
77852
78555
  if (this.isLineBreakRun(run2)) {
77853
78556
  return null;
77854
78557
  }
@@ -77985,6 +78688,200 @@ const _DomPainter = class _DomPainter2 {
77985
78688
  }
77986
78689
  return img;
77987
78690
  }
78691
+ /**
78692
+ * Renders a FieldAnnotationRun as an inline "pill" element matching super-editor's visual appearance.
78693
+ *
78694
+ * Field annotations are styled inline elements that display form fields with:
78695
+ * - Outer span with border, border-radius, padding, and background color
78696
+ * - Inner span containing the displayLabel or type-specific content (image, link, etc.)
78697
+ *
78698
+ * @param run - The FieldAnnotationRun to render containing field configuration and styling
78699
+ * @returns HTMLElement (span) or null if document is not available
78700
+ *
78701
+ * @example
78702
+ * ```typescript
78703
+ * // Text variant
78704
+ * renderFieldAnnotationRun({ kind: 'fieldAnnotation', variant: 'text', displayLabel: 'Full Name', fieldColor: '#980043' })
78705
+ * // Returns: <span class="annotation" style="border: 2px solid #b015b3; ..."><span class="annotation-content">Full Name</span></span>
78706
+ *
78707
+ * // Image variant with imageSrc
78708
+ * renderFieldAnnotationRun({ kind: 'fieldAnnotation', variant: 'image', displayLabel: 'Photo', imageSrc: 'data:image/png;...' })
78709
+ * // Returns: <span class="annotation"><span class="annotation-content"><img src="..." /></span></span>
78710
+ *
78711
+ * // Link variant
78712
+ * renderFieldAnnotationRun({ kind: 'fieldAnnotation', variant: 'link', displayLabel: 'Website', linkUrl: 'https://example.com' })
78713
+ * // Returns: <span class="annotation"><span class="annotation-content"><a href="...">https://example.com</a></span></span>
78714
+ * ```
78715
+ */
78716
+ renderFieldAnnotationRun(run2) {
78717
+ if (!this.doc) {
78718
+ return null;
78719
+ }
78720
+ if (run2.hidden) {
78721
+ const hidden = this.doc.createElement("span");
78722
+ hidden.style.display = "none";
78723
+ if (run2.pmStart != null) hidden.dataset.pmStart = String(run2.pmStart);
78724
+ if (run2.pmEnd != null) hidden.dataset.pmEnd = String(run2.pmEnd);
78725
+ return hidden;
78726
+ }
78727
+ const defaultBorderColor = "#b015b3";
78728
+ const defaultFieldColor = "#980043";
78729
+ const annotation = this.doc.createElement("span");
78730
+ annotation.classList.add("annotation");
78731
+ annotation.setAttribute("aria-label", "Field annotation");
78732
+ const showHighlight = run2.highlighted !== false;
78733
+ if (showHighlight) {
78734
+ const borderColor = run2.borderColor || defaultBorderColor;
78735
+ annotation.style.border = `2px solid ${borderColor}`;
78736
+ annotation.style.borderRadius = "2px";
78737
+ annotation.style.padding = "1px 2px";
78738
+ annotation.style.boxSizing = "border-box";
78739
+ const fieldColor = run2.fieldColor || defaultFieldColor;
78740
+ const bgColor = fieldColor.length === 7 ? `${fieldColor}33` : fieldColor;
78741
+ if (run2.textHighlight) {
78742
+ annotation.style.backgroundColor = run2.textHighlight;
78743
+ } else {
78744
+ annotation.style.backgroundColor = bgColor;
78745
+ }
78746
+ }
78747
+ if (run2.visibility === "hidden") {
78748
+ annotation.style.visibility = "hidden";
78749
+ }
78750
+ if (run2.size) {
78751
+ if (run2.size.width) {
78752
+ annotation.style.width = `${run2.size.width}px`;
78753
+ annotation.style.display = "inline-block";
78754
+ annotation.style.overflow = "hidden";
78755
+ }
78756
+ if (run2.size.height) {
78757
+ annotation.style.height = `${run2.size.height}px`;
78758
+ }
78759
+ }
78760
+ if (run2.fontFamily) {
78761
+ annotation.style.fontFamily = run2.fontFamily;
78762
+ }
78763
+ if (run2.fontSize) {
78764
+ const fontSize2 = typeof run2.fontSize === "number" ? `${run2.fontSize}pt` : run2.fontSize;
78765
+ annotation.style.fontSize = fontSize2;
78766
+ }
78767
+ if (run2.textColor) {
78768
+ annotation.style.color = run2.textColor;
78769
+ }
78770
+ if (run2.bold) {
78771
+ annotation.style.fontWeight = "bold";
78772
+ }
78773
+ if (run2.italic) {
78774
+ annotation.style.fontStyle = "italic";
78775
+ }
78776
+ if (run2.underline) {
78777
+ annotation.style.textDecoration = "underline";
78778
+ }
78779
+ annotation.style.zIndex = "1";
78780
+ const content = this.doc.createElement("span");
78781
+ content.classList.add("annotation-content");
78782
+ content.style.pointerEvents = "none";
78783
+ content.setAttribute("contenteditable", "false");
78784
+ switch (run2.variant) {
78785
+ case "image":
78786
+ case "signature": {
78787
+ if (run2.imageSrc) {
78788
+ const img = this.doc.createElement("img");
78789
+ const isDataUrl = run2.imageSrc.startsWith("data:");
78790
+ if (isDataUrl) {
78791
+ if (run2.imageSrc.length <= MAX_DATA_URL_LENGTH && VALID_IMAGE_DATA_URL.test(run2.imageSrc)) {
78792
+ img.src = run2.imageSrc;
78793
+ } else {
78794
+ content.textContent = run2.displayLabel;
78795
+ break;
78796
+ }
78797
+ } else {
78798
+ const sanitized = sanitizeHref(run2.imageSrc);
78799
+ if (sanitized) {
78800
+ img.src = sanitized.href;
78801
+ } else {
78802
+ content.textContent = run2.displayLabel;
78803
+ break;
78804
+ }
78805
+ }
78806
+ img.alt = run2.displayLabel;
78807
+ img.style.height = "auto";
78808
+ img.style.maxWidth = "100%";
78809
+ img.style.pointerEvents = "none";
78810
+ img.style.verticalAlign = "middle";
78811
+ if (run2.variant === "signature") {
78812
+ img.style.maxHeight = "28px";
78813
+ }
78814
+ content.appendChild(img);
78815
+ annotation.style.display = "inline-block";
78816
+ content.style.display = "inline-block";
78817
+ } else {
78818
+ content.textContent = run2.displayLabel || (run2.variant === "signature" ? "Signature" : "");
78819
+ }
78820
+ break;
78821
+ }
78822
+ case "link": {
78823
+ if (run2.linkUrl) {
78824
+ const link = this.doc.createElement("a");
78825
+ const sanitized = sanitizeHref(run2.linkUrl);
78826
+ if (sanitized) {
78827
+ link.href = sanitized.href;
78828
+ link.target = "_blank";
78829
+ link.rel = "noopener noreferrer";
78830
+ link.textContent = run2.linkUrl;
78831
+ link.style.textDecoration = "none";
78832
+ content.style.pointerEvents = "all";
78833
+ content.appendChild(link);
78834
+ } else {
78835
+ content.textContent = run2.displayLabel;
78836
+ }
78837
+ } else {
78838
+ content.textContent = run2.displayLabel;
78839
+ }
78840
+ break;
78841
+ }
78842
+ case "html": {
78843
+ if (run2.rawHtml && typeof run2.rawHtml === "string") {
78844
+ content.textContent = run2.displayLabel;
78845
+ annotation.style.display = "inline-block";
78846
+ content.style.display = "inline-block";
78847
+ } else {
78848
+ content.textContent = run2.displayLabel;
78849
+ }
78850
+ break;
78851
+ }
78852
+ case "text":
78853
+ case "checkbox":
78854
+ default: {
78855
+ content.textContent = run2.displayLabel;
78856
+ break;
78857
+ }
78858
+ }
78859
+ annotation.appendChild(content);
78860
+ annotation.dataset.type = run2.variant;
78861
+ if (run2.fieldId) {
78862
+ annotation.dataset.fieldId = run2.fieldId;
78863
+ }
78864
+ if (run2.fieldType) {
78865
+ annotation.dataset.fieldType = run2.fieldType;
78866
+ }
78867
+ annotation.draggable = true;
78868
+ annotation.dataset.draggable = "true";
78869
+ if (run2.displayLabel) {
78870
+ annotation.dataset.displayLabel = run2.displayLabel;
78871
+ }
78872
+ if (run2.variant) {
78873
+ annotation.dataset.variant = run2.variant;
78874
+ }
78875
+ assertPmPositions(run2, "field annotation run");
78876
+ if (run2.pmStart != null) {
78877
+ annotation.dataset.pmStart = String(run2.pmStart);
78878
+ }
78879
+ if (run2.pmEnd != null) {
78880
+ annotation.dataset.pmEnd = String(run2.pmEnd);
78881
+ }
78882
+ this.applySdtDataset(annotation, run2.sdt);
78883
+ return annotation;
78884
+ }
77988
78885
  /**
77989
78886
  * Renders a single line of a paragraph block.
77990
78887
  *
@@ -78162,6 +79059,22 @@ const _DomPainter = class _DomPainter2 {
78162
79059
  if (this.isBreakRun(baseRun)) {
78163
79060
  continue;
78164
79061
  }
79062
+ if (this.isFieldAnnotationRun(baseRun)) {
79063
+ const elem = this.renderRun(baseRun, context, trackedConfig);
79064
+ if (elem) {
79065
+ if (styleId) {
79066
+ elem.setAttribute("styleid", styleId);
79067
+ }
79068
+ const runSegments2 = segmentsByRun.get(runIndex);
79069
+ const segX = runSegments2 && runSegments2[0]?.x !== void 0 ? runSegments2[0].x : cumulativeX;
79070
+ const segWidth = (runSegments2 && runSegments2[0]?.width !== void 0 ? runSegments2[0].width : 0) ?? 0;
79071
+ elem.style.position = "absolute";
79072
+ elem.style.left = `${segX}px`;
79073
+ el.appendChild(elem);
79074
+ cumulativeX = segX + segWidth;
79075
+ }
79076
+ continue;
79077
+ }
78165
79078
  const runSegments = segmentsByRun.get(runIndex);
78166
79079
  if (!runSegments || runSegments.length === 0) {
78167
79080
  continue;
@@ -78207,7 +79120,22 @@ const _DomPainter = class _DomPainter2 {
78207
79120
  });
78208
79121
  }
78209
79122
  } else {
79123
+ let currentInlineSdtWrapper = null;
79124
+ let currentInlineSdtId = null;
79125
+ const closeCurrentWrapper = () => {
79126
+ if (currentInlineSdtWrapper) {
79127
+ el.appendChild(currentInlineSdtWrapper);
79128
+ currentInlineSdtWrapper = null;
79129
+ currentInlineSdtId = null;
79130
+ }
79131
+ };
78210
79132
  runsForLine.forEach((run2) => {
79133
+ const runSdt = run2.sdt;
79134
+ const isInlineSdt = runSdt?.type === "structuredContent" && runSdt?.scope === "inline";
79135
+ const runSdtId = isInlineSdt && runSdt?.id ? String(runSdt.id) : null;
79136
+ if (runSdtId !== currentInlineSdtId) {
79137
+ closeCurrentWrapper();
79138
+ }
78211
79139
  if (run2.kind === "tab") {
78212
79140
  const tabEl = this.doc.createElement("span");
78213
79141
  tabEl.classList.add("superdoc-tab");
@@ -78235,9 +79163,37 @@ const _DomPainter = class _DomPainter2 {
78235
79163
  if (styleId) {
78236
79164
  elem.setAttribute("styleid", styleId);
78237
79165
  }
78238
- el.appendChild(elem);
79166
+ if (isInlineSdt && runSdtId && this.doc) {
79167
+ if (!currentInlineSdtWrapper) {
79168
+ currentInlineSdtWrapper = this.doc.createElement("span");
79169
+ currentInlineSdtWrapper.className = "superdoc-structured-content-inline";
79170
+ currentInlineSdtId = runSdtId;
79171
+ this.applySdtDataset(currentInlineSdtWrapper, runSdt);
79172
+ const alias = runSdt?.alias || "Inline content";
79173
+ const labelEl = this.doc.createElement("span");
79174
+ labelEl.className = "superdoc-structured-content-inline__label";
79175
+ labelEl.textContent = alias;
79176
+ currentInlineSdtWrapper.appendChild(labelEl);
79177
+ }
79178
+ const wrapperPmStart = currentInlineSdtWrapper.dataset.pmStart;
79179
+ const wrapperPmEnd = currentInlineSdtWrapper.dataset.pmEnd;
79180
+ if (run2.pmStart != null) {
79181
+ if (!wrapperPmStart || run2.pmStart < parseInt(wrapperPmStart, 10)) {
79182
+ currentInlineSdtWrapper.dataset.pmStart = String(run2.pmStart);
79183
+ }
79184
+ }
79185
+ if (run2.pmEnd != null) {
79186
+ if (!wrapperPmEnd || run2.pmEnd > parseInt(wrapperPmEnd, 10)) {
79187
+ currentInlineSdtWrapper.dataset.pmEnd = String(run2.pmEnd);
79188
+ }
79189
+ }
79190
+ currentInlineSdtWrapper.appendChild(elem);
79191
+ } else {
79192
+ el.appendChild(elem);
79193
+ }
78239
79194
  }
78240
79195
  });
79196
+ closeCurrentWrapper();
78241
79197
  }
78242
79198
  const anchors = el.querySelectorAll("a[href]");
78243
79199
  anchors.forEach((anchor) => {
@@ -78745,7 +79701,7 @@ const deriveBlockVersion = (block) => {
78745
79701
  return block.id;
78746
79702
  };
78747
79703
  const applyRunStyles = (element, run2, _isLink = false) => {
78748
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break") {
79704
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation") {
78749
79705
  return;
78750
79706
  }
78751
79707
  element.style.fontFamily = run2.fontFamily;
@@ -78905,6 +79861,10 @@ const sliceRunsForLine = (block, line) => {
78905
79861
  result.push(run2);
78906
79862
  continue;
78907
79863
  }
79864
+ if (run2.kind === "fieldAnnotation") {
79865
+ result.push(run2);
79866
+ continue;
79867
+ }
78908
79868
  if (!("text" in run2)) {
78909
79869
  continue;
78910
79870
  }
@@ -79220,6 +80180,10 @@ const DEFAULT_TAB_INTERVAL_PX = twipsToPx(DEFAULT_TAB_INTERVAL_TWIPS);
79220
80180
  const TAB_EPSILON = 0.1;
79221
80181
  const DEFAULT_DECIMAL_SEPARATOR = ".";
79222
80182
  const ALLOWED_TAB_VALS = /* @__PURE__ */ new Set(["start", "center", "end", "decimal", "bar", "clear"]);
80183
+ const FIELD_ANNOTATION_PILL_PADDING = 8;
80184
+ const FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2;
80185
+ const FIELD_ANNOTATION_VERTICAL_PADDING = 6;
80186
+ const DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16;
79223
80187
  const roundValue = (value) => value;
79224
80188
  function getCanvasContext() {
79225
80189
  if (!canvasContext) {
@@ -79299,6 +80263,9 @@ function isImageRun(run2) {
79299
80263
  function isLineBreakRun(run2) {
79300
80264
  return run2.kind === "lineBreak";
79301
80265
  }
80266
+ function isFieldAnnotationRun(run2) {
80267
+ return run2.kind === "fieldAnnotation";
80268
+ }
79302
80269
  async function measureBlock(block, constraints) {
79303
80270
  const normalized = normalizeConstraints(constraints);
79304
80271
  if (block.kind === "drawing") {
@@ -79665,6 +80632,92 @@ async function measureParagraphBlock(block, maxWidth) {
79665
80632
  lastAppliedTabAlign = null;
79666
80633
  continue;
79667
80634
  }
80635
+ if (isFieldAnnotationRun(run2)) {
80636
+ const displayText = run2.displayLabel || "";
80637
+ const annotationFontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
80638
+ const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
80639
+ const fontWeight = run2.bold ? "bold" : "normal";
80640
+ const fontStyle = run2.italic ? "italic" : "normal";
80641
+ const annotationFont = `${fontStyle} ${fontWeight} ${annotationFontSize}px ${annotationFontFamily}`;
80642
+ ctx2.font = annotationFont;
80643
+ const textWidth = displayText ? ctx2.measureText(displayText).width : 0;
80644
+ const annotationWidth = textWidth + FIELD_ANNOTATION_PILL_PADDING;
80645
+ const annotationHeight = annotationFontSize * FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER + FIELD_ANNOTATION_VERTICAL_PADDING;
80646
+ let annotationStartX;
80647
+ if (pendingTabAlignment && currentLine) {
80648
+ annotationStartX = alignPendingTabForWidth(annotationWidth);
80649
+ }
80650
+ if (!currentLine) {
80651
+ currentLine = {
80652
+ fromRun: runIndex,
80653
+ fromChar: 0,
80654
+ toRun: runIndex,
80655
+ toChar: 1,
80656
+ // Field annotations are atomic units
80657
+ width: annotationWidth,
80658
+ maxFontSize: annotationHeight,
80659
+ maxWidth: getEffectiveWidth(initialAvailableWidth),
80660
+ segments: [
80661
+ {
80662
+ runIndex,
80663
+ fromChar: 0,
80664
+ toChar: 1,
80665
+ width: annotationWidth,
80666
+ ...annotationStartX !== void 0 ? { x: annotationStartX } : {}
80667
+ }
80668
+ ]
80669
+ };
80670
+ continue;
80671
+ }
80672
+ if (currentLine.width + annotationWidth > currentLine.maxWidth && currentLine.width > 0) {
80673
+ const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing, currentLine.maxFontInfo);
80674
+ const completedLine = {
80675
+ ...currentLine,
80676
+ ...metrics
80677
+ };
80678
+ addBarTabsToLine(completedLine);
80679
+ lines.push(completedLine);
80680
+ tabStopCursor = 0;
80681
+ pendingTabAlignment = null;
80682
+ lastAppliedTabAlign = null;
80683
+ currentLine = {
80684
+ fromRun: runIndex,
80685
+ fromChar: 0,
80686
+ toRun: runIndex,
80687
+ toChar: 1,
80688
+ width: annotationWidth,
80689
+ maxFontSize: annotationHeight,
80690
+ maxWidth: getEffectiveWidth(contentWidth),
80691
+ segments: [
80692
+ {
80693
+ runIndex,
80694
+ fromChar: 0,
80695
+ toChar: 1,
80696
+ width: annotationWidth
80697
+ }
80698
+ ]
80699
+ };
80700
+ } else {
80701
+ currentLine.toRun = runIndex;
80702
+ currentLine.toChar = 1;
80703
+ currentLine.width = roundValue(currentLine.width + annotationWidth);
80704
+ currentLine.maxFontSize = Math.max(currentLine.maxFontSize, annotationHeight);
80705
+ if (!currentLine.segments) currentLine.segments = [];
80706
+ currentLine.segments.push({
80707
+ runIndex,
80708
+ fromChar: 0,
80709
+ toChar: 1,
80710
+ width: annotationWidth,
80711
+ ...annotationStartX !== void 0 ? { x: annotationStartX } : {}
80712
+ });
80713
+ }
80714
+ const tabAlign = lastAppliedTabAlign;
80715
+ if (tabAlign && currentLine && tabAlign.val === "end") {
80716
+ currentLine.width = roundValue(tabAlign.target);
80717
+ }
80718
+ lastAppliedTabAlign = null;
80719
+ continue;
80720
+ }
79668
80721
  if (!("text" in run2) || !("fontSize" in run2)) {
79669
80722
  continue;
79670
80723
  }
@@ -81629,6 +82682,12 @@ function isInRegisteredSurface(event) {
81629
82682
  }
81630
82683
  return false;
81631
82684
  }
82685
+ function isValidFieldAnnotationAttributes(attrs) {
82686
+ if (!attrs || typeof attrs !== "object") return false;
82687
+ const a = attrs;
82688
+ return typeof a.fieldId === "string" && typeof a.fieldType === "string" && typeof a.displayLabel === "string" && typeof a.type === "string";
82689
+ }
82690
+ const FIELD_ANNOTATION_DATA_TYPE = "fieldAnnotation";
81632
82691
  const DEFAULT_PAGE_SIZE = { w: 612, h: 792 };
81633
82692
  const DEFAULT_MARGINS = { top: 72, right: 72, bottom: 72, left: 72 };
81634
82693
  const WORD_CHARACTER_REGEX = /[\p{L}\p{N}''_~-]/u;
@@ -81654,6 +82713,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81654
82713
  __privateAdd$1(this, _layoutOptions);
81655
82714
  __privateAdd$1(this, _layoutState, { blocks: [], measures: [], layout: null });
81656
82715
  __privateAdd$1(this, _domPainter, null);
82716
+ __privateAdd$1(this, _dragHandlerCleanup, null);
81657
82717
  __privateAdd$1(this, _layoutError, null);
81658
82718
  __privateAdd$1(this, _layoutErrorState, "healthy");
81659
82719
  __privateAdd$1(this, _errorBanner, null);
@@ -81712,8 +82772,12 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81712
82772
  if (event.button !== 0) {
81713
82773
  return;
81714
82774
  }
82775
+ const target = event.target;
82776
+ const isDraggableAnnotation = target?.closest?.('[data-draggable="true"]') != null;
81715
82777
  if (!__privateGet$1(this, _layoutState).layout) {
81716
- event.preventDefault();
82778
+ if (!isDraggableAnnotation) {
82779
+ event.preventDefault();
82780
+ }
81717
82781
  if (document.activeElement instanceof HTMLElement) {
81718
82782
  document.activeElement.blur();
81719
82783
  }
@@ -81722,10 +82786,10 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81722
82786
  return;
81723
82787
  }
81724
82788
  const validPos = __privateMethod$1(this, _PresentationEditor_instances, getFirstTextPosition_fn).call(this);
81725
- const doc22 = __privateGet$1(this, _editor3)?.state?.doc;
81726
- if (doc22) {
82789
+ const doc222 = __privateGet$1(this, _editor3)?.state?.doc;
82790
+ if (doc222) {
81727
82791
  try {
81728
- const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(doc22, validPos));
82792
+ const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(doc222, validPos));
81729
82793
  __privateGet$1(this, _editor3).view?.dispatch(tr);
81730
82794
  } catch (error) {
81731
82795
  if (process$1$1.env.NODE_ENV === "development") {
@@ -81761,7 +82825,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81761
82825
  if (headerFooterRegion) {
81762
82826
  return;
81763
82827
  }
81764
- const hit = clickToPosition(
82828
+ const rawHit = clickToPosition(
81765
82829
  __privateGet$1(this, _layoutState).layout,
81766
82830
  __privateGet$1(this, _layoutState).blocks,
81767
82831
  __privateGet$1(this, _layoutState).measures,
@@ -81770,7 +82834,11 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81770
82834
  event.clientX,
81771
82835
  event.clientY
81772
82836
  );
81773
- event.preventDefault();
82837
+ const doc22 = __privateGet$1(this, _editor3).state?.doc;
82838
+ const hit = rawHit && doc22 ? { ...rawHit, pos: Math.max(0, Math.min(rawHit.pos, doc22.content.size)) } : rawHit;
82839
+ if (!isDraggableAnnotation) {
82840
+ event.preventDefault();
82841
+ }
81774
82842
  if (!hit) {
81775
82843
  if (document.activeElement instanceof HTMLElement) {
81776
82844
  document.activeElement.blur();
@@ -81778,10 +82846,10 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81778
82846
  const editorDom2 = __privateGet$1(this, _editor3).view?.dom;
81779
82847
  if (editorDom2) {
81780
82848
  const validPos = __privateMethod$1(this, _PresentationEditor_instances, getFirstTextPosition_fn).call(this);
81781
- const doc22 = __privateGet$1(this, _editor3)?.state?.doc;
81782
- if (doc22) {
82849
+ const doc222 = __privateGet$1(this, _editor3)?.state?.doc;
82850
+ if (doc222) {
81783
82851
  try {
81784
- const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(doc22, validPos));
82852
+ const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(doc222, validPos));
81785
82853
  __privateGet$1(this, _editor3).view?.dispatch(tr);
81786
82854
  } catch (error) {
81787
82855
  if (process$1$1.env.NODE_ENV === "development") {
@@ -81802,9 +82870,9 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81802
82870
  hit.pos
81803
82871
  );
81804
82872
  if (fragmentHit && (fragmentHit.fragment.kind === "image" || fragmentHit.fragment.kind === "drawing")) {
81805
- const doc22 = __privateGet$1(this, _editor3).state.doc;
82873
+ const doc222 = __privateGet$1(this, _editor3).state.doc;
81806
82874
  try {
81807
- const tr = __privateGet$1(this, _editor3).state.tr.setSelection(NodeSelection.create(doc22, hit.pos));
82875
+ const tr = __privateGet$1(this, _editor3).state.tr.setSelection(NodeSelection.create(doc222, hit.pos));
81808
82876
  __privateGet$1(this, _editor3).view?.dispatch(tr);
81809
82877
  if (__privateGet$1(this, _lastSelectedImageBlockId) && __privateGet$1(this, _lastSelectedImageBlockId) !== fragmentHit.fragment.blockId) {
81810
82878
  this.emit("imageDeselected", { blockId: __privateGet$1(this, _lastSelectedImageBlockId) });
@@ -81895,8 +82963,8 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81895
82963
  }
81896
82964
  }
81897
82965
  if (!handledByDepth) {
81898
- const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(__privateGet$1(this, _editor3).state.doc, hit.pos));
81899
82966
  try {
82967
+ const tr = __privateGet$1(this, _editor3).state.tr.setSelection(TextSelection$1.create(__privateGet$1(this, _editor3).state.doc, hit.pos));
81900
82968
  __privateGet$1(this, _editor3).view?.dispatch(tr);
81901
82969
  } catch {
81902
82970
  }
@@ -81971,6 +83039,90 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
81971
83039
  }
81972
83040
  __privateSet(this, _isDragging, false);
81973
83041
  });
83042
+ __privateAdd$1(this, _handleDragOver, (event) => {
83043
+ const activeEditor = this.getActiveEditor();
83044
+ if (!activeEditor?.isEditable) {
83045
+ return;
83046
+ }
83047
+ event.preventDefault();
83048
+ if (event.dataTransfer) {
83049
+ event.dataTransfer.dropEffect = "copy";
83050
+ }
83051
+ const dt = event.dataTransfer;
83052
+ const hasFieldAnnotation = dt?.types?.includes(FIELD_ANNOTATION_DATA_TYPE) || Boolean(dt?.getData?.(FIELD_ANNOTATION_DATA_TYPE));
83053
+ if (!hasFieldAnnotation) {
83054
+ return;
83055
+ }
83056
+ const hit = this.hitTest(event.clientX, event.clientY);
83057
+ const doc22 = activeEditor.state?.doc;
83058
+ if (!hit || !doc22) {
83059
+ return;
83060
+ }
83061
+ const pos = Math.min(Math.max(hit.pos, 1), doc22.content.size);
83062
+ const currentSelection = activeEditor.state.selection;
83063
+ const isSameCursor = currentSelection instanceof TextSelection$1 && currentSelection.from === pos && currentSelection.to === pos;
83064
+ if (isSameCursor) {
83065
+ return;
83066
+ }
83067
+ try {
83068
+ const tr = activeEditor.state.tr.setSelection(TextSelection$1.create(doc22, pos)).setMeta("addToHistory", false);
83069
+ activeEditor.view?.dispatch(tr);
83070
+ __privateMethod$1(this, _PresentationEditor_instances, scheduleSelectionUpdate_fn).call(this);
83071
+ } catch (error) {
83072
+ if (process$1$1.env.NODE_ENV === "development") {
83073
+ console.debug("[PresentationEditor] Drag position update skipped:", error);
83074
+ }
83075
+ }
83076
+ });
83077
+ __privateAdd$1(this, _handleDrop, (event) => {
83078
+ const activeEditor = this.getActiveEditor();
83079
+ if (!activeEditor?.isEditable) {
83080
+ return;
83081
+ }
83082
+ if (event.dataTransfer?.types?.includes("application/x-field-annotation")) {
83083
+ return;
83084
+ }
83085
+ event.preventDefault();
83086
+ event.stopPropagation();
83087
+ const fieldAnnotationData = event.dataTransfer?.getData(FIELD_ANNOTATION_DATA_TYPE);
83088
+ if (!fieldAnnotationData) {
83089
+ return;
83090
+ }
83091
+ const hit = this.hitTest(event.clientX, event.clientY);
83092
+ const selection = activeEditor.state?.selection;
83093
+ const fallbackPos = selection?.from ?? activeEditor.state?.doc?.content.size ?? null;
83094
+ const pos = hit?.pos ?? fallbackPos;
83095
+ if (pos == null) {
83096
+ return;
83097
+ }
83098
+ let parsedData = null;
83099
+ try {
83100
+ parsedData = JSON.parse(fieldAnnotationData);
83101
+ } catch {
83102
+ return;
83103
+ }
83104
+ const { attributes, sourceField } = parsedData ?? {};
83105
+ activeEditor.emit?.("fieldAnnotationDropped", {
83106
+ sourceField,
83107
+ editor: activeEditor,
83108
+ coordinates: hit,
83109
+ pos
83110
+ });
83111
+ if (attributes && isValidFieldAnnotationAttributes(attributes)) {
83112
+ activeEditor.commands?.addFieldAnnotation?.(pos, attributes, true);
83113
+ const posAfter = Math.min(pos + 1, activeEditor.state?.doc?.content.size ?? pos + 1);
83114
+ const tr = activeEditor.state?.tr.setSelection(TextSelection$1.create(activeEditor.state.doc, posAfter));
83115
+ if (tr) {
83116
+ activeEditor.view?.dispatch(tr);
83117
+ }
83118
+ __privateMethod$1(this, _PresentationEditor_instances, scheduleSelectionUpdate_fn).call(this);
83119
+ }
83120
+ const editorDom = activeEditor.view?.dom;
83121
+ if (editorDom) {
83122
+ editorDom.focus();
83123
+ activeEditor.view?.focus();
83124
+ }
83125
+ });
81974
83126
  __privateAdd$1(this, _handleDoubleClick, (event) => {
81975
83127
  if (event.button !== 0) return;
81976
83128
  if (!__privateGet$1(this, _layoutState).layout) return;
@@ -82160,6 +83312,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
82160
83312
  __privateMethod$1(this, _PresentationEditor_instances, applyZoom_fn).call(this);
82161
83313
  __privateMethod$1(this, _PresentationEditor_instances, setupEditorListeners_fn).call(this);
82162
83314
  __privateMethod$1(this, _PresentationEditor_instances, setupPointerHandlers_fn).call(this);
83315
+ __privateMethod$1(this, _PresentationEditor_instances, setupDragHandlers_fn).call(this);
82163
83316
  __privateMethod$1(this, _PresentationEditor_instances, setupInputBridge_fn).call(this);
82164
83317
  __privateMethod$1(this, _PresentationEditor_instances, syncTrackedChangesPreferences_fn).call(this);
82165
83318
  if (options.documentId) {
@@ -82871,6 +84024,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
82871
84024
  * Safe to call during partial initialization.
82872
84025
  */
82873
84026
  destroy() {
84027
+ var _a2;
82874
84028
  if (__privateGet$1(this, _rafHandle) != null) {
82875
84029
  __privateMethod$1(this, _PresentationEditor_instances, safeCleanup_fn).call(this, () => {
82876
84030
  const win = __privateGet$1(this, _visibleHost)?.ownerDocument?.defaultView ?? window;
@@ -82892,6 +84046,8 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
82892
84046
  __privateGet$1(this, _viewportHost)?.removeEventListener("pointermove", __privateGet$1(this, _handlePointerMove));
82893
84047
  __privateGet$1(this, _viewportHost)?.removeEventListener("pointerup", __privateGet$1(this, _handlePointerUp));
82894
84048
  __privateGet$1(this, _viewportHost)?.removeEventListener("pointerleave", __privateGet$1(this, _handlePointerLeave));
84049
+ __privateGet$1(this, _viewportHost)?.removeEventListener("dragover", __privateGet$1(this, _handleDragOver));
84050
+ __privateGet$1(this, _viewportHost)?.removeEventListener("drop", __privateGet$1(this, _handleDrop));
82895
84051
  __privateGet$1(this, _visibleHost)?.removeEventListener("keydown", __privateGet$1(this, _handleKeyDown));
82896
84052
  __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
82897
84053
  __privateGet$1(this, _inputBridge)?.destroy();
@@ -82930,6 +84086,8 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
82930
84086
  __privateSet(this, _session, { mode: "body" });
82931
84087
  __privateSet(this, _activeHeaderFooterEditor, null);
82932
84088
  __privateSet(this, _domPainter, null);
84089
+ (_a2 = __privateGet$1(this, _dragHandlerCleanup)) == null ? void 0 : _a2.call(this);
84090
+ __privateSet(this, _dragHandlerCleanup, null);
82933
84091
  __privateGet$1(this, _selectionOverlay2)?.remove();
82934
84092
  __privateGet$1(this, _painterHost)?.remove();
82935
84093
  __privateGet$1(this, _hiddenHost)?.remove();
@@ -82957,6 +84115,7 @@ _hiddenHost = /* @__PURE__ */ new WeakMap();
82957
84115
  _layoutOptions = /* @__PURE__ */ new WeakMap();
82958
84116
  _layoutState = /* @__PURE__ */ new WeakMap();
82959
84117
  _domPainter = /* @__PURE__ */ new WeakMap();
84118
+ _dragHandlerCleanup = /* @__PURE__ */ new WeakMap();
82960
84119
  _layoutError = /* @__PURE__ */ new WeakMap();
82961
84120
  _layoutErrorState = /* @__PURE__ */ new WeakMap();
82962
84121
  _errorBanner = /* @__PURE__ */ new WeakMap();
@@ -83340,8 +84499,99 @@ setupPointerHandlers_fn = function() {
83340
84499
  __privateGet$1(this, _viewportHost).addEventListener("pointermove", __privateGet$1(this, _handlePointerMove));
83341
84500
  __privateGet$1(this, _viewportHost).addEventListener("pointerup", __privateGet$1(this, _handlePointerUp));
83342
84501
  __privateGet$1(this, _viewportHost).addEventListener("pointerleave", __privateGet$1(this, _handlePointerLeave));
84502
+ __privateGet$1(this, _viewportHost).addEventListener("dragover", __privateGet$1(this, _handleDragOver));
84503
+ __privateGet$1(this, _viewportHost).addEventListener("drop", __privateGet$1(this, _handleDrop));
83343
84504
  __privateGet$1(this, _visibleHost).addEventListener("keydown", __privateGet$1(this, _handleKeyDown));
83344
84505
  };
84506
+ setupDragHandlers_fn = function() {
84507
+ var _a2;
84508
+ (_a2 = __privateGet$1(this, _dragHandlerCleanup)) == null ? void 0 : _a2.call(this);
84509
+ __privateSet(this, _dragHandlerCleanup, null);
84510
+ __privateSet(this, _dragHandlerCleanup, createDragHandler(__privateGet$1(this, _painterHost), {
84511
+ onDragOver: (event) => {
84512
+ if (!event.hasFieldAnnotation || event.event.clientX === 0) {
84513
+ return;
84514
+ }
84515
+ const activeEditor = this.getActiveEditor();
84516
+ if (!activeEditor?.isEditable) {
84517
+ return;
84518
+ }
84519
+ const hit = this.hitTest(event.clientX, event.clientY);
84520
+ const doc2 = activeEditor.state?.doc;
84521
+ if (!hit || !doc2) {
84522
+ return;
84523
+ }
84524
+ const pos = Math.min(Math.max(hit.pos, 1), doc2.content.size);
84525
+ const currentSelection = activeEditor.state.selection;
84526
+ if (currentSelection instanceof TextSelection$1 && currentSelection.from === pos && currentSelection.to === pos) {
84527
+ return;
84528
+ }
84529
+ try {
84530
+ const tr = activeEditor.state.tr.setSelection(TextSelection$1.create(doc2, pos)).setMeta("addToHistory", false);
84531
+ activeEditor.view?.dispatch(tr);
84532
+ __privateMethod$1(this, _PresentationEditor_instances, scheduleSelectionUpdate_fn).call(this);
84533
+ } catch {
84534
+ }
84535
+ },
84536
+ onDrop: (event) => {
84537
+ event.event.preventDefault();
84538
+ event.event.stopPropagation();
84539
+ if (event.pmPosition === null) {
84540
+ return;
84541
+ }
84542
+ const activeEditor = this.getActiveEditor();
84543
+ const { state: state2, view } = activeEditor;
84544
+ if (!state2 || !view) {
84545
+ return;
84546
+ }
84547
+ const fieldId = event.data.fieldId;
84548
+ if (fieldId) {
84549
+ const targetPos = event.pmPosition;
84550
+ let sourceStart = null;
84551
+ let sourceEnd = null;
84552
+ let sourceNode = null;
84553
+ state2.doc.descendants((node, pos) => {
84554
+ if (node.type.name === "fieldAnnotation" && node.attrs.fieldId === fieldId) {
84555
+ sourceStart = pos;
84556
+ sourceEnd = pos + node.nodeSize;
84557
+ sourceNode = node;
84558
+ return false;
84559
+ }
84560
+ return true;
84561
+ });
84562
+ if (sourceStart === null || sourceEnd === null || !sourceNode) {
84563
+ return;
84564
+ }
84565
+ if (targetPos >= sourceStart && targetPos <= sourceEnd) {
84566
+ return;
84567
+ }
84568
+ const tr = state2.tr;
84569
+ tr.delete(sourceStart, sourceEnd);
84570
+ const mappedTarget = tr.mapping.map(targetPos);
84571
+ if (mappedTarget < 0 || mappedTarget > tr.doc.content.size) {
84572
+ return;
84573
+ }
84574
+ tr.insert(mappedTarget, sourceNode);
84575
+ tr.setMeta("uiEvent", "drop");
84576
+ view.dispatch(tr);
84577
+ return;
84578
+ }
84579
+ const attrs = event.data.attributes;
84580
+ if (attrs && isValidFieldAnnotationAttributes(attrs)) {
84581
+ const inserted = activeEditor.commands?.addFieldAnnotation?.(event.pmPosition, attrs, true);
84582
+ if (inserted) {
84583
+ __privateMethod$1(this, _PresentationEditor_instances, scheduleSelectionUpdate_fn).call(this);
84584
+ }
84585
+ return;
84586
+ }
84587
+ activeEditor.emit("fieldAnnotationDropped", {
84588
+ sourceField: event.data,
84589
+ editor: activeEditor,
84590
+ coordinates: { pos: event.pmPosition }
84591
+ });
84592
+ }
84593
+ }));
84594
+ };
83345
84595
  setupInputBridge_fn = function() {
83346
84596
  __privateGet$1(this, _inputBridge)?.destroy();
83347
84597
  const win = __privateGet$1(this, _visibleHost).ownerDocument?.defaultView ?? window;
@@ -83559,6 +84809,8 @@ isWordCharacter_fn = function(char) {
83559
84809
  _handlePointerMove = /* @__PURE__ */ new WeakMap();
83560
84810
  _handlePointerLeave = /* @__PURE__ */ new WeakMap();
83561
84811
  _handlePointerUp = /* @__PURE__ */ new WeakMap();
84812
+ _handleDragOver = /* @__PURE__ */ new WeakMap();
84813
+ _handleDrop = /* @__PURE__ */ new WeakMap();
83562
84814
  _handleDoubleClick = /* @__PURE__ */ new WeakMap();
83563
84815
  _handleKeyDown = /* @__PURE__ */ new WeakMap();
83564
84816
  focusHeaderFooterShortcut_fn = function(kind) {