ai-chatbot/lib/flow-board/xmind-typography.ts
134 79253245f3 fix(flow-board): align Xmind editor UI and restore marquee feedback
Add native-style menus, search and presentation controls, typography resources, and Xmind import/export styling support.

Bundle canvas styles for preview and production, show marquee borders and selection fills, and align editor density with the project UI. Include interaction regression coverage and client comparison notes.
2026-10-04 13:32:54 +08:00

24 lines
1.0 KiB
TypeScript

import { measureElement, updateElementSizeCache } from "@plait/common";
import type { PlaitBoard } from "@plait/core";
import { getDefaultFontSizeForMindElement, NodeSpace, type MindElement, type PlaitMindBoard } from "@plait/mind";
const measured = new WeakMap<object, number>();
/** Plait measures with a system font by default. Seed its cache with the canvas font. */
export function measureXmindTopics(board: PlaitBoard, element: MindElement) {
const topic = element.data?.topic;
const maxWidth = NodeSpace.getTopicMaxDynamicWidth(board as PlaitMindBoard, element);
if (topic && measured.get(topic) !== maxWidth) {
const size = measureElement(board, topic, {
fontSize: getDefaultFontSizeForMindElement(element),
fontFamily: 'NeverMind, Arial, "PingFang SC", sans-serif',
}, maxWidth);
updateElementSizeCache(board, topic, {
width: Math.ceil(size.width) + 2,
height: Math.ceil(size.height),
});
measured.set(topic, maxWidth);
}
for (const child of element.children || []) measureXmindTopics(board, child);
}