AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(mobile): open large mind maps at a readable size
tianma-ifa126c3441f9c
diff --git a/apps/ios/EditorSource/src/styles.css b/apps/ios/EditorSource/src/styles.cssindex 1b45a6f3..b1644b21 100644--- a/apps/ios/EditorSource/src/styles.css+++ b/apps/ios/EditorSource/src/styles.css@@ -838,11 +838,24 @@ html[data-theme="dark"] .ProseMirror pre code {height: auto;}+#editor.edgeever-diagram-reader-host {+ display: flex;+ flex-direction: column;+ overflow: hidden;+}++.edgeever-diagram-reader-controls {+ flex: 0 0 auto;+ padding-left: 16px;+ padding-right: 16px;+}+.edgeever-x6-diagram {- width: 100%;- height: min(56vh, 520px);- min-height: 360px;- margin: 18px 16px;+ flex: 1 1 auto;+ width: auto;+ height: auto;+ min-height: 240px;+ margin: 0 16px 16px;overflow: hidden;border: 1px solid #e3ece7;border-radius: 14px;@@ -850,6 +863,10 @@ html[data-theme="dark"] .ProseMirror pre code {touch-action: none;}+.edgeever-x6-diagram .x6-node {+ cursor: pointer;+}+html[data-theme="dark"] .edgeever-x6-diagram {border-color: #26382f;background: #101311;diff --git a/apps/ios/Tests/EdgeEverTests/TipTapContentSourceTests.swift b/apps/ios/Tests/EdgeEverTests/TipTapContentSourceTests.swiftindex 7d2500fc..b4aa2c5a 100644--- a/apps/ios/Tests/EdgeEverTests/TipTapContentSourceTests.swift+++ b/apps/ios/Tests/EdgeEverTests/TipTapContentSourceTests.swift@@ -327,11 +327,10 @@ final class TipTapContentSourceTests: XCTestCase {XCTAssertGreaterThan(graphWidth, 300, "X6 must occupy the viewer width instead of collapsing")XCTAssertGreaterThan(nodeCount, 0, "X6 must materialize diagram nodes")let controlsCount = try await evalInt(webView, "document.querySelectorAll('.edgeever-diagram-reader-controls').length")- XCTAssertEqual(controlsCount, 1, "reusing a viewer must not accumulate controls")- let hasReadingButton = try await evalBool(webView, "!!document.querySelector('button[aria-label=\"从起点阅读\"]')")- if hasReadingButton {- _ = try await eval(webView, "document.querySelector('button[aria-label=\"从起点阅读\"]').click()")- let readingScale = try await evalInt(webView, "parseInt(document.querySelector('button[aria-label=\"恢复 100%\"]').textContent)")+ XCTAssertEqual(controlsCount, 0, "the reader must not draw zoom chrome over the canvas")+ let isFlowchart = try await evalBool(webView, "document.querySelector('.edgeever-x6-diagram')?.getAttribute('aria-label') === '流程图'")+ if isFlowchart {+ let readingScale = try await evalInt(webView, "parseInt(document.querySelector('.edgeever-x6-diagram').dataset.scale)")XCTAssertEqual(readingScale, 100)let scrolled = try await evalBool(webView, """(function() {@@ -343,13 +342,6 @@ final class TipTapContentSourceTests: XCTestCase {})()""")XCTAssertTrue(scrolled, "ordinary wheel must move the graph viewport")-- _ = try await eval(webView, "document.querySelector('button[aria-label=\"放大\"]').click()")- let enlargedScale = try await evalInt(webView, "parseInt(document.querySelector('button[aria-label=\"恢复 100%\"]').textContent)")- XCTAssertEqual(enlargedScale, 125)- _ = try await eval(webView, "document.querySelector('button[aria-label=\"适应画布\"]').click()")- let overviewScale = try await evalInt(webView, "parseInt(document.querySelector('button[aria-label=\"恢复 100%\"]').textContent)")- XCTAssertLessThan(overviewScale, 80)}let leakedLegacyFallback = try await evalBool(webView, "document.body.innerText.includes('node list only')")diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsxindex 27a80b09..7b70a2b6 100644--- a/apps/mobile/src/components/LocalTiptapEditor.tsx+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx@@ -3182,9 +3182,12 @@ const getEditorStyles = (theme: "light" | "dark", options?: { viewer?: boolean }.edgeever-code-block, .edgeever-mermaid-code-block { position: relative; margin: 18px 0; overflow: visible; background: transparent; }.edgeever-code-copy-button { position: absolute; top: 8px; right: 8px; z-index: 1; border: 1px solid ${theme === "dark" ? "#475569" : "#cbded1"}; border-radius: 6px; padding: 5px 8px; background: ${theme === "dark" ? "rgba(30, 41, 59, 0.94)" : "rgba(247, 251, 248, 0.94)"}; color: ${theme === "dark" ? "#cbd5e1" : "#475569"}; font: inherit; font-size: 12px; line-height: 1.35; }.edgeever-code-copy-button:active { border-color: #0f766e; color: ${theme === "dark" ? "#86efac" : "#0f766e"}; }- .edgeever-x6-document { min-height: 100%; padding: 18px 12px 32px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; }- .edgeever-x6-diagram { width: 100%; height: min(56vh, 520px); min-height: 360px; overflow: hidden; border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"}; border-radius: 14px; background: ${theme === "dark" ? "#101311" : "#f8faf9"}; touch-action: none; }+ .edgeever-editor-scroll:has(.edgeever-x6-document) { display: flex; flex-direction: column; overflow: hidden; }+ .edgeever-x6-document, .edgeever-diagram-reader-host { display: flex; flex-direction: column; height: 100%; min-height: 100%; padding: 8px 12px 12px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; }+ .edgeever-diagram-reader-controls { flex: 0 0 auto; }+ .edgeever-x6-diagram { flex: 1 1 auto; width: 100%; height: auto; min-height: 240px; overflow: hidden; border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"}; border-radius: 14px; background: ${theme === "dark" ? "#101311" : "#f8faf9"}; touch-action: none; }.edgeever-x6-diagram .x6-graph-svg { overflow: hidden; }+ .edgeever-x6-diagram .x6-node { cursor: pointer; }.edgeever-mermaid-code-block > pre { display: none; margin: 8px 0 0; }.edgeever-mermaid-code-block.is-source-visible > pre { display: block; }.edgeever-mermaid-preview { display: flex; min-height: 104px; align-items: center; justify-content: center; overflow-x: auto; padding: 16px 4px; background: transparent; }diff --git a/apps/mobile/src/lib/mobile-diagram.test.ts b/apps/mobile/src/lib/mobile-diagram.test.tsindex 56a1b964..0ac3824a 100644--- a/apps/mobile/src/lib/mobile-diagram.test.ts+++ b/apps/mobile/src/lib/mobile-diagram.test.ts@@ -1,3 +1,4 @@+import { readFileSync } from "node:fs";import { describe, expect, test } from "bun:test";import { createDefaultDiagramDocument, diagramFallbackMarkdown, serializeDiagramDocument } from "@edgeever/shared";import { getMobileVisualDiagramKind, hasMobileVisualDiagram, resolveMobileMemoViewerContent } from "./mobile-diagram";@@ -35,6 +36,13 @@ describe("mobile visual diagram viewer", () => {expect(hasMermaidCodeBlock(viewerContent)).toBe(true);});+ test("fills the remaining phone viewport instead of shrinking the canvas to a postage stamp", () => {+ const source = readFileSync(new URL("../components/LocalTiptapEditor.tsx", import.meta.url), "utf8");+ expect(source).toContain(".edgeever-editor-scroll:has(.edgeever-x6-document) { display: flex; flex-direction: column; overflow: hidden; }");+ expect(source).toContain("flex: 1 1 auto");+ expect(source).not.toContain("height: min(56vh, 520px)");+ });+test("does not leak diagram metadata when browser codec globals are unavailable", () => {const serialized = serializeDiagramDocument(createDefaultDiagramDocument("mind-map"));const originalAtob = globalThis.atob;diff --git a/apps/web/src/components/ReadOnlyX6Diagram.tsx b/apps/web/src/components/ReadOnlyX6Diagram.tsxindex 494c4bc8..4046930a 100644--- a/apps/web/src/components/ReadOnlyX6Diagram.tsx+++ b/apps/web/src/components/ReadOnlyX6Diagram.tsx@@ -79,11 +79,19 @@ export const ReadOnlyX6Diagram = ({return (<section className="edgeever-x6-document"><style>{`- .edgeever-x6-document { min-height: 360px; padding: 8px 12px 24px; }+ .edgeever-x6-document, .edgeever-diagram-reader-host {+ display: flex;+ flex-direction: column;+ min-height: min(78vh, 760px);+ height: min(78vh, 760px);+ padding: 8px 12px 16px;+ }+ .edgeever-diagram-reader-controls { flex: 0 0 auto; }.edgeever-x6-diagram {+ flex: 1 1 auto;width: 100%;- height: min(70vh, 640px);- min-height: 360px;+ height: auto;+ min-height: 240px;overflow: hidden;border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"};border-radius: 14px;@@ -91,6 +99,7 @@ export const ReadOnlyX6Diagram = ({touch-action: none;}.edgeever-x6-diagram .x6-graph-svg { overflow: hidden; }+ .edgeever-x6-diagram .x6-node { cursor: pointer; }`}</style><divaria-label={diagramTitle(diagram, locale)}diff --git a/apps/web/src/lib/diagram-layout.test.mjs b/apps/web/src/lib/diagram-layout.test.mjsindex cb650710..b460aaec 100644--- a/apps/web/src/lib/diagram-layout.test.mjs+++ b/apps/web/src/lib/diagram-layout.test.mjs@@ -245,4 +245,12 @@ describe("diagram auto layout", () => {minScale: 0.85,});});++ test("keeps mind-map viewports at reading size instead of shrinking the whole tree", () => {+ expect(getDiagramLayoutViewport("mind-map")).toEqual({+ anchor: "root",+ maxScale: 1,+ minScale: 0.85,+ });+ });});diff --git a/packages/shared/src/diagram-layout.ts b/packages/shared/src/diagram-layout.tsindex 436731d7..2d34f024 100644--- a/packages/shared/src/diagram-layout.ts+++ b/packages/shared/src/diagram-layout.ts@@ -736,7 +736,7 @@ const DIAGRAM_LAYOUT_STRATEGIES: Record<DiagramKind, DiagramLayoutStrategy> = {"mind-map": {kind: "mind-map",layout: computeMindMapLayout,- viewport: { anchor: "root", maxScale: 1 },+ viewport: { anchor: "root", maxScale: 1, minScale: FLOWCHART_READABLE_MIN_SCALE },},flowchart: {kind: "flowchart",diff --git a/packages/shared/src/diagram-reader.test.mjs b/packages/shared/src/diagram-reader.test.mjsnew file mode 100644index 00000000..bb43f2ec--- /dev/null+++ b/packages/shared/src/diagram-reader.test.mjs@@ -0,0 +1,85 @@+import { readFileSync } from "node:fs";+import { describe, expect, test } from "bun:test";+import {+ DIAGRAM_READER_MIN_SCALE,+ diagramReaderFocusNode,+ diagramReaderFocusTranslate,+ diagramReaderOpeningMode,+ diagramReaderPinchScale,+} from "./diagram-reader.ts";++const mindMap = {+ kind: "mind-map",+ nodes: [+ { id: "root", label: "核心", x: 400, y: 300, width: 120, height: 46 },+ { id: "left", label: "左支", x: 40, y: 80, width: 96, height: 36, parentId: "root" },+ { id: "right", label: "右支", x: 760, y: 520, width: 96, height: 36, parentId: "root" },+ ],+ edges: [+ { id: "e1", source: "root", target: "left" },+ { id: "e2", source: "root", target: "right" },+ ],+};++const flowchart = {+ kind: "flowchart",+ nodes: [+ { id: "start", label: "开始", x: 80, y: 0, width: 100, height: 40, shape: "terminator" },+ { id: "end", label: "结束", x: 80, y: 1600, width: 100, height: 40, shape: "terminator" },+ ],+ edges: [{ id: "e", source: "start", target: "end" }],+};++const architecture = {+ kind: "architecture",+ nodes: [+ { id: "system", label: "系统", x: 0, y: 0, width: 500, height: 300, shape: "boundary" },+ { id: "api", label: "API", x: 240, y: 40, width: 156, height: 64, shape: "service" },+ { id: "web", label: "Web", x: 40, y: 40, width: 156, height: 64, shape: "frontend" },+ ],+ edges: [{ id: "e", source: "web", target: "api" }],+};++describe("diagram reader opening view", () => {+ test("keeps compact diagrams fitted and refuses to open large maps as postage stamps", () => {+ expect(diagramReaderOpeningMode(1)).toBe("fit");+ expect(diagramReaderOpeningMode(0.9)).toBe("fit");+ expect(diagramReaderOpeningMode(0.18)).toBe("read");+ expect(diagramReaderOpeningMode(DIAGRAM_READER_MIN_SCALE)).toBe("fit");+ expect(diagramReaderOpeningMode(DIAGRAM_READER_MIN_SCALE - 0.01)).toBe("read");+ });++ test("focuses the mind-map root, flowchart start, and leftmost architecture component", () => {+ expect(diagramReaderFocusNode(mindMap)?.id).toBe("root");+ expect(diagramReaderFocusNode(flowchart)?.id).toBe("start");+ expect(diagramReaderFocusNode(architecture)?.id).toBe("web");+ });++ test("centers a mind map on the root and pins a flowchart to the top of the canvas", () => {+ const viewport = { width: 390, height: 520 };+ const mind = diagramReaderFocusTranslate(mindMap.nodes[0], viewport, "mind-map", 1);+ expect(mind.tx).toBe(390 / 2 - (400 + 120 / 2));+ expect(mind.ty).toBe(520 / 2 - (300 + 46 / 2));+ const flow = diagramReaderFocusTranslate(flowchart.nodes[0], viewport, "flowchart", 1);+ expect(flow.tx).toBe(390 / 2 - (80 + 100 / 2));+ expect(flow.ty).toBe(32);+ });++ test("scales a pinch around the starting zoom without jumping past the clamps", () => {+ expect(diagramReaderPinchScale(1, 100, 200)).toBe(2);+ expect(diagramReaderPinchScale(1, 100, 50)).toBe(0.5);+ expect(diagramReaderPinchScale(1, 100, 800)).toBe(2.5);+ expect(diagramReaderPinchScale(0.2, 100, 10)).toBe(0.1);+ expect(diagramReaderPinchScale(1, 4, 40)).toBe(1);+ });++ test("opens large diagrams at reading size and keeps Fit as a true overview", () => {+ const source = readFileSync(new URL("./diagram-reader.ts", import.meta.url), "utf8");+ expect(source).toContain("if (diagramReaderOpeningMode(graph.scale().sx) === \"read\") read()");+ expect(source).toContain("graph.on(\"node:click\", onNodeFocus)");+ expect(source).not.toContain("edgeever-diagram-reader-controls");+ expect(source).not.toContain("适应画布");+ expect(source).not.toContain("从中心阅读");+ expect(source).not.toContain("if (diagram.kind === 'flowchart' && graph.scale().sx < FLOWCHART_READABLE_MIN_SCALE) read()");+ });+});diff --git a/packages/shared/src/diagram-reader.ts b/packages/shared/src/diagram-reader.tsindex 65e8c9e4..ae1888d3 100644--- a/packages/shared/src/diagram-reader.ts+++ b/packages/shared/src/diagram-reader.ts@@ -1,64 +1,133 @@import { attachDiagramScroll } from "./diagram-scroll";-import type { DiagramDocument } from './diagram';+import type { DiagramDocument, DiagramKind } from "./diagram";import { FLOWCHART_READABLE_MIN_SCALE } from "./diagram-flowchart-style";+type ReaderBox = { x: number; y: number; width: number; height: number };+type ReaderNode = {+ getBBox?: () => ReaderBox;+};+type ReaderGraph = {resize: (width: number, height: number) => unknown;scale: () => { sx: number; sy: number };- zoomTo: (scale: number) => unknown;+ zoomTo: (scale: number, options?: { center?: { x: number; y: number }; minScale?: number; maxScale?: number }) => unknown;zoomToFit: (options: { maxScale: number; padding: number }) => unknown;centerContent: () => unknown;translate: { (): { tx: number; ty: number }; (x: number, y: number): unknown };- on: (event: string, callback: () => void) => unknown;- off: (event: string, callback: () => void) => unknown;+ on: (event: string, callback: (args?: { node?: ReaderNode }) => void) => unknown;+ off: (event: string, callback: (args?: { node?: ReaderNode }) => void) => unknown;+ disablePanning?: () => unknown;+ enablePanning?: () => unknown;+};++export const DIAGRAM_READER_MIN_SCALE = FLOWCHART_READABLE_MIN_SCALE;+export const DIAGRAM_READER_MAX_SCALE = 2.5;+export const DIAGRAM_READER_FIT_PADDING = 28;++export const diagramReaderOpeningMode = (fitScale: number, minScale = DIAGRAM_READER_MIN_SCALE) => (+ fitScale + 1e-6 >= minScale ? "fit" : "read"+);++export const diagramReaderFocusNode = (diagram: DiagramDocument) => {+ if (!diagram.nodes.length) return undefined;+ if (diagram.kind === "flowchart") {+ const incoming = new Set(diagram.edges.map((edge) => edge.target));+ return diagram.nodes.find((node) => !incoming.has(node.id)) ?? diagram.nodes[0];+ }+ if (diagram.kind === "architecture") {+ const content = diagram.nodes.filter((node) => node.shape !== "boundary");+ return [...(content.length ? content : diagram.nodes)]+ .sort((left, right) => left.x - right.x || left.y - right.y || left.id.localeCompare(right.id))[0];+ }+ return diagram.nodes.find((node) => !node.parentId) ?? diagram.nodes[0];};-/** Common touch-sized reading controls for Android and iOS WebViews. No document writes. */+export const diagramReaderFocusTranslate = (+ node: ReaderBox,+ viewport: { width: number; height: number },+ kind: DiagramKind,+ scale = 1,+) => {+ const cx = node.x + node.width / 2;+ const cy = kind === "flowchart" ? node.y : node.y + node.height / 2;+ return {+ tx: viewport.width / 2 - cx * scale,+ ty: (kind === "flowchart" ? 32 : viewport.height / 2) - cy * scale,+ };+};++export const diagramReaderPinchScale = (+ startScale: number,+ startDistance: number,+ currentDistance: number,+ minScale = 0.1,+ maxScale = DIAGRAM_READER_MAX_SCALE,+) => {+ if (startDistance < 8) return startScale;+ return Math.min(maxScale, Math.max(minScale, startScale * (currentDistance / startDistance)));+};++const touchDistance = (left: Touch, right: Touch) => Math.hypot(left.clientX - right.clientX, left.clientY - right.clientY);++const touchCenter = (left: Touch, right: Touch, bounds: DOMRect) => ({+ x: (left.clientX + right.clientX) / 2 - bounds.left,+ y: (left.clientY + right.clientY) / 2 - bounds.top,+});++/** Touch pan / pinch / tap-to-focus for Android and iOS WebViews. No document writes. */export const attachDiagramReader = (graph: ReaderGraph, container: HTMLElement, diagram: DiagramDocument,- locale: string, dark: boolean,+ _locale: string, _dark: boolean,) => {const detachScroll = attachDiagramScroll(container, graph);- const english = locale === 'en-US';- const toolbar = document.createElement('div');- toolbar.className = 'edgeever-diagram-reader-controls';- toolbar.setAttribute('role', 'group');- toolbar.setAttribute('aria-label', english ? 'Diagram view' : '图表视图');- toolbar.style.cssText = `display:flex;flex-wrap:wrap;align-items:center;gap:6px;padding:8px 16px;color:${dark ? '#E8F2ED' : '#173B2E'};`;- const addButton = (label: string, action: () => void, aria = label) => {- const button = document.createElement('button');- button.type = 'button';- button.textContent = label;- button.setAttribute('aria-label', aria);- button.style.cssText = 'min-width:44px;min-height:44px;padding:8px;border:1px solid #7f9c8e;border-radius:8px;background:transparent;color:inherit;font:inherit;touch-action:manipulation;';- button.onclick = action;- toolbar.appendChild(button);- return button;- };+ const host = container.parentElement;+ host?.classList.add("edgeever-diagram-reader-host");const fit = () => {- graph.zoomToFit({ maxScale: 1, padding: 28 });- if (diagram.kind === 'flowchart' && graph.scale().sx < FLOWCHART_READABLE_MIN_SCALE) read();- else graph.centerContent();+ graph.zoomToFit({ maxScale: 1, padding: DIAGRAM_READER_FIT_PADDING });+ graph.centerContent();+ };+ const applyFocus = (node: ReaderBox, scale = 1) => {+ graph.zoomTo(scale);+ const next = diagramReaderFocusTranslate(node, { width, height }, diagram.kind, scale);+ graph.translate(next.tx, next.ty);};const read = () => {- const incoming = new Set(diagram.edges.map((edge) => edge.target));- const start = diagram.nodes.find((node) => !incoming.has(node.id)) ?? diagram.nodes[0];+ const start = diagramReaderFocusNode(diagram);if (!start) return;- graph.zoomTo(1);- graph.translate(width / 2 - start.x - start.width / 2, 32 - start.y);+ applyFocus(start, 1);+ };+ const update = () => { container.dataset.scale = `${Math.round(graph.scale().sx * 100)}`; };+ graph.on("scale", update);+ const onNodeFocus = (args?: { node?: ReaderNode }) => {+ const box = args?.node?.getBBox?.();+ if (!box) return;+ applyFocus(box, Math.max(1, graph.scale().sx));+ };+ graph.on("node:click", onNodeFocus);+ let pinch: { distance: number; scale: number } | null = null;+ const onTouchStart = (event: TouchEvent) => {+ if (event.touches.length === 2) {+ pinch = { distance: touchDistance(event.touches[0], event.touches[1]), scale: graph.scale().sx };+ graph.disablePanning?.();+ }};- addButton('−', () => graph.zoomTo(Math.max(0.1, graph.scale().sx / 1.25)), english ? 'Zoom out' : '缩小');- const percent = addButton('100%', () => { graph.zoomTo(1); graph.centerContent(); }, english ? 'Reset zoom to 100%' : '恢复 100%');- addButton('+', () => graph.zoomTo(Math.min(2.5, graph.scale().sx * 1.25)), english ? 'Zoom in' : '放大');- addButton(english ? 'Fit' : '适应画布', fit);- if (diagram.kind === 'flowchart') addButton(english ? 'Read from start' : '从起点阅读', read);- const hint = document.createElement('div');- hint.textContent = english ? 'Drag the diagram to explore. Use + / − to zoom.' : '拖动画布浏览,使用 + / − 缩放';- hint.style.cssText = 'flex-basis:100%;font-size:12px;opacity:.75;';- toolbar.appendChild(hint);- container.parentNode?.insertBefore(toolbar, container);- const update = () => { percent.textContent = `${Math.round(graph.scale().sx * 100)}%`; };- graph.on('scale', update);+ const onTouchMove = (event: TouchEvent) => {+ if (!pinch || event.touches.length !== 2) return;+ event.preventDefault();+ event.stopPropagation();+ const scale = diagramReaderPinchScale(pinch.scale, pinch.distance, touchDistance(event.touches[0], event.touches[1]));+ graph.zoomTo(scale, { center: touchCenter(event.touches[0], event.touches[1], container.getBoundingClientRect()) });+ };+ const onTouchEnd = (event: TouchEvent) => {+ if (event.touches.length < 2) {+ pinch = null;+ graph.enablePanning?.();+ }+ };+ container.addEventListener("touchstart", onTouchStart, { passive: true });+ container.addEventListener("touchmove", onTouchMove, { capture: true, passive: false });+ container.addEventListener("touchend", onTouchEnd);+ container.addEventListener("touchcancel", onTouchEnd);let width = 0;let height = 0;return {@@ -68,13 +137,26 @@ export const attachDiagramReader = (const previous = graph.translate();const dx = (nextWidth - width) / 2;const dy = (nextHeight - height) / 2;+ const relayout = first || (height < 80 && nextHeight >= 160);width = nextWidth; height = nextHeight;graph.resize(width, height);- if (first) {+ if (relayout) {fit();+ if (diagramReaderOpeningMode(graph.scale().sx) === "read") read();} else graph.translate(previous.tx + dx, previous.ty + dy);update();},- dispose() { detachScroll(); graph.off('scale', update); toolbar.remove(); },+ dispose() {+ detachScroll();+ graph.off("scale", update);+ graph.off("node:click", onNodeFocus);+ container.removeEventListener("touchstart", onTouchStart);+ container.removeEventListener("touchmove", onTouchMove, true);+ container.removeEventListener("touchend", onTouchEnd);+ container.removeEventListener("touchcancel", onTouchEnd);+ graph.enablePanning?.();+ host?.classList.remove("edgeever-diagram-reader-host");+ delete container.dataset.scale;+ },};};diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 2c129a5b..0b7748d9 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -41,6 +41,11 @@ export * from "./pdf-attachment";export * from "./types";export * from './plugin-capabilities';-export { attachDiagramReader } from "./diagram-reader";+export {+ attachDiagramReader,+ DIAGRAM_READER_MIN_SCALE,+ diagramReaderFocusNode,+ diagramReaderOpeningMode,+} from "./diagram-reader";export { attachDiagramScroll } from "./diagram-scroll";