@tnotesjs/core 0.0.6 → 0.0.8
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/README.md +87 -84
- package/dist/{chunk-JDVN2QYW.js → chunk-JUMVJKWV.js} +615 -614
- package/dist/cli/index.js +125 -125
- package/dist/vitepress/config/index.js +184 -210
- package/package.json +15 -3
- package/types/config.ts +61 -61
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- package/types/shims.d.ts +3 -4
- package/vitepress/assets/icons/icon__check.svg +3 -3
- package/vitepress/assets/icons/icon__clipboard.svg +7 -7
- package/vitepress/assets/icons/icon__close.svg +1 -1
- package/vitepress/assets/icons/icon__collapse.svg +1 -1
- package/vitepress/assets/icons/icon__confirm.svg +1 -1
- package/vitepress/assets/icons/icon__copy.svg +4 -4
- package/vitepress/assets/icons/icon__focus.svg +1 -1
- package/vitepress/assets/icons/icon__fold.svg +3 -3
- package/vitepress/assets/icons/icon__folder.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
- package/vitepress/assets/icons/icon__github.svg +3 -3
- package/vitepress/assets/icons/icon__mindmap.svg +1 -1
- package/vitepress/assets/icons/icon__next.svg +1 -1
- package/vitepress/assets/icons/icon__number_gray.svg +1 -1
- package/vitepress/assets/icons/icon__number_purple.svg +1 -1
- package/vitepress/assets/icons/icon__prev.svg +1 -1
- package/vitepress/assets/icons/icon__restore.svg +1 -1
- package/vitepress/assets/icons/icon__rotate.svg +4 -4
- package/vitepress/assets/icons/icon__search.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
- package/vitepress/assets/icons/icon__totop.svg +5 -5
- package/vitepress/assets/icons/icon__vscode.svg +5 -5
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
- package/vitepress/assets/icons/index.ts +38 -38
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -372
- package/vitepress/components/CodeBlockFullscreen/index.ts +115 -114
- package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
- package/vitepress/components/Discussions/Discussions.module.scss +32 -32
- package/vitepress/components/Discussions/Discussions.vue +211 -210
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
- package/vitepress/components/EnWordList/EnWordList.vue +543 -542
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
- package/vitepress/components/Footprints/Footprints.module.scss +93 -93
- package/vitepress/components/Footprints/Footprints.vue +377 -377
- package/vitepress/components/Layout/AboutModal.module.scss +233 -233
- package/vitepress/components/Layout/AboutModal.vue +105 -105
- package/vitepress/components/Layout/AboutPanel.vue +270 -265
- package/vitepress/components/Layout/ContentCollapse.vue +603 -602
- package/vitepress/components/Layout/CustomSidebar.vue +608 -605
- package/vitepress/components/Layout/DocBeforeControls.vue +149 -139
- package/vitepress/components/Layout/DocFooter.vue +233 -232
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
- package/vitepress/components/Layout/ImagePreview.vue +281 -280
- package/vitepress/components/Layout/Layout.module.scss +661 -661
- package/vitepress/components/Layout/Layout.vue +539 -542
- package/vitepress/components/Layout/NoteStatus.vue +140 -139
- package/vitepress/components/Layout/SidebarItems.vue +267 -262
- package/vitepress/components/Layout/SidebarNavBefore.vue +92 -92
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
- package/vitepress/components/Layout/ToggleFullContent.vue +35 -34
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
- package/vitepress/components/Layout/ToggleSidebar.vue +36 -35
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -121
- package/vitepress/components/Layout/composables/useNoteSave.ts +173 -172
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +113 -110
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +86 -83
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/LoadingPage/LoadingPage.vue +192 -192
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
- package/vitepress/components/MarkMap/MarkMap.vue +405 -404
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
- package/vitepress/components/Mermaid/Mermaid.vue +365 -363
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
- package/vitepress/components/NotesTable/NotesTable.vue +98 -97
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.module.scss +433 -433
- package/vitepress/components/Settings/Settings.vue +306 -305
- package/vitepress/components/SidebarCard/MindMapView.vue +484 -483
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +946 -948
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +91 -91
- package/vitepress/components/notesConfig.data.ts +73 -73
- package/vitepress/components/sidebar.data.ts +59 -59
- package/vitepress/components/tnotes-config.data.ts +21 -21
- package/vitepress/components/utils.ts +26 -26
- package/vitepress/config/index.ts +160 -146
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -24
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -20
- package/vitepress/configs/markdown.config.ts +366 -365
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +434 -470
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -106
- package/vitepress/plugins/renameNotePlugin.ts +60 -59
- package/vitepress/plugins/updateConfigPlugin.ts +63 -62
- package/vitepress/theme/index.ts +95 -93
- package/vitepress/theme/styles/base.scss +50 -50
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +175 -175
- package/vitepress/theme/styles/components/markmap.scss +101 -101
- package/vitepress/theme/styles/components/swiper.scss +255 -255
- package/vitepress/theme/styles/index.scss +25 -25
- package/vitepress/theme/styles/layout.scss +62 -62
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
|
@@ -1,404 +1,405 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import { Transformer } from 'markmap-lib'
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import 'markmap-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
// autoFit
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
toolbarEl
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
toolbarEl
|
|
127
|
-
toolbarEl.style.
|
|
128
|
-
toolbarEl.style.
|
|
129
|
-
toolbarEl.style.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
fullscreenBtn
|
|
144
|
-
fullscreenBtn.
|
|
145
|
-
fullscreenBtn.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
updateContainer
|
|
156
|
-
updateContainer.style.
|
|
157
|
-
updateContainer.style.
|
|
158
|
-
updateContainer.style.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
levelInput
|
|
163
|
-
levelInput.
|
|
164
|
-
levelInput.
|
|
165
|
-
levelInput.
|
|
166
|
-
levelInput.
|
|
167
|
-
levelInput.
|
|
168
|
-
levelInput.
|
|
169
|
-
levelInput.style.
|
|
170
|
-
levelInput.style.
|
|
171
|
-
levelInput.style.
|
|
172
|
-
levelInput.style.
|
|
173
|
-
levelInput.style.
|
|
174
|
-
levelInput.style.
|
|
175
|
-
levelInput.style.
|
|
176
|
-
|
|
177
|
-
// levelInput.style.
|
|
178
|
-
levelInput.style.
|
|
179
|
-
levelInput.
|
|
180
|
-
levelInput.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
value = 1
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
value = 100
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
updateBtn
|
|
232
|
-
updateBtn.
|
|
233
|
-
updateBtn.
|
|
234
|
-
updateBtn.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
updateContainer.appendChild(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(document as any).
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
document.addEventListener('
|
|
372
|
-
document.addEventListener('
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
observer
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
document.removeEventListener('
|
|
390
|
-
document.removeEventListener('
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
</
|
|
403
|
-
|
|
404
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { scaleOrdinal, schemePastel2, schemeSet3, schemeTableau10 } from 'd3'
|
|
3
|
+
import { Transformer } from 'markmap-lib'
|
|
4
|
+
import { Toolbar } from 'markmap-toolbar'
|
|
5
|
+
import 'markmap-toolbar/dist/style.css'
|
|
6
|
+
import { Markmap, IMarkmapOptions } from 'markmap-view'
|
|
7
|
+
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
8
|
+
|
|
9
|
+
import { icon__fullscreen, icon__fullscreen_exit, icon__confirm } from '../../assets/icons'
|
|
10
|
+
import { MARKMAP_THEME_KEY, MARKMAP_EXPAND_LEVEL_KEY } from '../constants'
|
|
11
|
+
|
|
12
|
+
// doc: https://github.com/markmap/markmap/blob/205367a24603dc187f67da1658940c6cade20dce/packages/markmap-view/src/constants.ts#L15
|
|
13
|
+
|
|
14
|
+
const props = defineProps({
|
|
15
|
+
content: { type: String, default: '' },
|
|
16
|
+
duration: { type: Number, default: 100 },
|
|
17
|
+
spacingVertical: { type: Number, default: 10 },
|
|
18
|
+
spacingHorizontal: { type: Number, default: 20 },
|
|
19
|
+
nodeMinHeight: { type: Number, default: 24 },
|
|
20
|
+
initialExpandLevel: { type: Number, default: 5 },
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const svgRef = ref<SVGSVGElement | null>(null)
|
|
24
|
+
const containerRef = ref<HTMLDivElement | null>(null)
|
|
25
|
+
|
|
26
|
+
let markmapInstance: Markmap | null = null
|
|
27
|
+
let observer: MutationObserver | null = null
|
|
28
|
+
let toolbarEl: HTMLElement | null = null
|
|
29
|
+
|
|
30
|
+
// 从 localStorage 读取配置,如果没有则使用 props 或默认值
|
|
31
|
+
const getInitialExpandLevel = () => {
|
|
32
|
+
if (typeof window !== 'undefined') {
|
|
33
|
+
const saved = localStorage.getItem(MARKMAP_EXPAND_LEVEL_KEY)
|
|
34
|
+
if (saved) return parseInt(saved)
|
|
35
|
+
}
|
|
36
|
+
return props.initialExpandLevel
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getThemeColorFn = () => {
|
|
40
|
+
if (typeof window !== 'undefined') {
|
|
41
|
+
const theme = localStorage.getItem(MARKMAP_THEME_KEY) || 'default'
|
|
42
|
+
switch (theme) {
|
|
43
|
+
case 'colorful':
|
|
44
|
+
return scaleOrdinal(schemeTableau10)
|
|
45
|
+
case 'dark':
|
|
46
|
+
return scaleOrdinal(schemeSet3)
|
|
47
|
+
default:
|
|
48
|
+
return scaleOrdinal(schemePastel2)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return scaleOrdinal(schemePastel2)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 可由配置/props 初始化,也可以通过工具栏改动
|
|
55
|
+
const expandLevel = ref(getInitialExpandLevel())
|
|
56
|
+
const transformer = new Transformer()
|
|
57
|
+
const isFullscreen = ref(false)
|
|
58
|
+
|
|
59
|
+
// 保存工具栏中层级输入框的引用,方便同步显示与绑定事件
|
|
60
|
+
let toolbarLevelInput: HTMLInputElement | null = null
|
|
61
|
+
|
|
62
|
+
function renderMarkmap(content: string, level = expandLevel.value) {
|
|
63
|
+
if (!svgRef.value) return
|
|
64
|
+
|
|
65
|
+
nextTick().then(() => {
|
|
66
|
+
if (markmapInstance) {
|
|
67
|
+
try {
|
|
68
|
+
markmapInstance.destroy()
|
|
69
|
+
} catch {}
|
|
70
|
+
markmapInstance = null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!content.trim()) {
|
|
74
|
+
svgRef.value!.innerHTML = '<text x="20" y="30" fill="#999">空内容</text>'
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const { root } = transformer.transform(content)
|
|
80
|
+
const colorFn = getThemeColorFn()
|
|
81
|
+
const options: Partial<IMarkmapOptions> = {
|
|
82
|
+
// autoFit 会自动调整 scale 和 position 来适配当前容器大小,在阅读大量节点内容的时候,会放大某块区域阅读,每次展开节点或者收起节点,都会自动触发 autoFit,导致阅读体验不佳,因此不启用。
|
|
83
|
+
// autoFit: true,
|
|
84
|
+
initialExpandLevel: level,
|
|
85
|
+
duration: props.duration,
|
|
86
|
+
nodeMinHeight: props.nodeMinHeight,
|
|
87
|
+
spacingVertical: props.spacingVertical,
|
|
88
|
+
spacingHorizontal: props.spacingHorizontal,
|
|
89
|
+
maxInitialScale: 2,
|
|
90
|
+
maxWidth: 400,
|
|
91
|
+
// 使用配置的主题颜色
|
|
92
|
+
color: (node): string => colorFn(`${node.state?.path || ''}`),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
markmapInstance = Markmap.create(svgRef.value!, options, root)
|
|
96
|
+
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
try {
|
|
99
|
+
markmapInstance?.fit() // 确保居中
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.warn('fit failed', e)
|
|
102
|
+
}
|
|
103
|
+
}, 0)
|
|
104
|
+
|
|
105
|
+
initToolbar()
|
|
106
|
+
setupObserver()
|
|
107
|
+
} catch (error: any) {
|
|
108
|
+
console.error('Markmap render error:', error)
|
|
109
|
+
svgRef.value!.innerHTML = `<text x="20" y="30" fill="red">Markmap 错误: ${error.message}</text>`
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function initToolbar() {
|
|
115
|
+
if (!markmapInstance || !containerRef.value) return
|
|
116
|
+
|
|
117
|
+
// 移除现有的工具栏
|
|
118
|
+
if (toolbarEl) {
|
|
119
|
+
toolbarEl.remove()
|
|
120
|
+
toolbarEl = null
|
|
121
|
+
toolbarLevelInput = null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 创建新工具栏
|
|
125
|
+
const { el } = Toolbar.create(markmapInstance)
|
|
126
|
+
toolbarEl = el
|
|
127
|
+
toolbarEl.style.position = 'absolute'
|
|
128
|
+
toolbarEl.style.top = '1rem'
|
|
129
|
+
toolbarEl.style.right = '.5rem'
|
|
130
|
+
toolbarEl.style.scale = '.8'
|
|
131
|
+
const brand = toolbarEl.querySelector('.mm-toolbar-brand')
|
|
132
|
+
if (brand) toolbarEl.removeChild(brand)
|
|
133
|
+
containerRef.value.appendChild(toolbarEl)
|
|
134
|
+
|
|
135
|
+
// 添加自定义全屏按钮
|
|
136
|
+
addFullscreenButton(toolbarEl)
|
|
137
|
+
|
|
138
|
+
// 在工具栏中添加更新按钮 + 层级输入(并支持 Enter 键触发)
|
|
139
|
+
addUpdateButton(toolbarEl)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function addFullscreenButton(toolbar: HTMLElement) {
|
|
143
|
+
const fullscreenBtn = document.createElement('div')
|
|
144
|
+
fullscreenBtn.className = 'mm-toolbar-item'
|
|
145
|
+
fullscreenBtn.title = isFullscreen.value ? '退出全屏' : '全屏'
|
|
146
|
+
fullscreenBtn.innerHTML = isFullscreen.value
|
|
147
|
+
? `<img src="${icon__fullscreen_exit}" alt="退出全屏" style="width:18px;height:18px;display:block" />`
|
|
148
|
+
: `<img src="${icon__fullscreen}" alt="全屏" style="width:18px;height:18px;display:block" />`
|
|
149
|
+
fullscreenBtn.addEventListener('click', toggleFullscreen)
|
|
150
|
+
toolbar.appendChild(fullscreenBtn)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function addUpdateButton(toolbar: HTMLElement) {
|
|
154
|
+
// 创建更新按钮容器
|
|
155
|
+
const updateContainer = document.createElement('div')
|
|
156
|
+
updateContainer.style.display = 'flex'
|
|
157
|
+
updateContainer.style.alignItems = 'center'
|
|
158
|
+
updateContainer.style.gap = '8px'
|
|
159
|
+
updateContainer.style.marginRight = '5px'
|
|
160
|
+
|
|
161
|
+
// 创建输入框(确保具有 id/name,且样式能在工具栏中清晰可见)
|
|
162
|
+
const levelInput = document.createElement('input')
|
|
163
|
+
levelInput.type = 'number'
|
|
164
|
+
levelInput.id = 'markmap-expand-level'
|
|
165
|
+
levelInput.name = 'markmap-expand-level'
|
|
166
|
+
levelInput.min = '1'
|
|
167
|
+
levelInput.max = '100'
|
|
168
|
+
levelInput.value = expandLevel.value.toString()
|
|
169
|
+
levelInput.style.width = '2.4rem'
|
|
170
|
+
levelInput.style.height = '1.6rem'
|
|
171
|
+
levelInput.style.padding = '2px 6px'
|
|
172
|
+
levelInput.style.fontSize = '12px'
|
|
173
|
+
levelInput.style.lineHeight = '1.2'
|
|
174
|
+
levelInput.style.textAlign = 'center'
|
|
175
|
+
levelInput.style.boxSizing = 'border-box'
|
|
176
|
+
levelInput.style.borderBottom = '.5px solid var(--vp-c-tip-1)'
|
|
177
|
+
// levelInput.style.borderRadius = '4px'
|
|
178
|
+
// levelInput.style.background = 'var(--vp-c-bg)'
|
|
179
|
+
levelInput.style.color = 'var(--vp-c-tip-1)'
|
|
180
|
+
levelInput.title = '展开层级'
|
|
181
|
+
levelInput.setAttribute('aria-label', 'markmap-expand-level')
|
|
182
|
+
|
|
183
|
+
// 保存引用,供外部(props 改变)同步输入值
|
|
184
|
+
toolbarLevelInput = levelInput
|
|
185
|
+
|
|
186
|
+
// 实时限制输入范围(1-100)
|
|
187
|
+
levelInput.addEventListener('input', (e) => {
|
|
188
|
+
const input = e.target as HTMLInputElement
|
|
189
|
+
let value = parseInt(input.value)
|
|
190
|
+
|
|
191
|
+
// 如果输入为空或非数字,不做处理
|
|
192
|
+
if (input.value === '' || isNaN(value)) return
|
|
193
|
+
|
|
194
|
+
// 限制范围:1-100
|
|
195
|
+
if (value < 1) {
|
|
196
|
+
input.value = '1'
|
|
197
|
+
value = 1
|
|
198
|
+
} else if (value > 100) {
|
|
199
|
+
input.value = '100'
|
|
200
|
+
value = 100
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// 当输入框值变化时仅更新内部 expandLevel(不自动渲染)
|
|
205
|
+
levelInput.addEventListener('change', (e) => {
|
|
206
|
+
const value = parseInt((e.target as HTMLInputElement).value)
|
|
207
|
+
if (!isNaN(value) && value >= 1 && value <= 100) {
|
|
208
|
+
expandLevel.value = value
|
|
209
|
+
} else {
|
|
210
|
+
// 回退到之前的值(避免非法输入)
|
|
211
|
+
levelInput.value = expandLevel.value.toString()
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
// 按键监听:按 Enter 时触发更新(相当于点击确认按钮)
|
|
216
|
+
levelInput.addEventListener('keydown', (e) => {
|
|
217
|
+
if (e.key === 'Enter') {
|
|
218
|
+
// 同步输入框值到 expandLevel(防止未触发 change)
|
|
219
|
+
const val = parseInt((e.target as HTMLInputElement).value)
|
|
220
|
+
if (!isNaN(val) && val >= 1 && val <= 100) {
|
|
221
|
+
expandLevel.value = val
|
|
222
|
+
} else {
|
|
223
|
+
// 如果超出范围,重置为有效值
|
|
224
|
+
levelInput.value = expandLevel.value.toString()
|
|
225
|
+
}
|
|
226
|
+
onUpdateClick()
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
// 创建按钮
|
|
231
|
+
const updateBtn = document.createElement('button')
|
|
232
|
+
updateBtn.type = 'button'
|
|
233
|
+
updateBtn.title = '确定层级并更新'
|
|
234
|
+
updateBtn.innerHTML = `<img src="${icon__confirm}" alt="确定" style="width:16px;height:16px;display:block" />`
|
|
235
|
+
updateBtn.addEventListener('click', onUpdateClick)
|
|
236
|
+
|
|
237
|
+
updateContainer.appendChild(levelInput)
|
|
238
|
+
updateContainer.appendChild(updateBtn)
|
|
239
|
+
|
|
240
|
+
// 将更新按钮插入到工具栏开头
|
|
241
|
+
toolbar.insertBefore(updateContainer, toolbar.firstChild)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 切换全屏(保持原来的实现)
|
|
245
|
+
function toggleFullscreen() {
|
|
246
|
+
if (!containerRef.value) return
|
|
247
|
+
|
|
248
|
+
if (!isFullscreen.value) {
|
|
249
|
+
// 进入全屏
|
|
250
|
+
if (containerRef.value.requestFullscreen) {
|
|
251
|
+
containerRef.value.requestFullscreen().catch((err) => {
|
|
252
|
+
console.error('全屏请求失败:', err)
|
|
253
|
+
})
|
|
254
|
+
} else if ((containerRef.value as any).webkitRequestFullscreen) {
|
|
255
|
+
;(containerRef.value as any).webkitRequestFullscreen()
|
|
256
|
+
} else if ((containerRef.value as any).msRequestFullscreen) {
|
|
257
|
+
;(containerRef.value as any).msRequestFullscreen()
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
// 退出全屏
|
|
261
|
+
if (document.exitFullscreen) {
|
|
262
|
+
document.exitFullscreen()
|
|
263
|
+
} else if ((document as any).webkitExitFullscreen) {
|
|
264
|
+
;(document as any).webkitExitFullscreen()
|
|
265
|
+
} else if ((document as any).msExitFullscreen) {
|
|
266
|
+
;(document as any).msExitFullscreen()
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 监听全屏状态变化
|
|
272
|
+
function handleFullscreenChange() {
|
|
273
|
+
isFullscreen.value = !!(
|
|
274
|
+
document.fullscreenElement ||
|
|
275
|
+
(document as any).webkitFullscreenElement ||
|
|
276
|
+
(document as any).msFullscreenElement
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
// 更新工具栏中的全屏按钮(若存在)
|
|
280
|
+
if (toolbarEl) {
|
|
281
|
+
const fullscreenBtn = toolbarEl.querySelector(
|
|
282
|
+
'.mm-toolbar-item:last-child'
|
|
283
|
+
) as HTMLButtonElement
|
|
284
|
+
if (fullscreenBtn) {
|
|
285
|
+
fullscreenBtn.title = isFullscreen.value
|
|
286
|
+
? '退出全屏(Exit Fullscreen)'
|
|
287
|
+
: '全屏(Fullscreen)'
|
|
288
|
+
fullscreenBtn.innerHTML = isFullscreen.value
|
|
289
|
+
? `<img src="${icon__fullscreen_exit}" alt="退出全屏" style="width:18px;height:18px;display:block" />`
|
|
290
|
+
: `<img src="${icon__fullscreen}" alt="全屏" style="width:18px;height:18px;display:block" />`
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 全屏模式下调整SVG高度
|
|
295
|
+
if (svgRef.value) {
|
|
296
|
+
if (isFullscreen.value) {
|
|
297
|
+
svgRef.value.style.height = 'calc(100vh - 100px)'
|
|
298
|
+
} else {
|
|
299
|
+
svgRef.value.style.height = '400px'
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 确保居中 - 无论进入还是退出全屏都执行居中
|
|
303
|
+
setTimeout(() => {
|
|
304
|
+
if (markmapInstance) {
|
|
305
|
+
try {
|
|
306
|
+
markmapInstance.fit()
|
|
307
|
+
} catch (e) {
|
|
308
|
+
console.warn('居中失败', e)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}, 300)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function setupObserver() {
|
|
316
|
+
if (!svgRef.value) return
|
|
317
|
+
if (observer !== null) {
|
|
318
|
+
observer.disconnect()
|
|
319
|
+
}
|
|
320
|
+
observer = new MutationObserver(() => {
|
|
321
|
+
// DOM 变动后处理(保留扩展点)
|
|
322
|
+
})
|
|
323
|
+
observer.observe(svgRef.value, {
|
|
324
|
+
childList: true,
|
|
325
|
+
subtree: true,
|
|
326
|
+
attributes: true,
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 只监听内容变化,expandLevel 改动不自动渲染(点击/Enter 确认渲染)
|
|
331
|
+
watch(
|
|
332
|
+
() => props.content,
|
|
333
|
+
(newVal) => {
|
|
334
|
+
renderMarkmap(decodeURIComponent(newVal || ''))
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
// 新增:当外部传入的 initialExpandLevel 改变时,组件应同步并重新渲染
|
|
339
|
+
watch(
|
|
340
|
+
() => props.initialExpandLevel,
|
|
341
|
+
(newVal) => {
|
|
342
|
+
if (typeof newVal === 'number' && !isNaN(newVal)) {
|
|
343
|
+
expandLevel.value = newVal
|
|
344
|
+
// 更新输入框显示(如果已创建)
|
|
345
|
+
if (toolbarLevelInput) toolbarLevelInput.value = newVal.toString()
|
|
346
|
+
// 重新渲染使用新的层级(保持对外部 prop 改动的即时响应)
|
|
347
|
+
renderMarkmap(decodeURIComponent(props.content || ''), newVal)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
// 同步:当内部 expandLevel 变更时(例如通过输入框 change 事件),更新工具栏输入显示
|
|
353
|
+
watch(expandLevel, (v) => {
|
|
354
|
+
if (toolbarLevelInput) {
|
|
355
|
+
const asStr = (v || 0).toString()
|
|
356
|
+
if (toolbarLevelInput.value !== asStr) {
|
|
357
|
+
toolbarLevelInput.value = asStr
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
// 点击更新按钮才用当前 expandLevel 渲染
|
|
363
|
+
function onUpdateClick() {
|
|
364
|
+
renderMarkmap(decodeURIComponent(props.content || ''), expandLevel.value)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
onMounted(() => {
|
|
368
|
+
renderMarkmap(decodeURIComponent(props.content || ''))
|
|
369
|
+
|
|
370
|
+
// 添加全屏事件监听
|
|
371
|
+
document.addEventListener('fullscreenchange', handleFullscreenChange)
|
|
372
|
+
document.addEventListener('webkitfullscreenchange', handleFullscreenChange)
|
|
373
|
+
document.addEventListener('MSFullscreenChange', handleFullscreenChange)
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
onBeforeUnmount(() => {
|
|
377
|
+
if (markmapInstance) {
|
|
378
|
+
try {
|
|
379
|
+
markmapInstance.destroy()
|
|
380
|
+
} catch {}
|
|
381
|
+
markmapInstance = null
|
|
382
|
+
}
|
|
383
|
+
if (observer !== null) {
|
|
384
|
+
observer.disconnect()
|
|
385
|
+
observer = null
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 移除全屏事件监听
|
|
389
|
+
document.removeEventListener('fullscreenchange', handleFullscreenChange)
|
|
390
|
+
document.removeEventListener('webkitfullscreenchange', handleFullscreenChange)
|
|
391
|
+
document.removeEventListener('MSFullscreenChange', handleFullscreenChange)
|
|
392
|
+
})
|
|
393
|
+
</script>
|
|
394
|
+
|
|
395
|
+
<template>
|
|
396
|
+
<div
|
|
397
|
+
:class="$style.markmapContainer"
|
|
398
|
+
ref="containerRef"
|
|
399
|
+
style="position: relative"
|
|
400
|
+
>
|
|
401
|
+
<svg ref="svgRef" style="width: 100%; height: 400px"></svg>
|
|
402
|
+
</div>
|
|
403
|
+
</template>
|
|
404
|
+
|
|
405
|
+
<style module src="./MarkMap.module.scss"></style>
|