drawui-core 0.5.1 → 0.5.2

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.
package/dist/index.d.cts CHANGED
@@ -567,6 +567,17 @@ declare function getTheme(): DrawuiTheme;
567
567
  declare function hexToRgba(hex: string, alpha: number): string;
568
568
  /** 颜色变暗/变亮:percent 负数变暗、正数变亮 */
569
569
  declare function shadeColor(hex: string, percent: number): string;
570
+ /** 页面主题(画布背景 + UI 色调),与 react 层 theme.less 的 data-theme 一一对应 */
571
+ type PageTheme = 'light' | 'warm' | 'gray' | 'purple' | 'green' | 'eye-care';
572
+ /** 页面主题在 core 层需要覆盖的颜色 */
573
+ interface PageThemePreset {
574
+ /** 网格线颜色 */
575
+ grid: string;
576
+ }
577
+ /** 页面主题预设:网格颜色随背景深浅调整,保证可见但不突兀 */
578
+ declare const PAGE_THEMES: Record<PageTheme, PageThemePreset>;
579
+ /** 默认页面主题 */
580
+ declare const DEFAULT_PAGE_THEME: PageTheme;
570
581
 
571
582
  /**
572
583
  * 国际化:框架无关的轻量字典 + 语言切换。
@@ -758,6 +769,10 @@ declare const zhCN: {
758
769
  readonly 'mindmap.expand': "展开";
759
770
  readonly 'mindmap.close': "关闭编辑";
760
771
  readonly 'mindmap.more': "更多设置";
772
+ readonly 'mindmap.level': "层级";
773
+ readonly 'mindmap.promote1': "升一级";
774
+ readonly 'mindmap.promote2': "升两级";
775
+ readonly 'mindmap.promoteDisabled': "已至顶层";
761
776
  readonly 'tool.table': "表格";
762
777
  readonly 'toolbar.table': "表格";
763
778
  readonly 'shape.table': "表格";
@@ -794,6 +809,14 @@ declare const zhCN: {
794
809
  readonly 'ctx.delete': "删除";
795
810
  readonly 'toolbar.icon': "图标";
796
811
  readonly 'toolbar.image': "图片";
812
+ readonly 'toolbar.more': "更多";
813
+ readonly 'toolbar.pageTheme': "页面主题";
814
+ readonly 'pageTheme.light': "默认";
815
+ readonly 'pageTheme.warm': "暖黄";
816
+ readonly 'pageTheme.gray': "浅灰";
817
+ readonly 'pageTheme.purple': "浅紫";
818
+ readonly 'pageTheme.green': "浅绿";
819
+ readonly 'pageTheme.eye-care': "护眼";
797
820
  readonly 'tool.image': "图片";
798
821
  readonly 'image.uploadFailed': "图片上传失败";
799
822
  readonly 'image.insertFailed': "图片插入失败";
@@ -947,6 +970,29 @@ declare function getMindMapNodeSiblings(root: MindMapNode, nodeId: string): {
947
970
  * newIndex 是相对于同 direction siblings 的索引。
948
971
  */
949
972
  declare function reorderMindMapNodeInTree(root: MindMapNode, nodeId: string, newIndex: number): MindMapNode;
973
+ /**
974
+ * 把节点「升级」levels 层:把 node 重新挂到它第 levels 层祖先之下,并紧挨着
975
+ * 它原来的直接祖先(即第 levels 层祖先的子节点)之后。
976
+ *
977
+ * - 升 1 层:node 成为「父节点的兄弟」(新父 = 祖父);
978
+ * - 升 2 层:node 成为「祖父节点的兄弟」(新父 = 曾祖父);
979
+ * - ……依此类推。
980
+ *
981
+ * 节点自身的子树(children)整体跟着一起上移,不会被拆散。
982
+ * 可行性由调用方判断:node 的 depth 必须 ≥ levels + 1(至少要有一个「新父」)。
983
+ * 不满足条件时原样返回 root(不改动)。
984
+ */
985
+ declare function promoteMindMapNodeInTree(root: MindMapNode, nodeId: string, levels: number): MindMapNode;
986
+ /**
987
+ * 把节点「转移」到另一个父节点下,落在同方向兄弟组的 insertIndex 处。
988
+ * 用于拖拽换层级:把节点拖到某个节点上 → 成为该节点的兄弟。
989
+ *
990
+ * - 子树整体跟随,不被拆散;
991
+ * - 目标父节点落在被移动节点自身子树内(或就是它自己)时,原样返回,避免把树拆坏;
992
+ * - 目标父节点是根节点时,把节点 direction 设为目标兄弟组的方向(否则会被分到错误方向组);
993
+ * 目标是普通节点时清掉显式 direction,改为跟随新父节点的方向。
994
+ */
995
+ declare function moveMindMapNodeInTree(root: MindMapNode, nodeId: string, targetParentId: string, direction: MindMapDirection, insertIndex: number): MindMapNode;
950
996
 
951
997
  type Listener$1 = () => void;
952
998
  type NotificationListener = (message: string) => void;
@@ -963,6 +1009,11 @@ type UiEvent = {
963
1009
  | {
964
1010
  kind: 'imageError';
965
1011
  message: string;
1012
+ }
1013
+ /** 正在拖拽/调整图形(移动/缩放/旋转/拖连线端点或线段/从锚点拉新连线):React 侧据此临时隐藏顶栏工具条 */
1014
+ | {
1015
+ kind: 'drag';
1016
+ active: boolean;
966
1017
  };
967
1018
  /** Editor 构造选项:主题色 / 语言 / 初始数据 / 本地持久化开关 */
968
1019
  interface EditorOptions {
@@ -997,6 +1048,8 @@ declare class Editor {
997
1048
  private isPanning;
998
1049
  private panStart;
999
1050
  private dragStartPositions;
1051
+ /** 是否正处于「拖拽/调整图形」交互中:通过 UiEvent 'drag' 通知 React 临时隐藏顶栏工具条 */
1052
+ private interactionDragging;
1000
1053
  private lastClickTime;
1001
1054
  private lastClickShapeId;
1002
1055
  private editingShapeId;
@@ -1031,6 +1084,13 @@ declare class Editor {
1031
1084
  * siblingIds 已按 cross 坐标排好序,方便 Renderer 直接画插入指示线。
1032
1085
  */
1033
1086
  private mindMapReorderTarget;
1087
+ /**
1088
+ * 拖拽「换层级」计划。两种落点:
1089
+ * - `sibling`:拖到目标节点的**外侧**(框外 48px 内)→ 成为该节点的同方向兄弟(targetParent = 目标节点的父节点);
1090
+ * - `child`:拖到目标节点的**框内** → 成为该节点的子节点(targetParent = 目标节点自身)。
1091
+ * 与 mindMapReorderTarget 的区别:那个是「同父级内重排序」,这个是「换父级(换层级)」。
1092
+ */
1093
+ private mindMapReparentPlan;
1034
1094
  private tableSelection;
1035
1095
  private tableEditing;
1036
1096
  private renderScheduled;
@@ -1198,6 +1258,8 @@ declare class Editor {
1198
1258
  connectToExisting(context: GenerationContext, targetShapeId: string, binding?: ArrowBinding): void;
1199
1259
  subscribeUi(listener: (payload: UiEvent) => void): () => boolean;
1200
1260
  private emitUi;
1261
+ /** 同步「是否正在拖拽图形」状态:仅在实际变化时发出 UiEvent,避免每帧轰炸订阅者 */
1262
+ private setInteractionDragging;
1201
1263
  /** 批量更新选中图形的样式(边框色、填充色等),提交历史记录 */
1202
1264
  updateSelectedShapesStyle(updates: Partial<ShapeStyle>): void;
1203
1265
  /** 批量更新选中图形的文字颜色/高亮背景色/高亮透明度,提交历史记录 */
@@ -1343,6 +1405,15 @@ declare class Editor {
1343
1405
  private pageToMindMapLocal;
1344
1406
  /** 计算拖拽节点时,在其同方向兄弟列表中的目标插入索引 */
1345
1407
  private calcMindMapReorderTarget;
1408
+ /**
1409
+ * 结构变化后补偿导图中心的位移,让**根节点在屏幕上不动**。
1410
+ *
1411
+ * 背景:`layoutMindMap` 末尾会把包围盒中心对齐到导图中心,所以树一变宽/变高,
1412
+ * 所有节点都会整体平移 —— 换层级/增删节点时看起来就是「整张图跳了一下」。
1413
+ * 这里按根节点在旧/新布局中的局部坐标差反向平移导图中心,于是只有受影响的
1414
+ * 子树重排,画面不会整体滑走(XMind 等也是这样,居中主题是视觉锚点)。
1415
+ */
1416
+ private anchorMindMapAtRoot;
1346
1417
  /** 获取选中的思维导图(恰好选中一个时) */
1347
1418
  getSelectedMindMap(): MindMapShape | null;
1348
1419
  /** 页面坐标下的思维导图节点命中:返回所在导图与节点 id */
@@ -1361,6 +1432,21 @@ declare class Editor {
1361
1432
  shapeId: string;
1362
1433
  nodeId: string;
1363
1434
  } | null;
1435
+ /**
1436
+ * 导图局部坐标下命中「某个节点框」的节点 id(拖拽换层级用)。
1437
+ * 排除 excludeNodeId 及其整棵子树 —— 否则会出现「把节点拖进自己的子树」这种非法落点。
1438
+ */
1439
+ private hitMindMapNodeBox;
1440
+ /**
1441
+ * 「成为子节点」落点:目标节点 targetId 的子节点组信息。
1442
+ * - `direction`:该组子节点的生长方向(目标非根 = 布局算出的目标方向;目标是根 = 取 cross 上离指针最近的方向组);
1443
+ * - `childIds`:已有的同方向子节点 id(为空表示新节点会成为第一个孩子)。
1444
+ */
1445
+ private mindMapChildGroup;
1446
+ /** 按 cross 坐标给同方向兄弟排序(Renderer 画落点占位框时要求同源顺序) */
1447
+ private mindMapSortByCross;
1448
+ /** 落点指示只在「真的变了」时更新(避免每帧 scheduleRender 抖动) */
1449
+ private setReorderIndicator;
1364
1450
  /** 光标语义命中:仅节点框(含「+」快捷按钮、折叠/展开标记)内才命中,节点间空档不命中 */
1365
1451
  getMindMapCursorHitAtPoint(point: Vec2): {
1366
1452
  shapeId: string;
@@ -1427,10 +1513,23 @@ declare class Editor {
1427
1513
  addMindMapSibling(shapeId: string, nodeId: string): void;
1428
1514
  /** 将节点在其同方向兄弟列表中移动到目标索引 */
1429
1515
  reorderMindMapNode(shapeId: string, nodeId: string, targetIndex: number): void;
1516
+ /**
1517
+ * 拖拽换层级:把节点移到目标父节点下、同方向兄弟组的 insertIndex 处。
1518
+ * 「拖到某个节点框上」= 成为该节点的同方向兄弟(即 targetParent = 该节点的父节点)。
1519
+ * 非法落点(目标是自己或自己的后代替)不修改文档。
1520
+ */
1521
+ moveMindMapNodeToParent(shapeId: string, nodeId: string, targetParentId: string, direction: MindMapDirection, insertIndex: number): void;
1430
1522
  /** 删除指定节点(含子树);删除根节点则移除整个思维导图 */
1431
1523
  deleteMindMapNode(shapeId: string, nodeId: string): void;
1432
1524
  /** 折叠/展开指定节点 */
1433
1525
  toggleMindMapCollapse(shapeId: string, nodeId: string): void;
1526
+ /** 节点能否「升级」levels 层:depth 必须 ≥ levels + 1(至少得有个新父节点)。根节点不可升级。 */
1527
+ canPromoteMindMapNode(shapeId: string, nodeId: string, levels: number): boolean;
1528
+ /**
1529
+ * 把节点升级 levels 层(升 1 层 = 成为父节点的兄弟;升 2 层 = 成为祖父节点的兄弟)。
1530
+ * 节点自身子树整体上移,不被拆散。不可升级时(已到顶层)直接返回,不改动文档。
1531
+ */
1532
+ promoteMindMapNode(shapeId: string, nodeId: string, levels: number): void;
1434
1533
  /** 获取选中的表格(恰好选中一个时) */
1435
1534
  getSelectedTable(): TableShape | null;
1436
1535
  private getTableById;
@@ -1823,6 +1922,8 @@ declare class Renderer {
1823
1922
  targetIndex: number;
1824
1923
  direction: MindMapDirection;
1825
1924
  siblingIds: string[];
1925
+ /** 「成为子节点」模式:目标节点 id(高亮它 + 子组为空时定位占位框) */
1926
+ childParentId?: string;
1826
1927
  } | null,
1827
1928
  /** 导出用:非 null 时先以该颜色铺满整块画布(白底等),默认不铺(透明) */
1828
1929
  background?: string | null,
@@ -2416,6 +2517,11 @@ declare abstract class Tool {
2416
2517
  * @returns 是否确实清理了状态(false = 本来就是空闲态,调用方可跳过重绘)
2417
2518
  */
2418
2519
  cancelTransient(): boolean;
2520
+ /**
2521
+ * 是否正处于「拖拽/调整图形」中(移动/缩放/旋转图形、拖连线端点或线段、从锚点拉新连线)。
2522
+ * 默认 false;选择工具等会覆盖,供编辑器据此临时隐藏顶栏工具条。
2523
+ */
2524
+ isDragging(): boolean;
2419
2525
  dispose(): void;
2420
2526
  }
2421
2527
 
@@ -2510,6 +2616,11 @@ declare class SelectTool extends Tool {
2510
2616
  */
2511
2617
  private finishSegmentDrag;
2512
2618
  hasTransientState(): boolean;
2619
+ /**
2620
+ * 拖拽/调整图形中:移动、缩放、旋转、拖连线端点、拖线段、从锚点拉新连线。
2621
+ * (框选空白、表格内框选单元格不算「拖图形」,不触发顶栏隐藏。)
2622
+ */
2623
+ isDragging(): boolean;
2513
2624
  /**
2514
2625
  * 取消一切瞬态交互(拖拽/生成/框选/旋转/连线端点拖拽)并清掉画布上的瞬态预览。
2515
2626
  * 触发场景:指针在窗口外松手丢失 pointerup、窗口失焦、点击画布外、无按压的移动、
@@ -2987,4 +3098,4 @@ declare function imageDataUrl(src: string): string | null;
2987
3098
  /** 清空缓存(测试/卸载时用;会释放自己创建的 blob 地址) */
2988
3099
  declare function clearImageCache(): void;
2989
3100
 
2990
- export { type ArrowBinding, type ArrowHeadType, type ArrowShape, type ArrowStyle, ArrowTool, BoardExtentKeeper, type BoardExtentResult, type BoardExtentUpdate, Camera, type CameraState, type CircleShape, type ConnectionType, DEFAULT_HIGHLIGHTER_COLOR, DEFAULT_IMAGE_MAX_SIZE_BYTES, type DiamondShape, type DrawShape, type DrawuiTheme, type DrawuiThemeSelection, Editor, type EditorData, type EditorOptions, type EditorState, type EllipseShape, type ExportFormat, type ExportOptions, type FreehandMode, FreehandTool, type GenerationContext, HandTool, type HexagonShape, ICONS, ICON_CATEGORIES, ICON_CATEGORY_INK, ICON_DEFAULT_INK, ICON_DEFAULT_SIZE, ICON_GRID, type IconCategoryId, type IconDef, type IconLayer, type IconShape, type ImageShape, type ImageUploadConfig, type ImageUploadOption, type ImageUploader, LANGUAGES, type Language, type LineShape, LineTool, MINDMAP_COLORS, MINDMAP_DIRECTIONS, MINDMAP_FONT_SIZE, MINDMAP_HANDLE_HIT_RADIUS, MINDMAP_HANDLE_RADIUS, MINDMAP_MAX_WIDTH, MINDMAP_MIN_WIDTH, MINDMAP_NODE_HEIGHT, MIN_HANDLE_SEGMENT, MIN_JOG, Mat2d, type MessageKey, type MindMapDirection, type MindMapHandleKind, type MindMapHandlePos, type MindMapLayoutResult, type MindMapNode, type MindMapNodePos, type MindMapShape, type OctagonShape, type ParallelogramShape, type PentagonShape, type Rect, type RectangleShape, Renderer, type RoundedRectangleShape, STICKY_FOLD_RATIO, STICKY_NOTE_COLORS, STICKY_NOTE_DEFAULT_COLOR, STICKY_TEXT_SCALE, type SegmentHandle, SelectTool, type Shape, type ShapeStyle, ShapeTool, type ShapeType, type SnapGuide, type StarShape, type StickyNoteShape, TABLE_CELL_PADDING_X, TABLE_CELL_PADDING_Y, TABLE_DEFAULT_COL_WIDTH, TABLE_DEFAULT_ROW_HEIGHT, TABLE_FONT_SIZE, TABLE_HEADER_FILL, TABLE_LINE_HEIGHT_RATIO, TABLE_MAX_AUTO_LINES, TABLE_MIN_COL_WIDTH, TABLE_MIN_ROW_HEIGHT, TABLE_MOVE_HANDLE_GAP, TABLE_MOVE_HANDLE_HEIGHT, TABLE_MOVE_HANDLE_WIDTH, THEME, type TableCell, type TableShape, type TextShape, type ToolType, type TrapezoidShape, type TriangleShape, UML_FONT_SIZE, UML_HEADER_HEIGHT, UML_LINE_HEIGHT, UML_MIN_WIDTH, UML_PADDING_X, UML_PADDING_Y, type UiEvent, type UmlAttribute, type UmlClassShape, type UmlInterfaceShape, type UmlMethod, type UmlVisibility, Vec, type Vec2 as Vec2Type, addImageReadyListener, calcUmlClassSize, clearImageCache, cloneMindMapNode, cloneTable, cloneTableCells, collapseRoute, collectTemporaryImageSrcs, connectorSegmentHandles, countMindMapNodes, createTableCells, downloadBlob, effectiveDirection, ensureImagesLoaded, exportToBlob, findMindMapNode, getContentBounds, getIcon, getLanguage, getMindMapNodeDepth, getMindMapNodeSiblings, getMindMapParent, getTheme, hasIcon, hexToRgba, hitTableBody, hitTableMoveHandle, iconInk, iconsByCategory, imageDataUrl, isEmptyRect, isFlippableShapeType, isHorizontalDirection, isImageFailed, isImageLoading, isStubCorner, isUploaderFunction, layoutMindMap, loadImage, mindMapHandleAtLocalPoint, mindMapNodeColor, mindMapNodeHandles, mindMapNodeSize, offsetConnectorSegment, parseUploadResponse, peekImage, pickSegmentHandle, pointToSegmentDistance, pruneStubBends, rectsIntersect, renderSVGString, renderToCanvas, reorderMindMapNodeInTree, routeToUserPoints, sameRoute, searchIcons, setImageCrossOrigin, setLanguage, setTheme, shadeColor, subscribeLanguage, subscribeTheme, subtractUnion, t, tableAnchorAt, tableCellAtLocalClamped, tableCellLineCount, tableCellLocalRect, tableCellTextStartOffset, tableCoveredMap, tableDeleteColumn, tableDeleteRow, tableExpandRangeToMerges, tableGrowRowHeights, tableInsertColumn, tableInsertRow, tableLocalPoint, tableMerge, tableMoveHandleLocalRect, tablePagePoint, tableRangeHasMerge, tableRangeLocalRect, tableRowAtPoint, tableSplit, tableSplitRange, tableTotalHeight, tableTotalWidth, umlAttrRowText, umlMethodRowText, unionRect, uploadImageViaConfig };
3101
+ export { type ArrowBinding, type ArrowHeadType, type ArrowShape, type ArrowStyle, ArrowTool, BoardExtentKeeper, type BoardExtentResult, type BoardExtentUpdate, Camera, type CameraState, type CircleShape, type ConnectionType, DEFAULT_HIGHLIGHTER_COLOR, DEFAULT_IMAGE_MAX_SIZE_BYTES, DEFAULT_PAGE_THEME, type DiamondShape, type DrawShape, type DrawuiTheme, type DrawuiThemeSelection, Editor, type EditorData, type EditorOptions, type EditorState, type EllipseShape, type ExportFormat, type ExportOptions, type FreehandMode, FreehandTool, type GenerationContext, HandTool, type HexagonShape, ICONS, ICON_CATEGORIES, ICON_CATEGORY_INK, ICON_DEFAULT_INK, ICON_DEFAULT_SIZE, ICON_GRID, type IconCategoryId, type IconDef, type IconLayer, type IconShape, type ImageShape, type ImageUploadConfig, type ImageUploadOption, type ImageUploader, LANGUAGES, type Language, type LineShape, LineTool, MINDMAP_COLORS, MINDMAP_DIRECTIONS, MINDMAP_FONT_SIZE, MINDMAP_HANDLE_HIT_RADIUS, MINDMAP_HANDLE_RADIUS, MINDMAP_MAX_WIDTH, MINDMAP_MIN_WIDTH, MINDMAP_NODE_HEIGHT, MIN_HANDLE_SEGMENT, MIN_JOG, Mat2d, type MessageKey, type MindMapDirection, type MindMapHandleKind, type MindMapHandlePos, type MindMapLayoutResult, type MindMapNode, type MindMapNodePos, type MindMapShape, type OctagonShape, PAGE_THEMES, type PageTheme, type PageThemePreset, type ParallelogramShape, type PentagonShape, type Rect, type RectangleShape, Renderer, type RoundedRectangleShape, STICKY_FOLD_RATIO, STICKY_NOTE_COLORS, STICKY_NOTE_DEFAULT_COLOR, STICKY_TEXT_SCALE, type SegmentHandle, SelectTool, type Shape, type ShapeStyle, ShapeTool, type ShapeType, type SnapGuide, type StarShape, type StickyNoteShape, TABLE_CELL_PADDING_X, TABLE_CELL_PADDING_Y, TABLE_DEFAULT_COL_WIDTH, TABLE_DEFAULT_ROW_HEIGHT, TABLE_FONT_SIZE, TABLE_HEADER_FILL, TABLE_LINE_HEIGHT_RATIO, TABLE_MAX_AUTO_LINES, TABLE_MIN_COL_WIDTH, TABLE_MIN_ROW_HEIGHT, TABLE_MOVE_HANDLE_GAP, TABLE_MOVE_HANDLE_HEIGHT, TABLE_MOVE_HANDLE_WIDTH, THEME, type TableCell, type TableShape, type TextShape, type ToolType, type TrapezoidShape, type TriangleShape, UML_FONT_SIZE, UML_HEADER_HEIGHT, UML_LINE_HEIGHT, UML_MIN_WIDTH, UML_PADDING_X, UML_PADDING_Y, type UiEvent, type UmlAttribute, type UmlClassShape, type UmlInterfaceShape, type UmlMethod, type UmlVisibility, Vec, type Vec2 as Vec2Type, addImageReadyListener, calcUmlClassSize, clearImageCache, cloneMindMapNode, cloneTable, cloneTableCells, collapseRoute, collectTemporaryImageSrcs, connectorSegmentHandles, countMindMapNodes, createTableCells, downloadBlob, effectiveDirection, ensureImagesLoaded, exportToBlob, findMindMapNode, getContentBounds, getIcon, getLanguage, getMindMapNodeDepth, getMindMapNodeSiblings, getMindMapParent, getTheme, hasIcon, hexToRgba, hitTableBody, hitTableMoveHandle, iconInk, iconsByCategory, imageDataUrl, isEmptyRect, isFlippableShapeType, isHorizontalDirection, isImageFailed, isImageLoading, isStubCorner, isUploaderFunction, layoutMindMap, loadImage, mindMapHandleAtLocalPoint, mindMapNodeColor, mindMapNodeHandles, mindMapNodeSize, moveMindMapNodeInTree, offsetConnectorSegment, parseUploadResponse, peekImage, pickSegmentHandle, pointToSegmentDistance, promoteMindMapNodeInTree, pruneStubBends, rectsIntersect, renderSVGString, renderToCanvas, reorderMindMapNodeInTree, routeToUserPoints, sameRoute, searchIcons, setImageCrossOrigin, setLanguage, setTheme, shadeColor, subscribeLanguage, subscribeTheme, subtractUnion, t, tableAnchorAt, tableCellAtLocalClamped, tableCellLineCount, tableCellLocalRect, tableCellTextStartOffset, tableCoveredMap, tableDeleteColumn, tableDeleteRow, tableExpandRangeToMerges, tableGrowRowHeights, tableInsertColumn, tableInsertRow, tableLocalPoint, tableMerge, tableMoveHandleLocalRect, tablePagePoint, tableRangeHasMerge, tableRangeLocalRect, tableRowAtPoint, tableSplit, tableSplitRange, tableTotalHeight, tableTotalWidth, umlAttrRowText, umlMethodRowText, unionRect, uploadImageViaConfig };
package/dist/index.d.ts CHANGED
@@ -567,6 +567,17 @@ declare function getTheme(): DrawuiTheme;
567
567
  declare function hexToRgba(hex: string, alpha: number): string;
568
568
  /** 颜色变暗/变亮:percent 负数变暗、正数变亮 */
569
569
  declare function shadeColor(hex: string, percent: number): string;
570
+ /** 页面主题(画布背景 + UI 色调),与 react 层 theme.less 的 data-theme 一一对应 */
571
+ type PageTheme = 'light' | 'warm' | 'gray' | 'purple' | 'green' | 'eye-care';
572
+ /** 页面主题在 core 层需要覆盖的颜色 */
573
+ interface PageThemePreset {
574
+ /** 网格线颜色 */
575
+ grid: string;
576
+ }
577
+ /** 页面主题预设:网格颜色随背景深浅调整,保证可见但不突兀 */
578
+ declare const PAGE_THEMES: Record<PageTheme, PageThemePreset>;
579
+ /** 默认页面主题 */
580
+ declare const DEFAULT_PAGE_THEME: PageTheme;
570
581
 
571
582
  /**
572
583
  * 国际化:框架无关的轻量字典 + 语言切换。
@@ -758,6 +769,10 @@ declare const zhCN: {
758
769
  readonly 'mindmap.expand': "展开";
759
770
  readonly 'mindmap.close': "关闭编辑";
760
771
  readonly 'mindmap.more': "更多设置";
772
+ readonly 'mindmap.level': "层级";
773
+ readonly 'mindmap.promote1': "升一级";
774
+ readonly 'mindmap.promote2': "升两级";
775
+ readonly 'mindmap.promoteDisabled': "已至顶层";
761
776
  readonly 'tool.table': "表格";
762
777
  readonly 'toolbar.table': "表格";
763
778
  readonly 'shape.table': "表格";
@@ -794,6 +809,14 @@ declare const zhCN: {
794
809
  readonly 'ctx.delete': "删除";
795
810
  readonly 'toolbar.icon': "图标";
796
811
  readonly 'toolbar.image': "图片";
812
+ readonly 'toolbar.more': "更多";
813
+ readonly 'toolbar.pageTheme': "页面主题";
814
+ readonly 'pageTheme.light': "默认";
815
+ readonly 'pageTheme.warm': "暖黄";
816
+ readonly 'pageTheme.gray': "浅灰";
817
+ readonly 'pageTheme.purple': "浅紫";
818
+ readonly 'pageTheme.green': "浅绿";
819
+ readonly 'pageTheme.eye-care': "护眼";
797
820
  readonly 'tool.image': "图片";
798
821
  readonly 'image.uploadFailed': "图片上传失败";
799
822
  readonly 'image.insertFailed': "图片插入失败";
@@ -947,6 +970,29 @@ declare function getMindMapNodeSiblings(root: MindMapNode, nodeId: string): {
947
970
  * newIndex 是相对于同 direction siblings 的索引。
948
971
  */
949
972
  declare function reorderMindMapNodeInTree(root: MindMapNode, nodeId: string, newIndex: number): MindMapNode;
973
+ /**
974
+ * 把节点「升级」levels 层:把 node 重新挂到它第 levels 层祖先之下,并紧挨着
975
+ * 它原来的直接祖先(即第 levels 层祖先的子节点)之后。
976
+ *
977
+ * - 升 1 层:node 成为「父节点的兄弟」(新父 = 祖父);
978
+ * - 升 2 层:node 成为「祖父节点的兄弟」(新父 = 曾祖父);
979
+ * - ……依此类推。
980
+ *
981
+ * 节点自身的子树(children)整体跟着一起上移,不会被拆散。
982
+ * 可行性由调用方判断:node 的 depth 必须 ≥ levels + 1(至少要有一个「新父」)。
983
+ * 不满足条件时原样返回 root(不改动)。
984
+ */
985
+ declare function promoteMindMapNodeInTree(root: MindMapNode, nodeId: string, levels: number): MindMapNode;
986
+ /**
987
+ * 把节点「转移」到另一个父节点下,落在同方向兄弟组的 insertIndex 处。
988
+ * 用于拖拽换层级:把节点拖到某个节点上 → 成为该节点的兄弟。
989
+ *
990
+ * - 子树整体跟随,不被拆散;
991
+ * - 目标父节点落在被移动节点自身子树内(或就是它自己)时,原样返回,避免把树拆坏;
992
+ * - 目标父节点是根节点时,把节点 direction 设为目标兄弟组的方向(否则会被分到错误方向组);
993
+ * 目标是普通节点时清掉显式 direction,改为跟随新父节点的方向。
994
+ */
995
+ declare function moveMindMapNodeInTree(root: MindMapNode, nodeId: string, targetParentId: string, direction: MindMapDirection, insertIndex: number): MindMapNode;
950
996
 
951
997
  type Listener$1 = () => void;
952
998
  type NotificationListener = (message: string) => void;
@@ -963,6 +1009,11 @@ type UiEvent = {
963
1009
  | {
964
1010
  kind: 'imageError';
965
1011
  message: string;
1012
+ }
1013
+ /** 正在拖拽/调整图形(移动/缩放/旋转/拖连线端点或线段/从锚点拉新连线):React 侧据此临时隐藏顶栏工具条 */
1014
+ | {
1015
+ kind: 'drag';
1016
+ active: boolean;
966
1017
  };
967
1018
  /** Editor 构造选项:主题色 / 语言 / 初始数据 / 本地持久化开关 */
968
1019
  interface EditorOptions {
@@ -997,6 +1048,8 @@ declare class Editor {
997
1048
  private isPanning;
998
1049
  private panStart;
999
1050
  private dragStartPositions;
1051
+ /** 是否正处于「拖拽/调整图形」交互中:通过 UiEvent 'drag' 通知 React 临时隐藏顶栏工具条 */
1052
+ private interactionDragging;
1000
1053
  private lastClickTime;
1001
1054
  private lastClickShapeId;
1002
1055
  private editingShapeId;
@@ -1031,6 +1084,13 @@ declare class Editor {
1031
1084
  * siblingIds 已按 cross 坐标排好序,方便 Renderer 直接画插入指示线。
1032
1085
  */
1033
1086
  private mindMapReorderTarget;
1087
+ /**
1088
+ * 拖拽「换层级」计划。两种落点:
1089
+ * - `sibling`:拖到目标节点的**外侧**(框外 48px 内)→ 成为该节点的同方向兄弟(targetParent = 目标节点的父节点);
1090
+ * - `child`:拖到目标节点的**框内** → 成为该节点的子节点(targetParent = 目标节点自身)。
1091
+ * 与 mindMapReorderTarget 的区别:那个是「同父级内重排序」,这个是「换父级(换层级)」。
1092
+ */
1093
+ private mindMapReparentPlan;
1034
1094
  private tableSelection;
1035
1095
  private tableEditing;
1036
1096
  private renderScheduled;
@@ -1198,6 +1258,8 @@ declare class Editor {
1198
1258
  connectToExisting(context: GenerationContext, targetShapeId: string, binding?: ArrowBinding): void;
1199
1259
  subscribeUi(listener: (payload: UiEvent) => void): () => boolean;
1200
1260
  private emitUi;
1261
+ /** 同步「是否正在拖拽图形」状态:仅在实际变化时发出 UiEvent,避免每帧轰炸订阅者 */
1262
+ private setInteractionDragging;
1201
1263
  /** 批量更新选中图形的样式(边框色、填充色等),提交历史记录 */
1202
1264
  updateSelectedShapesStyle(updates: Partial<ShapeStyle>): void;
1203
1265
  /** 批量更新选中图形的文字颜色/高亮背景色/高亮透明度,提交历史记录 */
@@ -1343,6 +1405,15 @@ declare class Editor {
1343
1405
  private pageToMindMapLocal;
1344
1406
  /** 计算拖拽节点时,在其同方向兄弟列表中的目标插入索引 */
1345
1407
  private calcMindMapReorderTarget;
1408
+ /**
1409
+ * 结构变化后补偿导图中心的位移,让**根节点在屏幕上不动**。
1410
+ *
1411
+ * 背景:`layoutMindMap` 末尾会把包围盒中心对齐到导图中心,所以树一变宽/变高,
1412
+ * 所有节点都会整体平移 —— 换层级/增删节点时看起来就是「整张图跳了一下」。
1413
+ * 这里按根节点在旧/新布局中的局部坐标差反向平移导图中心,于是只有受影响的
1414
+ * 子树重排,画面不会整体滑走(XMind 等也是这样,居中主题是视觉锚点)。
1415
+ */
1416
+ private anchorMindMapAtRoot;
1346
1417
  /** 获取选中的思维导图(恰好选中一个时) */
1347
1418
  getSelectedMindMap(): MindMapShape | null;
1348
1419
  /** 页面坐标下的思维导图节点命中:返回所在导图与节点 id */
@@ -1361,6 +1432,21 @@ declare class Editor {
1361
1432
  shapeId: string;
1362
1433
  nodeId: string;
1363
1434
  } | null;
1435
+ /**
1436
+ * 导图局部坐标下命中「某个节点框」的节点 id(拖拽换层级用)。
1437
+ * 排除 excludeNodeId 及其整棵子树 —— 否则会出现「把节点拖进自己的子树」这种非法落点。
1438
+ */
1439
+ private hitMindMapNodeBox;
1440
+ /**
1441
+ * 「成为子节点」落点:目标节点 targetId 的子节点组信息。
1442
+ * - `direction`:该组子节点的生长方向(目标非根 = 布局算出的目标方向;目标是根 = 取 cross 上离指针最近的方向组);
1443
+ * - `childIds`:已有的同方向子节点 id(为空表示新节点会成为第一个孩子)。
1444
+ */
1445
+ private mindMapChildGroup;
1446
+ /** 按 cross 坐标给同方向兄弟排序(Renderer 画落点占位框时要求同源顺序) */
1447
+ private mindMapSortByCross;
1448
+ /** 落点指示只在「真的变了」时更新(避免每帧 scheduleRender 抖动) */
1449
+ private setReorderIndicator;
1364
1450
  /** 光标语义命中:仅节点框(含「+」快捷按钮、折叠/展开标记)内才命中,节点间空档不命中 */
1365
1451
  getMindMapCursorHitAtPoint(point: Vec2): {
1366
1452
  shapeId: string;
@@ -1427,10 +1513,23 @@ declare class Editor {
1427
1513
  addMindMapSibling(shapeId: string, nodeId: string): void;
1428
1514
  /** 将节点在其同方向兄弟列表中移动到目标索引 */
1429
1515
  reorderMindMapNode(shapeId: string, nodeId: string, targetIndex: number): void;
1516
+ /**
1517
+ * 拖拽换层级:把节点移到目标父节点下、同方向兄弟组的 insertIndex 处。
1518
+ * 「拖到某个节点框上」= 成为该节点的同方向兄弟(即 targetParent = 该节点的父节点)。
1519
+ * 非法落点(目标是自己或自己的后代替)不修改文档。
1520
+ */
1521
+ moveMindMapNodeToParent(shapeId: string, nodeId: string, targetParentId: string, direction: MindMapDirection, insertIndex: number): void;
1430
1522
  /** 删除指定节点(含子树);删除根节点则移除整个思维导图 */
1431
1523
  deleteMindMapNode(shapeId: string, nodeId: string): void;
1432
1524
  /** 折叠/展开指定节点 */
1433
1525
  toggleMindMapCollapse(shapeId: string, nodeId: string): void;
1526
+ /** 节点能否「升级」levels 层:depth 必须 ≥ levels + 1(至少得有个新父节点)。根节点不可升级。 */
1527
+ canPromoteMindMapNode(shapeId: string, nodeId: string, levels: number): boolean;
1528
+ /**
1529
+ * 把节点升级 levels 层(升 1 层 = 成为父节点的兄弟;升 2 层 = 成为祖父节点的兄弟)。
1530
+ * 节点自身子树整体上移,不被拆散。不可升级时(已到顶层)直接返回,不改动文档。
1531
+ */
1532
+ promoteMindMapNode(shapeId: string, nodeId: string, levels: number): void;
1434
1533
  /** 获取选中的表格(恰好选中一个时) */
1435
1534
  getSelectedTable(): TableShape | null;
1436
1535
  private getTableById;
@@ -1823,6 +1922,8 @@ declare class Renderer {
1823
1922
  targetIndex: number;
1824
1923
  direction: MindMapDirection;
1825
1924
  siblingIds: string[];
1925
+ /** 「成为子节点」模式:目标节点 id(高亮它 + 子组为空时定位占位框) */
1926
+ childParentId?: string;
1826
1927
  } | null,
1827
1928
  /** 导出用:非 null 时先以该颜色铺满整块画布(白底等),默认不铺(透明) */
1828
1929
  background?: string | null,
@@ -2416,6 +2517,11 @@ declare abstract class Tool {
2416
2517
  * @returns 是否确实清理了状态(false = 本来就是空闲态,调用方可跳过重绘)
2417
2518
  */
2418
2519
  cancelTransient(): boolean;
2520
+ /**
2521
+ * 是否正处于「拖拽/调整图形」中(移动/缩放/旋转图形、拖连线端点或线段、从锚点拉新连线)。
2522
+ * 默认 false;选择工具等会覆盖,供编辑器据此临时隐藏顶栏工具条。
2523
+ */
2524
+ isDragging(): boolean;
2419
2525
  dispose(): void;
2420
2526
  }
2421
2527
 
@@ -2510,6 +2616,11 @@ declare class SelectTool extends Tool {
2510
2616
  */
2511
2617
  private finishSegmentDrag;
2512
2618
  hasTransientState(): boolean;
2619
+ /**
2620
+ * 拖拽/调整图形中:移动、缩放、旋转、拖连线端点、拖线段、从锚点拉新连线。
2621
+ * (框选空白、表格内框选单元格不算「拖图形」,不触发顶栏隐藏。)
2622
+ */
2623
+ isDragging(): boolean;
2513
2624
  /**
2514
2625
  * 取消一切瞬态交互(拖拽/生成/框选/旋转/连线端点拖拽)并清掉画布上的瞬态预览。
2515
2626
  * 触发场景:指针在窗口外松手丢失 pointerup、窗口失焦、点击画布外、无按压的移动、
@@ -2987,4 +3098,4 @@ declare function imageDataUrl(src: string): string | null;
2987
3098
  /** 清空缓存(测试/卸载时用;会释放自己创建的 blob 地址) */
2988
3099
  declare function clearImageCache(): void;
2989
3100
 
2990
- export { type ArrowBinding, type ArrowHeadType, type ArrowShape, type ArrowStyle, ArrowTool, BoardExtentKeeper, type BoardExtentResult, type BoardExtentUpdate, Camera, type CameraState, type CircleShape, type ConnectionType, DEFAULT_HIGHLIGHTER_COLOR, DEFAULT_IMAGE_MAX_SIZE_BYTES, type DiamondShape, type DrawShape, type DrawuiTheme, type DrawuiThemeSelection, Editor, type EditorData, type EditorOptions, type EditorState, type EllipseShape, type ExportFormat, type ExportOptions, type FreehandMode, FreehandTool, type GenerationContext, HandTool, type HexagonShape, ICONS, ICON_CATEGORIES, ICON_CATEGORY_INK, ICON_DEFAULT_INK, ICON_DEFAULT_SIZE, ICON_GRID, type IconCategoryId, type IconDef, type IconLayer, type IconShape, type ImageShape, type ImageUploadConfig, type ImageUploadOption, type ImageUploader, LANGUAGES, type Language, type LineShape, LineTool, MINDMAP_COLORS, MINDMAP_DIRECTIONS, MINDMAP_FONT_SIZE, MINDMAP_HANDLE_HIT_RADIUS, MINDMAP_HANDLE_RADIUS, MINDMAP_MAX_WIDTH, MINDMAP_MIN_WIDTH, MINDMAP_NODE_HEIGHT, MIN_HANDLE_SEGMENT, MIN_JOG, Mat2d, type MessageKey, type MindMapDirection, type MindMapHandleKind, type MindMapHandlePos, type MindMapLayoutResult, type MindMapNode, type MindMapNodePos, type MindMapShape, type OctagonShape, type ParallelogramShape, type PentagonShape, type Rect, type RectangleShape, Renderer, type RoundedRectangleShape, STICKY_FOLD_RATIO, STICKY_NOTE_COLORS, STICKY_NOTE_DEFAULT_COLOR, STICKY_TEXT_SCALE, type SegmentHandle, SelectTool, type Shape, type ShapeStyle, ShapeTool, type ShapeType, type SnapGuide, type StarShape, type StickyNoteShape, TABLE_CELL_PADDING_X, TABLE_CELL_PADDING_Y, TABLE_DEFAULT_COL_WIDTH, TABLE_DEFAULT_ROW_HEIGHT, TABLE_FONT_SIZE, TABLE_HEADER_FILL, TABLE_LINE_HEIGHT_RATIO, TABLE_MAX_AUTO_LINES, TABLE_MIN_COL_WIDTH, TABLE_MIN_ROW_HEIGHT, TABLE_MOVE_HANDLE_GAP, TABLE_MOVE_HANDLE_HEIGHT, TABLE_MOVE_HANDLE_WIDTH, THEME, type TableCell, type TableShape, type TextShape, type ToolType, type TrapezoidShape, type TriangleShape, UML_FONT_SIZE, UML_HEADER_HEIGHT, UML_LINE_HEIGHT, UML_MIN_WIDTH, UML_PADDING_X, UML_PADDING_Y, type UiEvent, type UmlAttribute, type UmlClassShape, type UmlInterfaceShape, type UmlMethod, type UmlVisibility, Vec, type Vec2 as Vec2Type, addImageReadyListener, calcUmlClassSize, clearImageCache, cloneMindMapNode, cloneTable, cloneTableCells, collapseRoute, collectTemporaryImageSrcs, connectorSegmentHandles, countMindMapNodes, createTableCells, downloadBlob, effectiveDirection, ensureImagesLoaded, exportToBlob, findMindMapNode, getContentBounds, getIcon, getLanguage, getMindMapNodeDepth, getMindMapNodeSiblings, getMindMapParent, getTheme, hasIcon, hexToRgba, hitTableBody, hitTableMoveHandle, iconInk, iconsByCategory, imageDataUrl, isEmptyRect, isFlippableShapeType, isHorizontalDirection, isImageFailed, isImageLoading, isStubCorner, isUploaderFunction, layoutMindMap, loadImage, mindMapHandleAtLocalPoint, mindMapNodeColor, mindMapNodeHandles, mindMapNodeSize, offsetConnectorSegment, parseUploadResponse, peekImage, pickSegmentHandle, pointToSegmentDistance, pruneStubBends, rectsIntersect, renderSVGString, renderToCanvas, reorderMindMapNodeInTree, routeToUserPoints, sameRoute, searchIcons, setImageCrossOrigin, setLanguage, setTheme, shadeColor, subscribeLanguage, subscribeTheme, subtractUnion, t, tableAnchorAt, tableCellAtLocalClamped, tableCellLineCount, tableCellLocalRect, tableCellTextStartOffset, tableCoveredMap, tableDeleteColumn, tableDeleteRow, tableExpandRangeToMerges, tableGrowRowHeights, tableInsertColumn, tableInsertRow, tableLocalPoint, tableMerge, tableMoveHandleLocalRect, tablePagePoint, tableRangeHasMerge, tableRangeLocalRect, tableRowAtPoint, tableSplit, tableSplitRange, tableTotalHeight, tableTotalWidth, umlAttrRowText, umlMethodRowText, unionRect, uploadImageViaConfig };
3101
+ export { type ArrowBinding, type ArrowHeadType, type ArrowShape, type ArrowStyle, ArrowTool, BoardExtentKeeper, type BoardExtentResult, type BoardExtentUpdate, Camera, type CameraState, type CircleShape, type ConnectionType, DEFAULT_HIGHLIGHTER_COLOR, DEFAULT_IMAGE_MAX_SIZE_BYTES, DEFAULT_PAGE_THEME, type DiamondShape, type DrawShape, type DrawuiTheme, type DrawuiThemeSelection, Editor, type EditorData, type EditorOptions, type EditorState, type EllipseShape, type ExportFormat, type ExportOptions, type FreehandMode, FreehandTool, type GenerationContext, HandTool, type HexagonShape, ICONS, ICON_CATEGORIES, ICON_CATEGORY_INK, ICON_DEFAULT_INK, ICON_DEFAULT_SIZE, ICON_GRID, type IconCategoryId, type IconDef, type IconLayer, type IconShape, type ImageShape, type ImageUploadConfig, type ImageUploadOption, type ImageUploader, LANGUAGES, type Language, type LineShape, LineTool, MINDMAP_COLORS, MINDMAP_DIRECTIONS, MINDMAP_FONT_SIZE, MINDMAP_HANDLE_HIT_RADIUS, MINDMAP_HANDLE_RADIUS, MINDMAP_MAX_WIDTH, MINDMAP_MIN_WIDTH, MINDMAP_NODE_HEIGHT, MIN_HANDLE_SEGMENT, MIN_JOG, Mat2d, type MessageKey, type MindMapDirection, type MindMapHandleKind, type MindMapHandlePos, type MindMapLayoutResult, type MindMapNode, type MindMapNodePos, type MindMapShape, type OctagonShape, PAGE_THEMES, type PageTheme, type PageThemePreset, type ParallelogramShape, type PentagonShape, type Rect, type RectangleShape, Renderer, type RoundedRectangleShape, STICKY_FOLD_RATIO, STICKY_NOTE_COLORS, STICKY_NOTE_DEFAULT_COLOR, STICKY_TEXT_SCALE, type SegmentHandle, SelectTool, type Shape, type ShapeStyle, ShapeTool, type ShapeType, type SnapGuide, type StarShape, type StickyNoteShape, TABLE_CELL_PADDING_X, TABLE_CELL_PADDING_Y, TABLE_DEFAULT_COL_WIDTH, TABLE_DEFAULT_ROW_HEIGHT, TABLE_FONT_SIZE, TABLE_HEADER_FILL, TABLE_LINE_HEIGHT_RATIO, TABLE_MAX_AUTO_LINES, TABLE_MIN_COL_WIDTH, TABLE_MIN_ROW_HEIGHT, TABLE_MOVE_HANDLE_GAP, TABLE_MOVE_HANDLE_HEIGHT, TABLE_MOVE_HANDLE_WIDTH, THEME, type TableCell, type TableShape, type TextShape, type ToolType, type TrapezoidShape, type TriangleShape, UML_FONT_SIZE, UML_HEADER_HEIGHT, UML_LINE_HEIGHT, UML_MIN_WIDTH, UML_PADDING_X, UML_PADDING_Y, type UiEvent, type UmlAttribute, type UmlClassShape, type UmlInterfaceShape, type UmlMethod, type UmlVisibility, Vec, type Vec2 as Vec2Type, addImageReadyListener, calcUmlClassSize, clearImageCache, cloneMindMapNode, cloneTable, cloneTableCells, collapseRoute, collectTemporaryImageSrcs, connectorSegmentHandles, countMindMapNodes, createTableCells, downloadBlob, effectiveDirection, ensureImagesLoaded, exportToBlob, findMindMapNode, getContentBounds, getIcon, getLanguage, getMindMapNodeDepth, getMindMapNodeSiblings, getMindMapParent, getTheme, hasIcon, hexToRgba, hitTableBody, hitTableMoveHandle, iconInk, iconsByCategory, imageDataUrl, isEmptyRect, isFlippableShapeType, isHorizontalDirection, isImageFailed, isImageLoading, isStubCorner, isUploaderFunction, layoutMindMap, loadImage, mindMapHandleAtLocalPoint, mindMapNodeColor, mindMapNodeHandles, mindMapNodeSize, moveMindMapNodeInTree, offsetConnectorSegment, parseUploadResponse, peekImage, pickSegmentHandle, pointToSegmentDistance, promoteMindMapNodeInTree, pruneStubBends, rectsIntersect, renderSVGString, renderToCanvas, reorderMindMapNodeInTree, routeToUserPoints, sameRoute, searchIcons, setImageCrossOrigin, setLanguage, setTheme, shadeColor, subscribeLanguage, subscribeTheme, subtractUnion, t, tableAnchorAt, tableCellAtLocalClamped, tableCellLineCount, tableCellLocalRect, tableCellTextStartOffset, tableCoveredMap, tableDeleteColumn, tableDeleteRow, tableExpandRangeToMerges, tableGrowRowHeights, tableInsertColumn, tableInsertRow, tableLocalPoint, tableMerge, tableMoveHandleLocalRect, tablePagePoint, tableRangeHasMerge, tableRangeLocalRect, tableRowAtPoint, tableSplit, tableSplitRange, tableTotalHeight, tableTotalWidth, umlAttrRowText, umlMethodRowText, unionRect, uploadImageViaConfig };