@file-viewer/renderer-mindmap 2.0.11
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/LICENSE +160 -0
- package/README.en.md +40 -0
- package/README.md +40 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/dist/xmind.d.ts +2 -0
- package/dist/xmind.js +875 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work by
|
|
47
|
+
the copyright owner or by an individual or Legal Entity authorized to submit on
|
|
48
|
+
behalf of the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent to the
|
|
50
|
+
Licensor or its representatives, including but not limited to communication on
|
|
51
|
+
electronic mailing lists, source code control systems, and issue tracking systems
|
|
52
|
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
53
|
+
and improving the Work, but excluding communication that is conspicuously marked
|
|
54
|
+
or otherwise designated in writing by the copyright owner as "Not a
|
|
55
|
+
Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
62
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
63
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
64
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
65
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
66
|
+
Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
69
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
70
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
71
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
72
|
+
transfer the Work, where such license applies only to those patent claims
|
|
73
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
74
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
75
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
76
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
77
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
78
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
79
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
80
|
+
such litigation is filed.
|
|
81
|
+
|
|
82
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
83
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
84
|
+
Source or Object form, provided that You meet the following conditions:
|
|
85
|
+
|
|
86
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
87
|
+
this License; and
|
|
88
|
+
|
|
89
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
90
|
+
You changed the files; and
|
|
91
|
+
|
|
92
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
93
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
94
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
95
|
+
of the Derivative Works; and
|
|
96
|
+
|
|
97
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
98
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
99
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
100
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
101
|
+
following places: within a NOTICE text file distributed as part of the Derivative
|
|
102
|
+
Works; within the Source form or documentation, if provided along with the
|
|
103
|
+
Derivative Works; or, within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents of the NOTICE
|
|
105
|
+
file are for informational purposes only and do not modify the License. You may
|
|
106
|
+
add Your own attribution notices within Derivative Works that You distribute,
|
|
107
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that such
|
|
108
|
+
additional attribution notices cannot be construed as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
111
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
112
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
113
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
114
|
+
with the conditions stated in this License.
|
|
115
|
+
|
|
116
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
117
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
118
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
119
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
120
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
121
|
+
executed with Licensor regarding such Contributions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
124
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
125
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
126
|
+
reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
129
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
130
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
131
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
132
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
135
|
+
associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
138
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
139
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
140
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
141
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
142
|
+
arising as a result of this License or out of the use or inability to use the
|
|
143
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
144
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
145
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
146
|
+
damages.
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
150
|
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
|
151
|
+
rights consistent with this License. However, in accepting such obligations, You
|
|
152
|
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
|
153
|
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
|
154
|
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
|
155
|
+
such Contributor by reason of your accepting any such warranty or additional
|
|
156
|
+
liability.
|
|
157
|
+
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
Copyright 2026 Flyfish Viewer
|
package/README.en.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @file-viewer/renderer-mindmap
|
|
2
|
+
|
|
3
|
+
Standalone XMind and mind map renderer package for Flyfish File Viewer. It parses modern `content.json` and classic `content.xml` XMind files, then renders an interactive `@panzoom/panzoom` powered canvas with drag panning, mobile pinch zoom, keyboard panning, responsive viewport fitting, unified toolbar state sync, sheet tabs, and node navigation.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import FileViewer from '@file-viewer/vue3'
|
|
9
|
+
import { mindmapRenderer } from '@file-viewer/renderer-mindmap'
|
|
10
|
+
|
|
11
|
+
const options = {
|
|
12
|
+
rendererMode: 'replace',
|
|
13
|
+
renderers: mindmapRenderer,
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
You can combine it with other renderer packages:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
21
|
+
import { mindmapRenderer } from '@file-viewer/renderer-mindmap'
|
|
22
|
+
|
|
23
|
+
const options = {
|
|
24
|
+
rendererMode: 'replace',
|
|
25
|
+
renderers: [pdfRenderer, mindmapRenderer],
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Capabilities
|
|
30
|
+
|
|
31
|
+
- Supports `.xmind`.
|
|
32
|
+
- Supports XMind 2020+ `content.json` and XMind 8 / Classic `content.xml`.
|
|
33
|
+
- Supports multiple sheets, hierarchy, labels, notes, hyperlinks, image resource hints, summaries, callouts, and floating-topic states.
|
|
34
|
+
- Supports toolbar zoom, fit-to-canvas, Panzoom drag panning, requestAnimationFrame-coalesced pan updates, `Ctrl` / `Command` + wheel pointer zoom, arrow-key panning, and mobile pinch zoom.
|
|
35
|
+
- Auto-fits the canvas on first render and host resize; after a user pans, wheels, or zooms manually, the renderer preserves the current view and only clamps unsafe bounds.
|
|
36
|
+
- Release browser smoke runs a real `.xmind` pan regression across normal Pointer, node-start dragging, wheel panning, and real mouse drag paths, so the canvas cannot silently regress into a non-draggable preview.
|
|
37
|
+
|
|
38
|
+
## Migration Note
|
|
39
|
+
|
|
40
|
+
The core package no longer bundles the XMind parser and no longer installs `@ljheee/xmind-parser` by default. Install this renderer explicitly, or use `@file-viewer/preset-all`, when XMind preview is required.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @file-viewer/renderer-mindmap
|
|
2
|
+
|
|
3
|
+
Flyfish File Viewer 的独立 XMind / Mind Map renderer 包。它负责解析现代 `content.json` 和经典 `content.xml` XMind 文件,并使用轻量 `@panzoom/panzoom` 提供支持拖拽平移、移动端双指缩放、键盘平移、自适应容器尺寸、统一 toolbar 状态同步和定位的脑图画布。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import FileViewer from '@file-viewer/vue3'
|
|
9
|
+
import { mindmapRenderer } from '@file-viewer/renderer-mindmap'
|
|
10
|
+
|
|
11
|
+
const options = {
|
|
12
|
+
rendererMode: 'replace',
|
|
13
|
+
renderers: mindmapRenderer,
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
也可以和其他 renderer 一起组合:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
21
|
+
import { mindmapRenderer } from '@file-viewer/renderer-mindmap'
|
|
22
|
+
|
|
23
|
+
const options = {
|
|
24
|
+
rendererMode: 'replace',
|
|
25
|
+
renderers: [pdfRenderer, mindmapRenderer],
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 能力边界
|
|
30
|
+
|
|
31
|
+
- 支持 `.xmind`。
|
|
32
|
+
- 支持 XMind 2020+ 的 `content.json` 和 XMind 8 / Classic 的 `content.xml`。
|
|
33
|
+
- 支持多 sheet、节点层级、标签、备注、链接、图片资源提示、概要/标注/浮动节点状态。
|
|
34
|
+
- 支持工具栏缩放、适配画布、Panzoom 拖拽平移、移动端双指缩放、按帧合并平移更新、`Ctrl` / `Command` + 滚轮指针缩放、键盘方向键平移。
|
|
35
|
+
- 首次打开和容器尺寸变化时会自动适配视图;用户手动拖拽、滚轮或缩放后会保留当前画布视角,只做安全边界校正。
|
|
36
|
+
- 浏览器 smoke 会对 `.xmind` 样例执行真实 pan 回归,覆盖普通 Pointer、节点起手拖拽、滚轮平移和真实鼠标拖拽,避免画布再次退化成“能打开但拖不动”。
|
|
37
|
+
|
|
38
|
+
## 迁移说明
|
|
39
|
+
|
|
40
|
+
core 已不再内置 XMind 解析器,也不会默认安装 `@ljheee/xmind-parser`。需要 XMind 脑图预览时,请显式安装本包,或直接使用 `@file-viewer/preset-all` 聚合能力。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FileRenderHandler, type FileViewerRenderedInstance, type FileViewerRendererPlugin, type RendererDefinition } from '@file-viewer/core';
|
|
2
|
+
export declare const mindmapRendererDefinition: RendererDefinition;
|
|
3
|
+
export declare const renderFileViewerMindMap: FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
|
|
4
|
+
export declare const mindmapRenderer: FileViewerRendererPlugin<FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>>;
|
|
5
|
+
export default mindmapRenderer;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DEFAULT_RENDERER_DEFINITIONS, } from '@file-viewer/core';
|
|
2
|
+
const mindmapDefinition = DEFAULT_RENDERER_DEFINITIONS.find(definition => definition.id === 'mindmap');
|
|
3
|
+
if (!mindmapDefinition) {
|
|
4
|
+
throw new Error('@file-viewer/renderer-mindmap could not locate the core mind map renderer definition.');
|
|
5
|
+
}
|
|
6
|
+
export const mindmapRendererDefinition = mindmapDefinition;
|
|
7
|
+
export const renderFileViewerMindMap = (buffer, target, type, context) => import('./xmind.js').then(({ default: renderXMind }) => renderXMind(buffer, target, type, context));
|
|
8
|
+
export const mindmapRenderer = {
|
|
9
|
+
id: 'file-viewer-renderer-mindmap',
|
|
10
|
+
label: 'Flyfish File Viewer mind map renderer',
|
|
11
|
+
definitions: [mindmapRendererDefinition],
|
|
12
|
+
handlers: [{
|
|
13
|
+
rendererId: mindmapRendererDefinition.id,
|
|
14
|
+
handler: renderFileViewerMindMap,
|
|
15
|
+
}],
|
|
16
|
+
};
|
|
17
|
+
export default mindmapRenderer;
|
package/dist/xmind.d.ts
ADDED
package/dist/xmind.js
ADDED
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
import Panzoom, {} from '@panzoom/panzoom';
|
|
3
|
+
import { parseXmind8Xml, parseXmind2020Json, } from '@ljheee/xmind-parser';
|
|
4
|
+
import { createFileViewerZoomChangeEmitter, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
5
|
+
const NODE_WIDTH = 236;
|
|
6
|
+
const ROOT_WIDTH = 260;
|
|
7
|
+
const LEVEL_GAP = 112;
|
|
8
|
+
const SIBLING_GAP = 24;
|
|
9
|
+
const CANVAS_PADDING = 44;
|
|
10
|
+
const MAX_RENDER_NODES = 1800;
|
|
11
|
+
const PAN_CLICK_THRESHOLD = 5;
|
|
12
|
+
const PAN_BOUNDARY_MARGIN = 180;
|
|
13
|
+
const PAN_MIN_VISIBLE_RATIO = 0.08;
|
|
14
|
+
const PAN_MIN_VISIBLE_PX = 56;
|
|
15
|
+
const WHEEL_ZOOM_STEP = 0.12;
|
|
16
|
+
const KEYBOARD_PAN_STEP = 42;
|
|
17
|
+
const KEYBOARD_PAN_FAST_STEP = 96;
|
|
18
|
+
const CLICK_SUPPRESSION_MS = 120;
|
|
19
|
+
const PANZOOM_EXCLUDE_CLASS = 'xmind-pan-exclude';
|
|
20
|
+
const xmindStyle = `
|
|
21
|
+
.xmind-viewer{height:100%;min-height:0;display:flex;flex-direction:column;background:#eef3f7;color:#172033}
|
|
22
|
+
.xmind-viewer *{box-sizing:border-box}
|
|
23
|
+
.xmind-toolbar{min-height:62px;display:flex;align-items:center;justify-content:space-between;gap:14px;padding:12px 16px;border-bottom:1px solid rgba(23,32,51,.08);background:#fff}
|
|
24
|
+
.xmind-title{min-width:0}.xmind-title span{color:#159365;font-size:12px;font-weight:900}.xmind-title strong{display:block;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:18px}
|
|
25
|
+
.xmind-actions{display:flex;align-items:center;gap:8px}.xmind-actions button{min-width:34px;min-height:30px;border:0;border-radius:8px;background:rgba(15,23,42,.06);color:#26364d;cursor:pointer;font-size:12px;font-weight:900}.xmind-actions button:hover{background:rgba(33,163,102,.14);color:#0f8f62}.xmind-actions span{min-width:48px;color:#64748b;text-align:center;font-size:12px;font-weight:900}
|
|
26
|
+
.xmind-tabs{display:flex;min-height:46px;gap:8px;align-items:center;overflow:auto;padding:8px 12px;border-bottom:1px solid rgba(23,32,51,.08);background:#f8fafc}
|
|
27
|
+
.xmind-tabs button{min-height:30px;max-width:220px;flex:0 0 auto;border:1px solid rgba(148,163,184,.28);border-radius:999px;padding:0 12px;background:#fff;color:#475569;cursor:pointer;font-size:12px;font-weight:800;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.xmind-tabs button.active{border-color:rgba(33,163,102,.35);background:rgba(33,163,102,.12);color:#0f8f62}
|
|
28
|
+
.xmind-body{flex:1;min-height:0;display:grid;grid-template-columns:minmax(220px,280px) minmax(0,1fr)}
|
|
29
|
+
.xmind-sidebar{min-height:0;overflow:auto;border-right:1px solid rgba(23,32,51,.08);background:rgba(255,255,255,.72);padding:14px}
|
|
30
|
+
.xmind-stats{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:12px}.xmind-stats div{border-radius:12px;background:#fff;padding:10px;box-shadow:inset 0 0 0 1px rgba(23,32,51,.06)}.xmind-stats span{display:block;color:#718096;font-size:12px}.xmind-stats strong{display:block;margin-top:4px;font-size:18px;color:#172033}
|
|
31
|
+
.xmind-outline{display:flex;flex-direction:column;gap:6px}.xmind-outline button{display:block;width:100%;min-height:32px;border:0;border-radius:9px;background:transparent;color:#334155;cursor:pointer;font:inherit;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.xmind-outline button:hover{background:rgba(33,163,102,.1);color:#0f766e}
|
|
32
|
+
.xmind-stage{position:relative;min-width:0;min-height:0;overflow:hidden;cursor:grab;touch-action:none;overscroll-behavior:contain;user-select:none;-webkit-user-select:none;-webkit-user-drag:none;-webkit-tap-highlight-color:transparent;contain:layout paint;background:linear-gradient(90deg,rgba(15,23,42,.04) 1px,transparent 1px),linear-gradient(180deg,rgba(15,23,42,.04) 1px,transparent 1px),#f3f7fb;background-size:32px 32px;outline:none}
|
|
33
|
+
.xmind-stage *{touch-action:none;-webkit-user-drag:none}
|
|
34
|
+
.xmind-stage:focus-visible{box-shadow:inset 0 0 0 2px rgba(59,130,246,.42)}
|
|
35
|
+
.xmind-stage:active{cursor:grabbing}
|
|
36
|
+
.xmind-stage.is-panning,.xmind-stage.is-space-panning,.xmind-stage.is-panning *,.xmind-stage.is-space-panning *{cursor:grabbing!important;user-select:none}
|
|
37
|
+
.xmind-zoom-box{position:absolute;inset:0;transform-origin:top left;will-change:transform;cursor:inherit}.xmind-surface{position:absolute;left:0;top:0;transform-origin:top left;will-change:transform;cursor:inherit}.xmind-edges{position:absolute;inset:0;overflow:visible;pointer-events:none}.xmind-edges path{fill:none;stroke:#9db2c7;stroke-width:2.2;stroke-linecap:round}
|
|
38
|
+
.xmind-node{position:absolute;width:236px;min-height:58px;border:1px solid rgba(15,23,42,.1);border-radius:14px;padding:12px 12px 10px;background:#fff;box-shadow:0 12px 28px rgba(23,32,51,.11);color:#172033;cursor:grab;user-select:none;-webkit-user-select:none}
|
|
39
|
+
.xmind-node:active,.xmind-stage.is-panning .xmind-node{cursor:grabbing}
|
|
40
|
+
.xmind-node.root{width:260px;border-color:rgba(33,163,102,.28);background:linear-gradient(135deg,#effdf5,#fff);box-shadow:0 18px 38px rgba(33,163,102,.16)}
|
|
41
|
+
.xmind-node.detached{border-style:dashed}.xmind-node.summary{background:#fff8e7}.xmind-node.callout{background:#eef6ff}
|
|
42
|
+
.xmind-node h3{margin:0;color:#172033;font-size:14px;line-height:1.35;word-break:break-word}.xmind-node.root h3{font-size:16px}
|
|
43
|
+
.xmind-badges,.xmind-labels{display:flex;flex-wrap:wrap;gap:5px;margin-top:8px}.xmind-badges span,.xmind-labels span{max-width:100%;border-radius:999px;padding:3px 7px;font-size:11px;font-weight:800;line-height:1.3}.xmind-badges span{background:#eef6f7;color:#0b7480}.xmind-labels span{background:#edf2ff;color:#3557a5}
|
|
44
|
+
.xmind-note{margin:8px 0 0;color:#64748b;font-size:12px;line-height:1.45;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}.xmind-link{display:block;margin-top:8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#0f766e;font-size:12px;font-weight:800;text-decoration:none;cursor:pointer}.xmind-image{display:block;max-width:100%;max-height:96px;margin-top:8px;border-radius:8px;object-fit:contain;background:#f8fafc}
|
|
45
|
+
.xmind-stage.is-panning .xmind-link{pointer-events:none}
|
|
46
|
+
.xmind-state{position:absolute;inset:0;z-index:4;display:flex;align-items:center;justify-content:center;padding:24px;color:#64748b;font-weight:800;text-align:center;background:rgba(238,243,247,.88)}.xmind-state[hidden]{display:none!important}.xmind-state.error{color:#b42318}
|
|
47
|
+
.file-viewer[data-viewer-theme='dark'] .xmind-viewer{background:#111827;color:#e5eef8}.file-viewer[data-viewer-theme='dark'] .xmind-toolbar,.file-viewer[data-viewer-theme='dark'] .xmind-tabs,.file-viewer[data-viewer-theme='dark'] .xmind-sidebar{background:#fff;color:#172033}
|
|
48
|
+
@media (prefers-color-scheme:dark){.file-viewer[data-viewer-theme='system'] .xmind-viewer{background:#111827;color:#e5eef8}.file-viewer[data-viewer-theme='system'] .xmind-toolbar,.file-viewer[data-viewer-theme='system'] .xmind-tabs,.file-viewer[data-viewer-theme='system'] .xmind-sidebar{background:#fff;color:#172033}}
|
|
49
|
+
@media (max-width:860px){.xmind-body{grid-template-columns:1fr}.xmind-sidebar{display:none}.xmind-toolbar{align-items:flex-start;flex-direction:column}.xmind-actions{width:100%;justify-content:flex-end}}
|
|
50
|
+
`;
|
|
51
|
+
const createStyle = () => {
|
|
52
|
+
const style = document.createElement('style');
|
|
53
|
+
style.textContent = xmindStyle;
|
|
54
|
+
return style;
|
|
55
|
+
};
|
|
56
|
+
const createElement = (tagName, className, text) => {
|
|
57
|
+
const element = document.createElement(tagName);
|
|
58
|
+
if (className) {
|
|
59
|
+
element.className = className;
|
|
60
|
+
}
|
|
61
|
+
if (text !== undefined) {
|
|
62
|
+
element.textContent = text;
|
|
63
|
+
}
|
|
64
|
+
return element;
|
|
65
|
+
};
|
|
66
|
+
const clampZoom = (value) => Math.min(2.5, Math.max(0.25, Number(value.toFixed(2))));
|
|
67
|
+
const normalizeArray = (value) => Array.isArray(value) ? value : [];
|
|
68
|
+
const textValue = (value, fallback = '') => {
|
|
69
|
+
return typeof value === 'string' && value.trim() ? value.trim() : fallback;
|
|
70
|
+
};
|
|
71
|
+
const truncate = (value, max = 220) => {
|
|
72
|
+
return value.length > max ? `${value.slice(0, max - 1)}...` : value;
|
|
73
|
+
};
|
|
74
|
+
const estimateNodeHeight = (node) => {
|
|
75
|
+
const lineCount = Math.max(1, Math.ceil(node.title.length / 22));
|
|
76
|
+
let height = 34 + lineCount * 18;
|
|
77
|
+
if (node.labels.length || node.markers.length || node.priority || node.progress || node.collapsed || node.detached || node.summary || node.callout) {
|
|
78
|
+
height += 28;
|
|
79
|
+
}
|
|
80
|
+
if (node.note) {
|
|
81
|
+
height += Math.min(60, 18 + Math.ceil(node.note.length / 34) * 16);
|
|
82
|
+
}
|
|
83
|
+
if (node.hyperlink) {
|
|
84
|
+
height += 24;
|
|
85
|
+
}
|
|
86
|
+
if (node.image) {
|
|
87
|
+
height += 96;
|
|
88
|
+
}
|
|
89
|
+
return Math.max(58, height);
|
|
90
|
+
};
|
|
91
|
+
const createMindNode = (node, depth, indexPath, counter) => {
|
|
92
|
+
counter.value += 1;
|
|
93
|
+
const data = node.data || {};
|
|
94
|
+
const children = counter.value >= MAX_RENDER_NODES
|
|
95
|
+
? []
|
|
96
|
+
: normalizeArray(node.children).map((child, index) => createMindNode(child, depth + 1, `${indexPath}.${index + 1}`, counter));
|
|
97
|
+
const view = {
|
|
98
|
+
id: `xmind-node-${indexPath.replace(/[^a-z0-9]+/gi, '-')}`,
|
|
99
|
+
title: textValue(data.text, depth === 0 ? 'Central Topic' : 'Untitled Topic'),
|
|
100
|
+
labels: normalizeArray(data.label).map(item => String(item)).filter(Boolean),
|
|
101
|
+
markers: normalizeArray(data.markers).map(item => String(item)).filter(Boolean),
|
|
102
|
+
note: textValue(data.note),
|
|
103
|
+
hyperlink: textValue(data.hyperlink),
|
|
104
|
+
image: textValue(data.image),
|
|
105
|
+
priority: typeof data.priority === 'number' ? data.priority : undefined,
|
|
106
|
+
progress: typeof data.progress === 'number' ? data.progress : undefined,
|
|
107
|
+
structure: textValue(data['xmind-structure']),
|
|
108
|
+
collapsed: data.expandState === 'collapse',
|
|
109
|
+
detached: data['xmind-detached'] === true,
|
|
110
|
+
summary: data['xmind-summary'] === true,
|
|
111
|
+
callout: data['xmind-callout'] === true,
|
|
112
|
+
depth,
|
|
113
|
+
children,
|
|
114
|
+
x: 0,
|
|
115
|
+
y: 0,
|
|
116
|
+
width: depth === 0 ? ROOT_WIDTH : NODE_WIDTH,
|
|
117
|
+
height: 0,
|
|
118
|
+
subtreeHeight: 0,
|
|
119
|
+
};
|
|
120
|
+
view.height = estimateNodeHeight(view);
|
|
121
|
+
return view;
|
|
122
|
+
};
|
|
123
|
+
const walkMindNodes = (node, visit) => {
|
|
124
|
+
visit(node);
|
|
125
|
+
node.children.forEach(child => walkMindNodes(child, visit));
|
|
126
|
+
};
|
|
127
|
+
const computeSubtree = (node) => {
|
|
128
|
+
if (!node.children.length) {
|
|
129
|
+
node.subtreeHeight = node.height;
|
|
130
|
+
return node.subtreeHeight;
|
|
131
|
+
}
|
|
132
|
+
const childHeight = node.children.reduce((sum, child, index) => (sum + computeSubtree(child) + (index > 0 ? SIBLING_GAP : 0)), 0);
|
|
133
|
+
node.subtreeHeight = Math.max(node.height, childHeight);
|
|
134
|
+
return node.subtreeHeight;
|
|
135
|
+
};
|
|
136
|
+
const assignLayout = (node, top) => {
|
|
137
|
+
node.x = CANVAS_PADDING + node.depth * (NODE_WIDTH + LEVEL_GAP);
|
|
138
|
+
node.y = top + (node.subtreeHeight - node.height) / 2;
|
|
139
|
+
if (!node.children.length) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const childTotal = node.children.reduce((sum, child, index) => (sum + child.subtreeHeight + (index > 0 ? SIBLING_GAP : 0)), 0);
|
|
143
|
+
let childTop = top + (node.subtreeHeight - childTotal) / 2;
|
|
144
|
+
node.children.forEach(child => {
|
|
145
|
+
assignLayout(child, childTop);
|
|
146
|
+
childTop += child.subtreeHeight + SIBLING_GAP;
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
const createSheetView = (document, index) => {
|
|
150
|
+
const counter = { value: 0 };
|
|
151
|
+
const root = createMindNode(document.root || { data: { text: document.title || `Sheet ${index + 1}` } }, 0, String(index + 1), counter);
|
|
152
|
+
computeSubtree(root);
|
|
153
|
+
assignLayout(root, CANVAS_PADDING);
|
|
154
|
+
let maxDepth = 0;
|
|
155
|
+
let maxRight = 0;
|
|
156
|
+
let maxBottom = 0;
|
|
157
|
+
walkMindNodes(root, node => {
|
|
158
|
+
maxDepth = Math.max(maxDepth, node.depth);
|
|
159
|
+
maxRight = Math.max(maxRight, node.x + node.width);
|
|
160
|
+
maxBottom = Math.max(maxBottom, node.y + node.height);
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
title: textValue(document.title, `Sheet ${index + 1}`),
|
|
164
|
+
theme: textValue(document.theme, '-'),
|
|
165
|
+
template: textValue(document.template, '-'),
|
|
166
|
+
version: textValue(document.version, '-'),
|
|
167
|
+
root,
|
|
168
|
+
nodeCount: counter.value,
|
|
169
|
+
maxDepth,
|
|
170
|
+
width: Math.max(840, maxRight + CANVAS_PADDING),
|
|
171
|
+
height: Math.max(520, maxBottom + CANVAS_PADDING),
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
const loadXMindSheets = async (buffer) => {
|
|
175
|
+
const zip = await JSZip.loadAsync(buffer);
|
|
176
|
+
const resources = {};
|
|
177
|
+
const resourceTasks = [];
|
|
178
|
+
zip.forEach((path, entry) => {
|
|
179
|
+
if (entry.dir || (!path.startsWith('resources/') && !path.startsWith('attachments/'))) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
resourceTasks.push(entry.async('uint8array').then(bytes => {
|
|
183
|
+
resources[path] = bytes;
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
await Promise.all(resourceTasks);
|
|
187
|
+
const parserOptions = {
|
|
188
|
+
resources: Object.keys(resources).length ? resources : null,
|
|
189
|
+
};
|
|
190
|
+
const contentJson = zip.file(/(^|\/)content\.json$/i)[0];
|
|
191
|
+
if (contentJson) {
|
|
192
|
+
return await parseXmind2020Json(await contentJson.async('text'), parserOptions);
|
|
193
|
+
}
|
|
194
|
+
const contentXml = zip.file(/(^|\/)content\.xml$/i)[0];
|
|
195
|
+
if (contentXml) {
|
|
196
|
+
const commentsXml = zip.file(/(^|\/)comments\.xml$/i)[0];
|
|
197
|
+
return await parseXmind8Xml(await contentXml.async('text'), {
|
|
198
|
+
...parserOptions,
|
|
199
|
+
commentsXml: commentsXml ? await commentsXml.async('text') : undefined,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
throw new Error('无法识别 XMind 文件: ZIP 中未找到 content.json 或 content.xml');
|
|
203
|
+
};
|
|
204
|
+
const badgeTexts = (node) => {
|
|
205
|
+
const badges = [];
|
|
206
|
+
if (node.priority) {
|
|
207
|
+
badges.push(`P${node.priority}`);
|
|
208
|
+
}
|
|
209
|
+
if (node.progress) {
|
|
210
|
+
badges.push(node.progress === 10 ? '暂停' : `${Math.min(100, Math.round((node.progress / 9) * 100))}%`);
|
|
211
|
+
}
|
|
212
|
+
if (node.collapsed) {
|
|
213
|
+
badges.push('折叠');
|
|
214
|
+
}
|
|
215
|
+
if (node.detached) {
|
|
216
|
+
badges.push('浮动');
|
|
217
|
+
}
|
|
218
|
+
if (node.summary) {
|
|
219
|
+
badges.push('概要');
|
|
220
|
+
}
|
|
221
|
+
if (node.callout) {
|
|
222
|
+
badges.push('标注');
|
|
223
|
+
}
|
|
224
|
+
node.markers.slice(0, 4).forEach(marker => badges.push(marker));
|
|
225
|
+
return badges;
|
|
226
|
+
};
|
|
227
|
+
const createEdgePath = (parent, child) => {
|
|
228
|
+
const startX = parent.x + parent.width;
|
|
229
|
+
const startY = parent.y + parent.height / 2;
|
|
230
|
+
const endX = child.x;
|
|
231
|
+
const endY = child.y + child.height / 2;
|
|
232
|
+
const handle = Math.max(48, (endX - startX) * 0.48);
|
|
233
|
+
return `M${startX} ${startY} C${startX + handle} ${startY}, ${endX - handle} ${endY}, ${endX} ${endY}`;
|
|
234
|
+
};
|
|
235
|
+
const renderEdges = (svg, node) => {
|
|
236
|
+
node.children.forEach(child => {
|
|
237
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
238
|
+
path.setAttribute('d', createEdgePath(node, child));
|
|
239
|
+
svg.append(path);
|
|
240
|
+
renderEdges(svg, child);
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
const createNodeElement = (node, scrollToNode, shouldSuppressClick) => {
|
|
244
|
+
const card = createElement('article', [
|
|
245
|
+
'xmind-node',
|
|
246
|
+
node.depth === 0 ? 'root' : '',
|
|
247
|
+
node.detached ? 'detached' : '',
|
|
248
|
+
node.summary ? 'summary' : '',
|
|
249
|
+
node.callout ? 'callout' : '',
|
|
250
|
+
].filter(Boolean).join(' '));
|
|
251
|
+
card.id = node.id;
|
|
252
|
+
card.style.left = `${node.x}px`;
|
|
253
|
+
card.style.top = `${node.y}px`;
|
|
254
|
+
card.style.width = `${node.width}px`;
|
|
255
|
+
card.style.minHeight = `${node.height}px`;
|
|
256
|
+
card.append(createElement('h3', undefined, node.title));
|
|
257
|
+
const badges = badgeTexts(node);
|
|
258
|
+
if (badges.length) {
|
|
259
|
+
const badgeList = createElement('div', 'xmind-badges');
|
|
260
|
+
badges.forEach(item => badgeList.append(createElement('span', undefined, item)));
|
|
261
|
+
card.append(badgeList);
|
|
262
|
+
}
|
|
263
|
+
if (node.labels.length) {
|
|
264
|
+
const labelList = createElement('div', 'xmind-labels');
|
|
265
|
+
node.labels.slice(0, 8).forEach(item => labelList.append(createElement('span', undefined, item)));
|
|
266
|
+
card.append(labelList);
|
|
267
|
+
}
|
|
268
|
+
if (node.note) {
|
|
269
|
+
card.append(createElement('p', 'xmind-note', truncate(node.note)));
|
|
270
|
+
}
|
|
271
|
+
if (node.image) {
|
|
272
|
+
if (/^data:image\//i.test(node.image) || /^https?:\/\//i.test(node.image)) {
|
|
273
|
+
const image = document.createElement('img');
|
|
274
|
+
image.className = 'xmind-image';
|
|
275
|
+
image.alt = node.title;
|
|
276
|
+
image.src = node.image;
|
|
277
|
+
image.draggable = false;
|
|
278
|
+
card.append(image);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
card.append(createElement('p', 'xmind-note', `图片资源: ${node.image}`));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (node.hyperlink) {
|
|
285
|
+
const link = document.createElement('a');
|
|
286
|
+
link.className = `xmind-link ${PANZOOM_EXCLUDE_CLASS}`;
|
|
287
|
+
link.textContent = node.hyperlink;
|
|
288
|
+
link.href = node.hyperlink.startsWith('http') ? node.hyperlink : '#';
|
|
289
|
+
link.target = '_blank';
|
|
290
|
+
link.rel = 'noreferrer';
|
|
291
|
+
link.draggable = false;
|
|
292
|
+
card.append(link);
|
|
293
|
+
}
|
|
294
|
+
card.addEventListener('click', event => {
|
|
295
|
+
if (shouldSuppressClick()) {
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
event.stopPropagation();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
scrollToNode(node);
|
|
301
|
+
});
|
|
302
|
+
return card;
|
|
303
|
+
};
|
|
304
|
+
export default async function renderXMind(buffer, target, _type = 'xmind', context) {
|
|
305
|
+
const zoomEmitter = createFileViewerZoomChangeEmitter();
|
|
306
|
+
let status = 'loading';
|
|
307
|
+
let errorMessage = '';
|
|
308
|
+
let zoom = 1;
|
|
309
|
+
let panX = 0;
|
|
310
|
+
let panY = 0;
|
|
311
|
+
let disposed = false;
|
|
312
|
+
let activeSheetIndex = 0;
|
|
313
|
+
let sheets = [];
|
|
314
|
+
let suppressNodeClick = false;
|
|
315
|
+
let spacePanning = false;
|
|
316
|
+
let userAdjustedViewport = false;
|
|
317
|
+
let resizeFrame;
|
|
318
|
+
let panzoom = null;
|
|
319
|
+
let programmaticPanzoomUpdate = false;
|
|
320
|
+
let panStartState = null;
|
|
321
|
+
const root = createElement('section', 'xmind-viewer');
|
|
322
|
+
root.dataset.viewerZoomProvider = 'xmind';
|
|
323
|
+
const toolbar = createElement('header', 'xmind-toolbar');
|
|
324
|
+
const title = createElement('div', 'xmind-title');
|
|
325
|
+
title.append(createElement('span', undefined, 'XMIND MIND MAP'), createElement('strong', undefined, (context === null || context === void 0 ? void 0 : context.filename) || 'XMind'));
|
|
326
|
+
const actions = createElement('div', 'xmind-actions');
|
|
327
|
+
const zoomOutButton = createElement('button', undefined, '-');
|
|
328
|
+
const zoomLabel = createElement('span', undefined, '100%');
|
|
329
|
+
const zoomInButton = createElement('button', undefined, '+');
|
|
330
|
+
const resetButton = createElement('button', undefined, '适合');
|
|
331
|
+
[zoomOutButton, zoomInButton, resetButton].forEach(button => {
|
|
332
|
+
button.type = 'button';
|
|
333
|
+
});
|
|
334
|
+
zoomOutButton.title = '缩小';
|
|
335
|
+
zoomInButton.title = '放大';
|
|
336
|
+
resetButton.title = '适配画布';
|
|
337
|
+
actions.append(zoomOutButton, zoomLabel, zoomInButton, resetButton);
|
|
338
|
+
toolbar.append(title, actions);
|
|
339
|
+
const tabs = createElement('nav', 'xmind-tabs');
|
|
340
|
+
const body = createElement('div', 'xmind-body');
|
|
341
|
+
const sidebar = createElement('aside', 'xmind-sidebar');
|
|
342
|
+
const stage = createElement('main', 'xmind-stage');
|
|
343
|
+
const ownerDocument = target.ownerDocument || document;
|
|
344
|
+
const ownerWindow = ownerDocument.defaultView || window;
|
|
345
|
+
stage.tabIndex = 0;
|
|
346
|
+
stage.setAttribute('role', 'application');
|
|
347
|
+
stage.setAttribute('aria-label', 'XMind canvas. Drag to pan, pinch on touch screens to zoom, double click to fit, use Ctrl or Command with wheel to zoom.');
|
|
348
|
+
stage.setAttribute('aria-keyshortcuts', 'Space ArrowLeft ArrowRight ArrowUp ArrowDown Control+0 Meta+0');
|
|
349
|
+
const zoomBox = createElement('div', 'xmind-zoom-box');
|
|
350
|
+
const surface = createElement('div', 'xmind-surface');
|
|
351
|
+
const state = createElement('div', 'xmind-state', '正在解析 XMind 脑图...');
|
|
352
|
+
zoomBox.append(surface);
|
|
353
|
+
stage.append(zoomBox, state);
|
|
354
|
+
body.append(sidebar, stage);
|
|
355
|
+
root.append(toolbar, tabs, body);
|
|
356
|
+
target.replaceChildren(createStyle(), root);
|
|
357
|
+
const getZoomState = () => ({
|
|
358
|
+
scale: zoom,
|
|
359
|
+
label: `${Math.round(zoom * 100)}%`,
|
|
360
|
+
canZoomIn: zoom < 2.5,
|
|
361
|
+
canZoomOut: zoom > 0.25,
|
|
362
|
+
canReset: zoom !== 1 || panX !== 0 || panY !== 0,
|
|
363
|
+
minScale: 0.25,
|
|
364
|
+
maxScale: 2.5,
|
|
365
|
+
});
|
|
366
|
+
const clampPan = () => {
|
|
367
|
+
const sheet = sheets[activeSheetIndex];
|
|
368
|
+
if (!sheet) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const viewportWidth = Math.max(1, stage.clientWidth);
|
|
372
|
+
const viewportHeight = Math.max(1, stage.clientHeight);
|
|
373
|
+
const scaledWidth = sheet.width * zoom;
|
|
374
|
+
const scaledHeight = sheet.height * zoom;
|
|
375
|
+
const resolveBounds = (viewportSize, contentSize) => {
|
|
376
|
+
if (contentSize <= viewportSize) {
|
|
377
|
+
const centered = (viewportSize - contentSize) / 2;
|
|
378
|
+
const slack = Math.max(PAN_BOUNDARY_MARGIN, viewportSize * 0.45);
|
|
379
|
+
return {
|
|
380
|
+
min: centered - slack,
|
|
381
|
+
max: centered + slack,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const visibleEdge = Math.min(Math.max(PAN_MIN_VISIBLE_PX, viewportSize * PAN_MIN_VISIBLE_RATIO), Math.max(PAN_MIN_VISIBLE_PX, contentSize * 0.35));
|
|
385
|
+
return {
|
|
386
|
+
min: visibleEdge - contentSize,
|
|
387
|
+
max: viewportSize - visibleEdge,
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
const xBounds = resolveBounds(viewportWidth, scaledWidth);
|
|
391
|
+
const yBounds = resolveBounds(viewportHeight, scaledHeight);
|
|
392
|
+
panX = Math.min(xBounds.max, Math.max(xBounds.min, panX));
|
|
393
|
+
panY = Math.min(yBounds.max, Math.max(yBounds.min, panY));
|
|
394
|
+
};
|
|
395
|
+
const syncPanzoomState = (markUserAdjusted) => {
|
|
396
|
+
if (!panzoom) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const pan = panzoom.getPan();
|
|
400
|
+
panX = Number.isFinite(pan.x) ? pan.x : panX;
|
|
401
|
+
panY = Number.isFinite(pan.y) ? pan.y : panY;
|
|
402
|
+
zoom = clampZoom(panzoom.getScale());
|
|
403
|
+
zoomLabel.textContent = `${Math.round(zoom * 100)}%`;
|
|
404
|
+
if (markUserAdjusted) {
|
|
405
|
+
userAdjustedViewport = true;
|
|
406
|
+
}
|
|
407
|
+
zoomEmitter.emit();
|
|
408
|
+
};
|
|
409
|
+
const updatePanzoom = (update) => {
|
|
410
|
+
programmaticPanzoomUpdate = true;
|
|
411
|
+
try {
|
|
412
|
+
update();
|
|
413
|
+
}
|
|
414
|
+
finally {
|
|
415
|
+
programmaticPanzoomUpdate = false;
|
|
416
|
+
}
|
|
417
|
+
syncPanzoomState(false);
|
|
418
|
+
};
|
|
419
|
+
const applyZoom = () => {
|
|
420
|
+
const sheet = sheets[activeSheetIndex];
|
|
421
|
+
if (sheet) {
|
|
422
|
+
zoomBox.style.width = `${sheet.width}px`;
|
|
423
|
+
zoomBox.style.height = `${sheet.height}px`;
|
|
424
|
+
surface.style.width = `${sheet.width}px`;
|
|
425
|
+
surface.style.height = `${sheet.height}px`;
|
|
426
|
+
}
|
|
427
|
+
clampPan();
|
|
428
|
+
surface.style.transform = '';
|
|
429
|
+
if (panzoom) {
|
|
430
|
+
updatePanzoom(() => {
|
|
431
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.zoom(zoom, { animate: false, force: true });
|
|
432
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.pan(panX, panY, { animate: false, force: true });
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
zoomBox.style.transform = `translate3d(${panX}px, ${panY}px, 0) scale(${zoom})`;
|
|
437
|
+
}
|
|
438
|
+
zoomLabel.textContent = `${Math.round(zoom * 100)}%`;
|
|
439
|
+
};
|
|
440
|
+
const setZoom = (scale) => {
|
|
441
|
+
userAdjustedViewport = true;
|
|
442
|
+
zoom = clampZoom(scale);
|
|
443
|
+
applyZoom();
|
|
444
|
+
zoomEmitter.emit();
|
|
445
|
+
return getZoomState();
|
|
446
|
+
};
|
|
447
|
+
const setZoomAtPoint = (scale, clientX, clientY) => {
|
|
448
|
+
const nextZoom = clampZoom(scale);
|
|
449
|
+
if (nextZoom === zoom) {
|
|
450
|
+
return getZoomState();
|
|
451
|
+
}
|
|
452
|
+
userAdjustedViewport = true;
|
|
453
|
+
if (panzoom) {
|
|
454
|
+
updatePanzoom(() => {
|
|
455
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.zoomToPoint(nextZoom, { clientX, clientY }, { animate: false, force: true });
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
const rect = stage.getBoundingClientRect();
|
|
460
|
+
const viewportX = clientX - rect.left;
|
|
461
|
+
const viewportY = clientY - rect.top;
|
|
462
|
+
const logicalX = (viewportX - panX) / zoom;
|
|
463
|
+
const logicalY = (viewportY - panY) / zoom;
|
|
464
|
+
zoom = nextZoom;
|
|
465
|
+
panX = viewportX - logicalX * zoom;
|
|
466
|
+
panY = viewportY - logicalY * zoom;
|
|
467
|
+
applyZoom();
|
|
468
|
+
zoomEmitter.emit();
|
|
469
|
+
}
|
|
470
|
+
return getZoomState();
|
|
471
|
+
};
|
|
472
|
+
const setZoomAtStageCenter = (scale) => {
|
|
473
|
+
const rect = stage.getBoundingClientRect();
|
|
474
|
+
return setZoomAtPoint(scale, rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
475
|
+
};
|
|
476
|
+
const fitSheetToStage = (markAsUserReset = false) => {
|
|
477
|
+
const sheet = sheets[activeSheetIndex];
|
|
478
|
+
if (!sheet) {
|
|
479
|
+
return getZoomState();
|
|
480
|
+
}
|
|
481
|
+
userAdjustedViewport = markAsUserReset ? false : userAdjustedViewport;
|
|
482
|
+
const availableWidth = Math.max(1, stage.clientWidth - CANVAS_PADDING);
|
|
483
|
+
const availableHeight = Math.max(1, stage.clientHeight - CANVAS_PADDING);
|
|
484
|
+
const fitScale = Math.min(1, availableWidth / sheet.width, availableHeight / sheet.height);
|
|
485
|
+
zoom = clampZoom(fitScale);
|
|
486
|
+
panX = (stage.clientWidth - sheet.width * zoom) / 2;
|
|
487
|
+
panY = (stage.clientHeight - sheet.height * zoom) / 2;
|
|
488
|
+
applyZoom();
|
|
489
|
+
zoomEmitter.emit();
|
|
490
|
+
return getZoomState();
|
|
491
|
+
};
|
|
492
|
+
const scrollToNode = (node) => {
|
|
493
|
+
userAdjustedViewport = true;
|
|
494
|
+
panX = stage.clientWidth / 2 - (node.x + node.width / 2) * zoom;
|
|
495
|
+
panY = stage.clientHeight / 2 - (node.y + node.height / 2) * zoom;
|
|
496
|
+
applyZoom();
|
|
497
|
+
zoomEmitter.emit();
|
|
498
|
+
};
|
|
499
|
+
const renderSidebar = (sheet) => {
|
|
500
|
+
sidebar.replaceChildren();
|
|
501
|
+
const stats = createElement('div', 'xmind-stats');
|
|
502
|
+
[
|
|
503
|
+
['节点', sheet.nodeCount],
|
|
504
|
+
['层级', sheet.maxDepth + 1],
|
|
505
|
+
['主题', sheet.theme],
|
|
506
|
+
['模板', sheet.template],
|
|
507
|
+
].forEach(([label, value]) => {
|
|
508
|
+
const cell = document.createElement('div');
|
|
509
|
+
cell.append(createElement('span', undefined, String(label)), createElement('strong', undefined, String(value)));
|
|
510
|
+
stats.append(cell);
|
|
511
|
+
});
|
|
512
|
+
sidebar.append(stats);
|
|
513
|
+
const outline = createElement('div', 'xmind-outline');
|
|
514
|
+
walkMindNodes(sheet.root, node => {
|
|
515
|
+
const item = createElement('button', undefined, `${' '.repeat(node.depth)}${node.title}`);
|
|
516
|
+
item.type = 'button';
|
|
517
|
+
item.style.paddingLeft = `${8 + node.depth * 14}px`;
|
|
518
|
+
item.addEventListener('click', () => scrollToNode(node));
|
|
519
|
+
outline.append(item);
|
|
520
|
+
});
|
|
521
|
+
sidebar.append(outline);
|
|
522
|
+
};
|
|
523
|
+
const renderSheet = () => {
|
|
524
|
+
const sheet = sheets[activeSheetIndex];
|
|
525
|
+
if (!sheet) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
surface.replaceChildren();
|
|
529
|
+
userAdjustedViewport = false;
|
|
530
|
+
surface.style.width = `${sheet.width}px`;
|
|
531
|
+
surface.style.height = `${sheet.height}px`;
|
|
532
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
533
|
+
svg.classList.add('xmind-edges');
|
|
534
|
+
svg.setAttribute('width', String(sheet.width));
|
|
535
|
+
svg.setAttribute('height', String(sheet.height));
|
|
536
|
+
svg.setAttribute('viewBox', `0 0 ${sheet.width} ${sheet.height}`);
|
|
537
|
+
renderEdges(svg, sheet.root);
|
|
538
|
+
surface.append(svg);
|
|
539
|
+
walkMindNodes(sheet.root, node => {
|
|
540
|
+
surface.append(createNodeElement(node, scrollToNode, () => suppressNodeClick));
|
|
541
|
+
});
|
|
542
|
+
renderSidebar(sheet);
|
|
543
|
+
applyZoom();
|
|
544
|
+
requestAnimationFrame(() => fitSheetToStage());
|
|
545
|
+
};
|
|
546
|
+
const renderTabs = () => {
|
|
547
|
+
tabs.replaceChildren();
|
|
548
|
+
sheets.forEach((sheet, index) => {
|
|
549
|
+
const button = createElement('button', index === activeSheetIndex ? 'active' : '', sheet.title);
|
|
550
|
+
button.type = 'button';
|
|
551
|
+
button.title = sheet.title;
|
|
552
|
+
button.addEventListener('click', () => {
|
|
553
|
+
activeSheetIndex = index;
|
|
554
|
+
renderTabs();
|
|
555
|
+
renderSheet();
|
|
556
|
+
});
|
|
557
|
+
tabs.append(button);
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
const syncState = () => {
|
|
561
|
+
state.hidden = status === 'ready';
|
|
562
|
+
state.classList.toggle('error', status === 'error');
|
|
563
|
+
state.textContent = status === 'error'
|
|
564
|
+
? errorMessage
|
|
565
|
+
: '正在解析 XMind 脑图...';
|
|
566
|
+
};
|
|
567
|
+
const load = async () => {
|
|
568
|
+
status = 'loading';
|
|
569
|
+
errorMessage = '';
|
|
570
|
+
syncState();
|
|
571
|
+
try {
|
|
572
|
+
const parsed = await loadXMindSheets(buffer);
|
|
573
|
+
if (disposed) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (!Array.isArray(parsed) || !parsed.length) {
|
|
577
|
+
throw new Error('XMind 文件中没有可预览的画布');
|
|
578
|
+
}
|
|
579
|
+
sheets = parsed.map(createSheetView);
|
|
580
|
+
activeSheetIndex = 0;
|
|
581
|
+
renderTabs();
|
|
582
|
+
renderSheet();
|
|
583
|
+
status = 'ready';
|
|
584
|
+
syncState();
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
if (disposed) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
console.error(error);
|
|
591
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
592
|
+
status = 'error';
|
|
593
|
+
syncState();
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
registerFileViewerZoomProvider(root, {
|
|
597
|
+
zoomIn: () => setZoomAtStageCenter(zoom + 0.15),
|
|
598
|
+
zoomOut: () => setZoomAtStageCenter(zoom - 0.15),
|
|
599
|
+
resetZoom: () => fitSheetToStage(true),
|
|
600
|
+
setZoom,
|
|
601
|
+
getState: getZoomState,
|
|
602
|
+
subscribe: zoomEmitter.subscribe,
|
|
603
|
+
});
|
|
604
|
+
const getPanTargetElement = (targetValue) => {
|
|
605
|
+
const ElementCtor = ownerWindow.Element || Element;
|
|
606
|
+
return targetValue instanceof ElementCtor ? targetValue : null;
|
|
607
|
+
};
|
|
608
|
+
const isPanBlockedTarget = (targetValue) => {
|
|
609
|
+
const element = getPanTargetElement(targetValue);
|
|
610
|
+
if (!element) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
if (element.closest('.xmind-toolbar,.xmind-tabs,.xmind-sidebar')) {
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
const interactive = element.closest('a,button,input,textarea,select,[contenteditable="true"]');
|
|
617
|
+
return Boolean(interactive && !interactive.closest('.xmind-node'));
|
|
618
|
+
};
|
|
619
|
+
const shouldPreventPanStartDefault = (targetValue) => {
|
|
620
|
+
const element = getPanTargetElement(targetValue);
|
|
621
|
+
return !(element === null || element === void 0 ? void 0 : element.closest('a[href],button,input,textarea,select,[contenteditable="true"]'));
|
|
622
|
+
};
|
|
623
|
+
const setSpacePanning = (enabled) => {
|
|
624
|
+
spacePanning = enabled;
|
|
625
|
+
stage.classList.toggle('is-space-panning', enabled);
|
|
626
|
+
};
|
|
627
|
+
const focusStage = () => {
|
|
628
|
+
try {
|
|
629
|
+
stage.focus({ preventScroll: true });
|
|
630
|
+
}
|
|
631
|
+
catch {
|
|
632
|
+
try {
|
|
633
|
+
stage.focus();
|
|
634
|
+
}
|
|
635
|
+
catch {
|
|
636
|
+
// Some embedded WebViews expose focus but reject focus options.
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const suppressNextNodeClick = () => {
|
|
641
|
+
suppressNodeClick = true;
|
|
642
|
+
ownerWindow.setTimeout(() => {
|
|
643
|
+
suppressNodeClick = false;
|
|
644
|
+
}, CLICK_SUPPRESSION_MS);
|
|
645
|
+
};
|
|
646
|
+
const onPanzoomStart = () => {
|
|
647
|
+
focusStage();
|
|
648
|
+
panStartState = { x: panX, y: panY, scale: zoom };
|
|
649
|
+
stage.classList.add('is-panning');
|
|
650
|
+
};
|
|
651
|
+
const onPanzoomChange = () => {
|
|
652
|
+
syncPanzoomState(!programmaticPanzoomUpdate);
|
|
653
|
+
};
|
|
654
|
+
const onPanzoomEnd = () => {
|
|
655
|
+
syncPanzoomState(!programmaticPanzoomUpdate);
|
|
656
|
+
stage.classList.remove('is-panning');
|
|
657
|
+
if (panStartState) {
|
|
658
|
+
const moved = Math.abs(panX - panStartState.x) +
|
|
659
|
+
Math.abs(panY - panStartState.y) +
|
|
660
|
+
Math.abs(zoom - panStartState.scale) * 100;
|
|
661
|
+
if (moved > PAN_CLICK_THRESHOLD) {
|
|
662
|
+
suppressNextNodeClick();
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
panStartState = null;
|
|
666
|
+
};
|
|
667
|
+
const initializePanzoom = () => {
|
|
668
|
+
panzoom = Panzoom(zoomBox, {
|
|
669
|
+
canvas: true,
|
|
670
|
+
cursor: 'grab',
|
|
671
|
+
minScale: 0.25,
|
|
672
|
+
maxScale: 2.5,
|
|
673
|
+
step: 0.15,
|
|
674
|
+
animate: false,
|
|
675
|
+
origin: '0 0',
|
|
676
|
+
touchAction: 'none',
|
|
677
|
+
excludeClass: PANZOOM_EXCLUDE_CLASS,
|
|
678
|
+
handleStartEvent: event => {
|
|
679
|
+
if (status !== 'ready' || (!spacePanning && isPanBlockedTarget(event.target))) {
|
|
680
|
+
event.preventDefault();
|
|
681
|
+
event.stopPropagation();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (shouldPreventPanStartDefault(event.target)) {
|
|
685
|
+
event.preventDefault();
|
|
686
|
+
}
|
|
687
|
+
event.stopPropagation();
|
|
688
|
+
focusStage();
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
zoomBox.addEventListener('panzoomstart', onPanzoomStart);
|
|
692
|
+
zoomBox.addEventListener('panzoomchange', onPanzoomChange);
|
|
693
|
+
zoomBox.addEventListener('panzoomend', onPanzoomEnd);
|
|
694
|
+
applyZoom();
|
|
695
|
+
};
|
|
696
|
+
const onStageWheel = (event) => {
|
|
697
|
+
if (status !== 'ready') {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
event.preventDefault();
|
|
701
|
+
if (!event.ctrlKey && !event.metaKey) {
|
|
702
|
+
userAdjustedViewport = true;
|
|
703
|
+
if (panzoom) {
|
|
704
|
+
updatePanzoom(() => {
|
|
705
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.pan(-event.deltaX, -event.deltaY, {
|
|
706
|
+
animate: false,
|
|
707
|
+
force: true,
|
|
708
|
+
relative: true,
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
panX -= event.deltaX;
|
|
714
|
+
panY -= event.deltaY;
|
|
715
|
+
applyZoom();
|
|
716
|
+
zoomEmitter.emit();
|
|
717
|
+
}
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const direction = event.deltaY > 0 ? -1 : 1;
|
|
721
|
+
setZoomAtPoint(zoom + direction * WHEEL_ZOOM_STEP, event.clientX, event.clientY);
|
|
722
|
+
};
|
|
723
|
+
const onStageKeyDown = (event) => {
|
|
724
|
+
if (status !== 'ready') {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const step = event.shiftKey ? KEYBOARD_PAN_FAST_STEP : KEYBOARD_PAN_STEP;
|
|
728
|
+
if (event.key === ' ') {
|
|
729
|
+
setSpacePanning(true);
|
|
730
|
+
event.preventDefault();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (event.key === 'ArrowLeft') {
|
|
734
|
+
userAdjustedViewport = true;
|
|
735
|
+
panX += step;
|
|
736
|
+
}
|
|
737
|
+
else if (event.key === 'ArrowRight') {
|
|
738
|
+
userAdjustedViewport = true;
|
|
739
|
+
panX -= step;
|
|
740
|
+
}
|
|
741
|
+
else if (event.key === 'ArrowUp') {
|
|
742
|
+
userAdjustedViewport = true;
|
|
743
|
+
panY += step;
|
|
744
|
+
}
|
|
745
|
+
else if (event.key === 'ArrowDown') {
|
|
746
|
+
userAdjustedViewport = true;
|
|
747
|
+
panY -= step;
|
|
748
|
+
}
|
|
749
|
+
else if ((event.key === '0' || event.key === 'Home') && (event.ctrlKey || event.metaKey)) {
|
|
750
|
+
fitSheetToStage(true);
|
|
751
|
+
event.preventDefault();
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (panzoom) {
|
|
758
|
+
updatePanzoom(() => {
|
|
759
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.pan(panX, panY, { animate: false, force: true });
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
applyZoom();
|
|
764
|
+
zoomEmitter.emit();
|
|
765
|
+
}
|
|
766
|
+
event.preventDefault();
|
|
767
|
+
};
|
|
768
|
+
const onStageKeyUp = (event) => {
|
|
769
|
+
if (event.key === ' ') {
|
|
770
|
+
setSpacePanning(false);
|
|
771
|
+
event.preventDefault();
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
const onStageDblClick = (event) => {
|
|
775
|
+
if (status !== 'ready' || isPanBlockedTarget(event.target)) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
fitSheetToStage(true);
|
|
779
|
+
event.preventDefault();
|
|
780
|
+
};
|
|
781
|
+
const onStageDragStart = (event) => {
|
|
782
|
+
event.preventDefault();
|
|
783
|
+
};
|
|
784
|
+
const onStageContextMenu = (event) => {
|
|
785
|
+
if (stage.classList.contains('is-panning')) {
|
|
786
|
+
event.preventDefault();
|
|
787
|
+
event.stopPropagation();
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const onStageSelectStart = (event) => {
|
|
791
|
+
if (stage.classList.contains('is-panning')) {
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const stopPanInteractions = () => {
|
|
796
|
+
panStartState = null;
|
|
797
|
+
stage.classList.remove('is-panning');
|
|
798
|
+
setSpacePanning(false);
|
|
799
|
+
};
|
|
800
|
+
const onDocumentVisibilityChange = () => {
|
|
801
|
+
if (ownerDocument.visibilityState === 'hidden') {
|
|
802
|
+
stopPanInteractions();
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
const refreshViewport = () => {
|
|
806
|
+
if (disposed || status !== 'ready') {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (userAdjustedViewport) {
|
|
810
|
+
applyZoom();
|
|
811
|
+
zoomEmitter.emit();
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
fitSheetToStage();
|
|
815
|
+
};
|
|
816
|
+
const scheduleViewportRefresh = () => {
|
|
817
|
+
if (resizeFrame !== undefined) {
|
|
818
|
+
ownerWindow.cancelAnimationFrame(resizeFrame);
|
|
819
|
+
}
|
|
820
|
+
resizeFrame = ownerWindow.requestAnimationFrame(() => {
|
|
821
|
+
resizeFrame = undefined;
|
|
822
|
+
refreshViewport();
|
|
823
|
+
});
|
|
824
|
+
};
|
|
825
|
+
const resizeObserver = typeof ownerWindow.ResizeObserver === 'function'
|
|
826
|
+
? new ownerWindow.ResizeObserver(scheduleViewportRefresh)
|
|
827
|
+
: null;
|
|
828
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(stage);
|
|
829
|
+
ownerWindow.addEventListener('resize', scheduleViewportRefresh);
|
|
830
|
+
initializePanzoom();
|
|
831
|
+
stage.addEventListener('wheel', onStageWheel, { passive: false });
|
|
832
|
+
stage.addEventListener('keydown', onStageKeyDown);
|
|
833
|
+
stage.addEventListener('keyup', onStageKeyUp);
|
|
834
|
+
stage.addEventListener('dblclick', onStageDblClick);
|
|
835
|
+
stage.addEventListener('dragstart', onStageDragStart);
|
|
836
|
+
stage.addEventListener('contextmenu', onStageContextMenu);
|
|
837
|
+
stage.addEventListener('selectstart', onStageSelectStart);
|
|
838
|
+
ownerWindow.addEventListener('keyup', onStageKeyUp);
|
|
839
|
+
ownerWindow.addEventListener('blur', stopPanInteractions);
|
|
840
|
+
ownerDocument.addEventListener('visibilitychange', onDocumentVisibilityChange);
|
|
841
|
+
zoomOutButton.addEventListener('click', () => setZoomAtStageCenter(zoom - 0.15));
|
|
842
|
+
zoomInButton.addEventListener('click', () => setZoomAtStageCenter(zoom + 0.15));
|
|
843
|
+
resetButton.addEventListener('click', () => fitSheetToStage(true));
|
|
844
|
+
syncState();
|
|
845
|
+
void load();
|
|
846
|
+
return {
|
|
847
|
+
$el: root,
|
|
848
|
+
unmount() {
|
|
849
|
+
disposed = true;
|
|
850
|
+
if (resizeFrame !== undefined) {
|
|
851
|
+
ownerWindow.cancelAnimationFrame(resizeFrame);
|
|
852
|
+
resizeFrame = undefined;
|
|
853
|
+
}
|
|
854
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
855
|
+
unregisterFileViewerZoomProvider(root);
|
|
856
|
+
zoomBox.removeEventListener('panzoomstart', onPanzoomStart);
|
|
857
|
+
zoomBox.removeEventListener('panzoomchange', onPanzoomChange);
|
|
858
|
+
zoomBox.removeEventListener('panzoomend', onPanzoomEnd);
|
|
859
|
+
panzoom === null || panzoom === void 0 ? void 0 : panzoom.destroy();
|
|
860
|
+
panzoom = null;
|
|
861
|
+
stage.removeEventListener('wheel', onStageWheel);
|
|
862
|
+
stage.removeEventListener('keydown', onStageKeyDown);
|
|
863
|
+
stage.removeEventListener('keyup', onStageKeyUp);
|
|
864
|
+
stage.removeEventListener('dblclick', onStageDblClick);
|
|
865
|
+
stage.removeEventListener('dragstart', onStageDragStart);
|
|
866
|
+
stage.removeEventListener('contextmenu', onStageContextMenu);
|
|
867
|
+
stage.removeEventListener('selectstart', onStageSelectStart);
|
|
868
|
+
ownerWindow.removeEventListener('keyup', onStageKeyUp);
|
|
869
|
+
ownerWindow.removeEventListener('resize', scheduleViewportRefresh);
|
|
870
|
+
ownerWindow.removeEventListener('blur', stopPanInteractions);
|
|
871
|
+
ownerDocument.removeEventListener('visibilitychange', onDocumentVisibilityChange);
|
|
872
|
+
target.replaceChildren();
|
|
873
|
+
},
|
|
874
|
+
};
|
|
875
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@file-viewer/renderer-mindmap",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Standalone XMind and mind map renderer plugin for Flyfish File Viewer.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"file-viewer",
|
|
9
|
+
"renderer",
|
|
10
|
+
"xmind",
|
|
11
|
+
"mindmap",
|
|
12
|
+
"document-preview",
|
|
13
|
+
"document-viewer",
|
|
14
|
+
"file-preview",
|
|
15
|
+
"self-hosted"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Wangyu",
|
|
23
|
+
"email": "wybaby168@gmail.com"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer-renderer-mindmap.git",
|
|
28
|
+
"directory": "packages/renderers/mindmap"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/flyfish-dev/file-viewer-renderer-mindmap/issues"
|
|
33
|
+
},
|
|
34
|
+
"funding": {
|
|
35
|
+
"type": "individual",
|
|
36
|
+
"url": "https://dev.flyfish.group/shop"
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"module": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.js",
|
|
45
|
+
"default": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"README.md",
|
|
52
|
+
"README.en.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@file-viewer/core": "^2.0.11",
|
|
57
|
+
"@ljheee/xmind-parser": "^1.1.3",
|
|
58
|
+
"@panzoom/panzoom": "^4.6.2",
|
|
59
|
+
"jszip": "^3.10.1"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"typescript": "^6.0.3"
|
|
63
|
+
},
|
|
64
|
+
"license": "Apache-2.0",
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -b tsconfig.json",
|
|
67
|
+
"type-check": "tsc -b tsconfig.json"
|
|
68
|
+
}
|
|
69
|
+
}
|