@tnotesjs/core 0.1.22 → 0.1.24
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 -87
- package/package.json +1 -1
- package/types/config.ts +60 -60
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- 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 +39 -39
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +369 -369
- package/vitepress/components/CodeBlockFullscreen/index.ts +209 -209
- package/vitepress/components/CodeBlockFullscreen/styles.css +126 -126
- package/vitepress/components/Discussions/Discussions.vue +242 -242
- package/vitepress/components/EnWordList/EnWordList.vue +664 -664
- package/vitepress/components/EnWordList/RightClickMenu.vue +87 -87
- package/vitepress/components/Footprints/Footprints.vue +472 -472
- package/vitepress/components/Layout/AboutModal.vue +329 -329
- package/vitepress/components/Layout/AboutPanel.vue +485 -485
- package/vitepress/components/Layout/ContentCollapse.vue +591 -591
- package/vitepress/components/Layout/CustomSidebar.vue +817 -817
- package/vitepress/components/Layout/DocBeforeControls.vue +145 -145
- package/vitepress/components/Layout/DocFooter.vue +233 -233
- package/vitepress/components/Layout/ImagePreview.vue +485 -485
- package/vitepress/components/Layout/Layout.vue +744 -744
- package/vitepress/components/Layout/NoteStatus.vue +140 -140
- package/vitepress/components/Layout/SidebarItems.vue +1083 -1083
- package/vitepress/components/Layout/SidebarNavBefore.vue +170 -170
- package/vitepress/components/Layout/SidebarResizeHandle.vue +368 -311
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.vue +45 -45
- package/vitepress/components/Layout/ToggleSidebar.vue +35 -35
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
- package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
- package/vitepress/components/Layout/composables/useSidebarLayout.ts +122 -122
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/MarkMap/MarkMap.vue +562 -562
- package/vitepress/components/Mermaid/Mermaid.vue +644 -644
- package/vitepress/components/NotesTable/NotesTable.vue +175 -175
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.vue +711 -711
- package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +945 -945
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +109 -109
- 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 +169 -169
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -25
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -23
- package/vitepress/configs/markdown.config.ts +368 -368
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +434 -434
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
- package/vitepress/plugins/renameNotePlugin.ts +68 -68
- package/vitepress/plugins/sidebarStructurePlugin.ts +260 -260
- package/vitepress/plugins/updateConfigPlugin.ts +63 -63
- package/vitepress/theme/index.ts +137 -137
- package/vitepress/theme/styles/base.scss +66 -64
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +172 -172
- 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 +79 -78
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
import { createApp, onMounted, onUnmounted } from 'vue'
|
|
2
|
-
|
|
3
|
-
import CodeBlockFullscreen from './CodeBlockFullscreen.vue'
|
|
4
|
-
import { icon__check, icon__clipboard, icon__fullscreen } from '../../assets/icons'
|
|
5
|
-
|
|
6
|
-
type CopyState = 'idle' | 'copied' | 'failed'
|
|
7
|
-
|
|
8
|
-
const CODE_BLOCK_SELECTOR = 'div[class*="language-"]'
|
|
9
|
-
const CODE_ACTIONS_CLASS = 'tn-code-actions'
|
|
10
|
-
const COPY_RESET_DELAY = 1000
|
|
11
|
-
|
|
12
|
-
export function useCodeBlockFullscreen() {
|
|
13
|
-
let fullscreenApp: any = null
|
|
14
|
-
let fullscreenContainer: HTMLElement | null = null
|
|
15
|
-
const copyResetTimers = new WeakMap<HTMLElement, number>()
|
|
16
|
-
|
|
17
|
-
function addCodeActions() {
|
|
18
|
-
// 找到所有代码块
|
|
19
|
-
const codeBlocks = document.querySelectorAll(CODE_BLOCK_SELECTOR)
|
|
20
|
-
|
|
21
|
-
codeBlocks.forEach((block) => {
|
|
22
|
-
if (!(block instanceof HTMLElement)) return
|
|
23
|
-
if (!block.querySelector('pre code')) return
|
|
24
|
-
block.querySelectorAll('.fullscreen-btn').forEach((button) => {
|
|
25
|
-
button.remove()
|
|
26
|
-
})
|
|
27
|
-
if (block.querySelector(`.${CODE_ACTIONS_CLASS}`)) return
|
|
28
|
-
|
|
29
|
-
const actions = document.createElement('div')
|
|
30
|
-
actions.className = CODE_ACTIONS_CLASS
|
|
31
|
-
|
|
32
|
-
const fullscreenButton = createActionButton({
|
|
33
|
-
className: 'tn-code-action-fullscreen',
|
|
34
|
-
title: '全屏查看代码',
|
|
35
|
-
icon: icon__fullscreen,
|
|
36
|
-
alt: '全屏',
|
|
37
|
-
})
|
|
38
|
-
fullscreenButton.addEventListener('click', () => {
|
|
39
|
-
openFullscreen(block)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const copyButton = createActionButton({
|
|
43
|
-
className: 'tn-code-action-copy',
|
|
44
|
-
title: '复制代码',
|
|
45
|
-
icon: icon__clipboard,
|
|
46
|
-
alt: '复制',
|
|
47
|
-
})
|
|
48
|
-
copyButton.addEventListener('click', () => {
|
|
49
|
-
void copyCode(block, copyButton)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
actions.append(fullscreenButton, copyButton)
|
|
53
|
-
block.appendChild(actions)
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function createActionButton(options: {
|
|
58
|
-
className: string
|
|
59
|
-
title: string
|
|
60
|
-
icon: string
|
|
61
|
-
alt: string
|
|
62
|
-
}) {
|
|
63
|
-
const button = document.createElement('button')
|
|
64
|
-
button.className = `tn-code-action ${options.className}`
|
|
65
|
-
button.type = 'button'
|
|
66
|
-
button.title = options.title
|
|
67
|
-
button.innerHTML = `<img src="${options.icon}" alt="${options.alt}" />`
|
|
68
|
-
|
|
69
|
-
return button
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function copyCode(codeBlock: HTMLElement, button: HTMLElement) {
|
|
73
|
-
const codeElement = codeBlock.querySelector('pre code')
|
|
74
|
-
const text = codeElement?.textContent ?? ''
|
|
75
|
-
if (!text) {
|
|
76
|
-
setCopyState(button, 'failed')
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
await navigator.clipboard.writeText(text)
|
|
82
|
-
setCopyState(button, 'copied')
|
|
83
|
-
} catch {
|
|
84
|
-
setCopyState(button, 'failed')
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function setCopyState(button: HTMLElement, state: CopyState) {
|
|
89
|
-
const currentTimer = copyResetTimers.get(button)
|
|
90
|
-
if (currentTimer) {
|
|
91
|
-
window.clearTimeout(currentTimer)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
button.dataset.copyState = state
|
|
95
|
-
if (button.parentElement) {
|
|
96
|
-
button.parentElement.dataset.copyState = state
|
|
97
|
-
}
|
|
98
|
-
button.title = getCopyTitle(state)
|
|
99
|
-
|
|
100
|
-
const icon = button.querySelector('img')
|
|
101
|
-
if (icon) {
|
|
102
|
-
icon.setAttribute('src', state === 'copied' ? icon__check : icon__clipboard)
|
|
103
|
-
icon.setAttribute('alt', state === 'copied' ? '已复制' : '复制')
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const timer = window.setTimeout(() => {
|
|
107
|
-
button.dataset.copyState = 'idle'
|
|
108
|
-
if (button.parentElement) {
|
|
109
|
-
button.parentElement.dataset.copyState = 'idle'
|
|
110
|
-
}
|
|
111
|
-
button.title = getCopyTitle('idle')
|
|
112
|
-
icon?.setAttribute('src', icon__clipboard)
|
|
113
|
-
icon?.setAttribute('alt', '复制')
|
|
114
|
-
copyResetTimers.delete(button)
|
|
115
|
-
}, COPY_RESET_DELAY)
|
|
116
|
-
|
|
117
|
-
copyResetTimers.set(button, timer)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function getCopyTitle(state: CopyState): string {
|
|
121
|
-
if (state === 'copied') return '已复制'
|
|
122
|
-
if (state === 'failed') return '复制失败'
|
|
123
|
-
|
|
124
|
-
return '复制代码'
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function openFullscreen(codeBlock: HTMLElement) {
|
|
128
|
-
// 获取代码内容
|
|
129
|
-
const pre = codeBlock.querySelector('pre')
|
|
130
|
-
if (!pre) return
|
|
131
|
-
|
|
132
|
-
const codeHtml = pre.outerHTML
|
|
133
|
-
|
|
134
|
-
// 提取语言
|
|
135
|
-
const classList = Array.from(codeBlock.classList)
|
|
136
|
-
const languageClass = classList.find((c) => c.startsWith('language-'))
|
|
137
|
-
const language = languageClass
|
|
138
|
-
? languageClass.replace('language-', '').toUpperCase()
|
|
139
|
-
: undefined
|
|
140
|
-
|
|
141
|
-
// 提取文件名(如果有)
|
|
142
|
-
const filenameSpan = codeBlock.querySelector('.lang')
|
|
143
|
-
const filename = filenameSpan?.textContent?.trim()
|
|
144
|
-
|
|
145
|
-
// 创建全屏组件容器
|
|
146
|
-
if (!fullscreenContainer) {
|
|
147
|
-
fullscreenContainer = document.createElement('div')
|
|
148
|
-
document.body.appendChild(fullscreenContainer)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// 创建 Vue 应用
|
|
152
|
-
fullscreenApp = createApp(CodeBlockFullscreen, {
|
|
153
|
-
isFullscreen: true,
|
|
154
|
-
codeHtml,
|
|
155
|
-
language,
|
|
156
|
-
filename,
|
|
157
|
-
'onUpdate:isFullscreen': (value: boolean) => {
|
|
158
|
-
if (!value) {
|
|
159
|
-
closeFullscreen()
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
fullscreenApp.mount(fullscreenContainer)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function closeFullscreen() {
|
|
168
|
-
if (fullscreenApp) {
|
|
169
|
-
fullscreenApp.unmount()
|
|
170
|
-
fullscreenApp = null
|
|
171
|
-
}
|
|
172
|
-
if (fullscreenContainer && fullscreenContainer.parentNode) {
|
|
173
|
-
fullscreenContainer.parentNode.removeChild(fullscreenContainer)
|
|
174
|
-
fullscreenContainer = null
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function cleanup() {
|
|
179
|
-
closeFullscreen()
|
|
180
|
-
document.querySelectorAll(`.${CODE_ACTIONS_CLASS}`).forEach((actions) => {
|
|
181
|
-
actions.remove()
|
|
182
|
-
})
|
|
183
|
-
document.querySelectorAll('.fullscreen-btn').forEach((button) => {
|
|
184
|
-
button.remove()
|
|
185
|
-
})
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
onMounted(() => {
|
|
189
|
-
// 初始化
|
|
190
|
-
setTimeout(() => {
|
|
191
|
-
addCodeActions()
|
|
192
|
-
}, 100)
|
|
193
|
-
|
|
194
|
-
// 监听路由变化
|
|
195
|
-
const observer = new MutationObserver(() => {
|
|
196
|
-
addCodeActions()
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
observer.observe(document.body, {
|
|
200
|
-
childList: true,
|
|
201
|
-
subtree: true,
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
onUnmounted(() => {
|
|
205
|
-
observer.disconnect()
|
|
206
|
-
cleanup()
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
}
|
|
1
|
+
import { createApp, onMounted, onUnmounted } from 'vue'
|
|
2
|
+
|
|
3
|
+
import CodeBlockFullscreen from './CodeBlockFullscreen.vue'
|
|
4
|
+
import { icon__check, icon__clipboard, icon__fullscreen } from '../../assets/icons'
|
|
5
|
+
|
|
6
|
+
type CopyState = 'idle' | 'copied' | 'failed'
|
|
7
|
+
|
|
8
|
+
const CODE_BLOCK_SELECTOR = 'div[class*="language-"]'
|
|
9
|
+
const CODE_ACTIONS_CLASS = 'tn-code-actions'
|
|
10
|
+
const COPY_RESET_DELAY = 1000
|
|
11
|
+
|
|
12
|
+
export function useCodeBlockFullscreen() {
|
|
13
|
+
let fullscreenApp: any = null
|
|
14
|
+
let fullscreenContainer: HTMLElement | null = null
|
|
15
|
+
const copyResetTimers = new WeakMap<HTMLElement, number>()
|
|
16
|
+
|
|
17
|
+
function addCodeActions() {
|
|
18
|
+
// 找到所有代码块
|
|
19
|
+
const codeBlocks = document.querySelectorAll(CODE_BLOCK_SELECTOR)
|
|
20
|
+
|
|
21
|
+
codeBlocks.forEach((block) => {
|
|
22
|
+
if (!(block instanceof HTMLElement)) return
|
|
23
|
+
if (!block.querySelector('pre code')) return
|
|
24
|
+
block.querySelectorAll('.fullscreen-btn').forEach((button) => {
|
|
25
|
+
button.remove()
|
|
26
|
+
})
|
|
27
|
+
if (block.querySelector(`.${CODE_ACTIONS_CLASS}`)) return
|
|
28
|
+
|
|
29
|
+
const actions = document.createElement('div')
|
|
30
|
+
actions.className = CODE_ACTIONS_CLASS
|
|
31
|
+
|
|
32
|
+
const fullscreenButton = createActionButton({
|
|
33
|
+
className: 'tn-code-action-fullscreen',
|
|
34
|
+
title: '全屏查看代码',
|
|
35
|
+
icon: icon__fullscreen,
|
|
36
|
+
alt: '全屏',
|
|
37
|
+
})
|
|
38
|
+
fullscreenButton.addEventListener('click', () => {
|
|
39
|
+
openFullscreen(block)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const copyButton = createActionButton({
|
|
43
|
+
className: 'tn-code-action-copy',
|
|
44
|
+
title: '复制代码',
|
|
45
|
+
icon: icon__clipboard,
|
|
46
|
+
alt: '复制',
|
|
47
|
+
})
|
|
48
|
+
copyButton.addEventListener('click', () => {
|
|
49
|
+
void copyCode(block, copyButton)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
actions.append(fullscreenButton, copyButton)
|
|
53
|
+
block.appendChild(actions)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createActionButton(options: {
|
|
58
|
+
className: string
|
|
59
|
+
title: string
|
|
60
|
+
icon: string
|
|
61
|
+
alt: string
|
|
62
|
+
}) {
|
|
63
|
+
const button = document.createElement('button')
|
|
64
|
+
button.className = `tn-code-action ${options.className}`
|
|
65
|
+
button.type = 'button'
|
|
66
|
+
button.title = options.title
|
|
67
|
+
button.innerHTML = `<img src="${options.icon}" alt="${options.alt}" />`
|
|
68
|
+
|
|
69
|
+
return button
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function copyCode(codeBlock: HTMLElement, button: HTMLElement) {
|
|
73
|
+
const codeElement = codeBlock.querySelector('pre code')
|
|
74
|
+
const text = codeElement?.textContent ?? ''
|
|
75
|
+
if (!text) {
|
|
76
|
+
setCopyState(button, 'failed')
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
await navigator.clipboard.writeText(text)
|
|
82
|
+
setCopyState(button, 'copied')
|
|
83
|
+
} catch {
|
|
84
|
+
setCopyState(button, 'failed')
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setCopyState(button: HTMLElement, state: CopyState) {
|
|
89
|
+
const currentTimer = copyResetTimers.get(button)
|
|
90
|
+
if (currentTimer) {
|
|
91
|
+
window.clearTimeout(currentTimer)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
button.dataset.copyState = state
|
|
95
|
+
if (button.parentElement) {
|
|
96
|
+
button.parentElement.dataset.copyState = state
|
|
97
|
+
}
|
|
98
|
+
button.title = getCopyTitle(state)
|
|
99
|
+
|
|
100
|
+
const icon = button.querySelector('img')
|
|
101
|
+
if (icon) {
|
|
102
|
+
icon.setAttribute('src', state === 'copied' ? icon__check : icon__clipboard)
|
|
103
|
+
icon.setAttribute('alt', state === 'copied' ? '已复制' : '复制')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const timer = window.setTimeout(() => {
|
|
107
|
+
button.dataset.copyState = 'idle'
|
|
108
|
+
if (button.parentElement) {
|
|
109
|
+
button.parentElement.dataset.copyState = 'idle'
|
|
110
|
+
}
|
|
111
|
+
button.title = getCopyTitle('idle')
|
|
112
|
+
icon?.setAttribute('src', icon__clipboard)
|
|
113
|
+
icon?.setAttribute('alt', '复制')
|
|
114
|
+
copyResetTimers.delete(button)
|
|
115
|
+
}, COPY_RESET_DELAY)
|
|
116
|
+
|
|
117
|
+
copyResetTimers.set(button, timer)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getCopyTitle(state: CopyState): string {
|
|
121
|
+
if (state === 'copied') return '已复制'
|
|
122
|
+
if (state === 'failed') return '复制失败'
|
|
123
|
+
|
|
124
|
+
return '复制代码'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function openFullscreen(codeBlock: HTMLElement) {
|
|
128
|
+
// 获取代码内容
|
|
129
|
+
const pre = codeBlock.querySelector('pre')
|
|
130
|
+
if (!pre) return
|
|
131
|
+
|
|
132
|
+
const codeHtml = pre.outerHTML
|
|
133
|
+
|
|
134
|
+
// 提取语言
|
|
135
|
+
const classList = Array.from(codeBlock.classList)
|
|
136
|
+
const languageClass = classList.find((c) => c.startsWith('language-'))
|
|
137
|
+
const language = languageClass
|
|
138
|
+
? languageClass.replace('language-', '').toUpperCase()
|
|
139
|
+
: undefined
|
|
140
|
+
|
|
141
|
+
// 提取文件名(如果有)
|
|
142
|
+
const filenameSpan = codeBlock.querySelector('.lang')
|
|
143
|
+
const filename = filenameSpan?.textContent?.trim()
|
|
144
|
+
|
|
145
|
+
// 创建全屏组件容器
|
|
146
|
+
if (!fullscreenContainer) {
|
|
147
|
+
fullscreenContainer = document.createElement('div')
|
|
148
|
+
document.body.appendChild(fullscreenContainer)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 创建 Vue 应用
|
|
152
|
+
fullscreenApp = createApp(CodeBlockFullscreen, {
|
|
153
|
+
isFullscreen: true,
|
|
154
|
+
codeHtml,
|
|
155
|
+
language,
|
|
156
|
+
filename,
|
|
157
|
+
'onUpdate:isFullscreen': (value: boolean) => {
|
|
158
|
+
if (!value) {
|
|
159
|
+
closeFullscreen()
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
fullscreenApp.mount(fullscreenContainer)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function closeFullscreen() {
|
|
168
|
+
if (fullscreenApp) {
|
|
169
|
+
fullscreenApp.unmount()
|
|
170
|
+
fullscreenApp = null
|
|
171
|
+
}
|
|
172
|
+
if (fullscreenContainer && fullscreenContainer.parentNode) {
|
|
173
|
+
fullscreenContainer.parentNode.removeChild(fullscreenContainer)
|
|
174
|
+
fullscreenContainer = null
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function cleanup() {
|
|
179
|
+
closeFullscreen()
|
|
180
|
+
document.querySelectorAll(`.${CODE_ACTIONS_CLASS}`).forEach((actions) => {
|
|
181
|
+
actions.remove()
|
|
182
|
+
})
|
|
183
|
+
document.querySelectorAll('.fullscreen-btn').forEach((button) => {
|
|
184
|
+
button.remove()
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
onMounted(() => {
|
|
189
|
+
// 初始化
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
addCodeActions()
|
|
192
|
+
}, 100)
|
|
193
|
+
|
|
194
|
+
// 监听路由变化
|
|
195
|
+
const observer = new MutationObserver(() => {
|
|
196
|
+
addCodeActions()
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
observer.observe(document.body, {
|
|
200
|
+
childList: true,
|
|
201
|
+
subtree: true,
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
onUnmounted(() => {
|
|
205
|
+
observer.disconnect()
|
|
206
|
+
cleanup()
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
/* 代码块操作按钮样式 */
|
|
2
|
-
div[class*='language-'] {
|
|
3
|
-
position: relative;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
div[class*='language-'] button.copy {
|
|
7
|
-
display: none !important;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.tn-code-actions {
|
|
11
|
-
position: absolute;
|
|
12
|
-
top: 8px;
|
|
13
|
-
right: 8px;
|
|
14
|
-
z-index: 10;
|
|
15
|
-
display: flex;
|
|
16
|
-
align-items: center;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
gap: 4px;
|
|
19
|
-
padding: 2px;
|
|
20
|
-
background-color: color-mix(in srgb, var(--vp-code-block-bg) 92%, transparent);
|
|
21
|
-
border: .1px solid var(--vp-c-divider);
|
|
22
|
-
border-radius: 7px;
|
|
23
|
-
opacity: 0;
|
|
24
|
-
transition: opacity 0.2s;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.tn-code-action {
|
|
28
|
-
display: inline-flex;
|
|
29
|
-
align-items: center;
|
|
30
|
-
justify-content: center;
|
|
31
|
-
width: 32px;
|
|
32
|
-
height: 32px;
|
|
33
|
-
padding: 0;
|
|
34
|
-
border: none;
|
|
35
|
-
background-color: transparent;
|
|
36
|
-
color: var(--vp-c-text-2);
|
|
37
|
-
border-radius: 6px;
|
|
38
|
-
cursor: pointer;
|
|
39
|
-
transition: all 0.2s;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.tn-code-action img {
|
|
43
|
-
width: 16px;
|
|
44
|
-
height: 16px;
|
|
45
|
-
filter: var(--vp-icon-filter, none);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
div[class*='language-']:hover .tn-code-actions,
|
|
49
|
-
.tn-code-actions:focus-within,
|
|
50
|
-
.tn-code-actions[data-copy-state='copied'],
|
|
51
|
-
.tn-code-actions[data-copy-state='failed'] {
|
|
52
|
-
opacity: 1;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.tn-code-action:hover {
|
|
56
|
-
background-color: var(--vp-c-default-soft);
|
|
57
|
-
color: var(--vp-c-brand-1);
|
|
58
|
-
transform: scale(1.05);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.tn-code-action:active {
|
|
62
|
-
transform: scale(0.95);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.tn-code-action-copy {
|
|
66
|
-
position: relative;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.tn-code-action-copy[data-copy-state='copied'] {
|
|
70
|
-
background-color: var(--vp-c-green-soft);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.tn-code-action-copy[data-copy-state='failed'] {
|
|
74
|
-
background-color: var(--vp-c-danger-soft);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.tn-code-action-copy::after {
|
|
78
|
-
position: absolute;
|
|
79
|
-
top: 50%;
|
|
80
|
-
right: calc(100% + 6px);
|
|
81
|
-
padding: 4px 7px;
|
|
82
|
-
color: var(--vp-c-text-1);
|
|
83
|
-
background: var(--vp-c-bg-elv);
|
|
84
|
-
border: 1px solid var(--vp-c-divider);
|
|
85
|
-
border-radius: 6px;
|
|
86
|
-
box-shadow: var(--vp-shadow-2);
|
|
87
|
-
content: attr(title);
|
|
88
|
-
font-size: 12px;
|
|
89
|
-
line-height: 18px;
|
|
90
|
-
opacity: 0;
|
|
91
|
-
pointer-events: none;
|
|
92
|
-
transform: translateY(-50%) translateX(2px);
|
|
93
|
-
transition:
|
|
94
|
-
opacity 0.16s ease,
|
|
95
|
-
transform 0.16s ease;
|
|
96
|
-
white-space: nowrap;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.tn-code-action-copy[data-copy-state='copied']::after,
|
|
100
|
-
.tn-code-action-copy[data-copy-state='failed']::after {
|
|
101
|
-
opacity: 1;
|
|
102
|
-
transform: translateY(-50%) translateX(0);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/* .dark .tn-code-action-copy img {
|
|
106
|
-
filter: invert(1);
|
|
107
|
-
} */
|
|
108
|
-
|
|
109
|
-
/* 移动端始终显示按钮 */
|
|
110
|
-
@media (max-width: 768px) {
|
|
111
|
-
.tn-code-actions {
|
|
112
|
-
/* opacity: 0.8; */
|
|
113
|
-
top: 6px;
|
|
114
|
-
right: 6px;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.tn-code-action {
|
|
118
|
-
width: 28px;
|
|
119
|
-
height: 28px;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
.tn-code-action img {
|
|
123
|
-
width: 14px;
|
|
124
|
-
height: 14px;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
1
|
+
/* 代码块操作按钮样式 */
|
|
2
|
+
div[class*='language-'] {
|
|
3
|
+
position: relative;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
div[class*='language-'] button.copy {
|
|
7
|
+
display: none !important;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.tn-code-actions {
|
|
11
|
+
position: absolute;
|
|
12
|
+
top: 8px;
|
|
13
|
+
right: 8px;
|
|
14
|
+
z-index: 10;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
gap: 4px;
|
|
19
|
+
padding: 2px;
|
|
20
|
+
background-color: color-mix(in srgb, var(--vp-code-block-bg) 92%, transparent);
|
|
21
|
+
border: .1px solid var(--vp-c-divider);
|
|
22
|
+
border-radius: 7px;
|
|
23
|
+
opacity: 0;
|
|
24
|
+
transition: opacity 0.2s;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.tn-code-action {
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
width: 32px;
|
|
32
|
+
height: 32px;
|
|
33
|
+
padding: 0;
|
|
34
|
+
border: none;
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
color: var(--vp-c-text-2);
|
|
37
|
+
border-radius: 6px;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
transition: all 0.2s;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.tn-code-action img {
|
|
43
|
+
width: 16px;
|
|
44
|
+
height: 16px;
|
|
45
|
+
filter: var(--vp-icon-filter, none);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
div[class*='language-']:hover .tn-code-actions,
|
|
49
|
+
.tn-code-actions:focus-within,
|
|
50
|
+
.tn-code-actions[data-copy-state='copied'],
|
|
51
|
+
.tn-code-actions[data-copy-state='failed'] {
|
|
52
|
+
opacity: 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.tn-code-action:hover {
|
|
56
|
+
background-color: var(--vp-c-default-soft);
|
|
57
|
+
color: var(--vp-c-brand-1);
|
|
58
|
+
transform: scale(1.05);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.tn-code-action:active {
|
|
62
|
+
transform: scale(0.95);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.tn-code-action-copy {
|
|
66
|
+
position: relative;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.tn-code-action-copy[data-copy-state='copied'] {
|
|
70
|
+
background-color: var(--vp-c-green-soft);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.tn-code-action-copy[data-copy-state='failed'] {
|
|
74
|
+
background-color: var(--vp-c-danger-soft);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.tn-code-action-copy::after {
|
|
78
|
+
position: absolute;
|
|
79
|
+
top: 50%;
|
|
80
|
+
right: calc(100% + 6px);
|
|
81
|
+
padding: 4px 7px;
|
|
82
|
+
color: var(--vp-c-text-1);
|
|
83
|
+
background: var(--vp-c-bg-elv);
|
|
84
|
+
border: 1px solid var(--vp-c-divider);
|
|
85
|
+
border-radius: 6px;
|
|
86
|
+
box-shadow: var(--vp-shadow-2);
|
|
87
|
+
content: attr(title);
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
line-height: 18px;
|
|
90
|
+
opacity: 0;
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
transform: translateY(-50%) translateX(2px);
|
|
93
|
+
transition:
|
|
94
|
+
opacity 0.16s ease,
|
|
95
|
+
transform 0.16s ease;
|
|
96
|
+
white-space: nowrap;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.tn-code-action-copy[data-copy-state='copied']::after,
|
|
100
|
+
.tn-code-action-copy[data-copy-state='failed']::after {
|
|
101
|
+
opacity: 1;
|
|
102
|
+
transform: translateY(-50%) translateX(0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* .dark .tn-code-action-copy img {
|
|
106
|
+
filter: invert(1);
|
|
107
|
+
} */
|
|
108
|
+
|
|
109
|
+
/* 移动端始终显示按钮 */
|
|
110
|
+
@media (max-width: 768px) {
|
|
111
|
+
.tn-code-actions {
|
|
112
|
+
/* opacity: 0.8; */
|
|
113
|
+
top: 6px;
|
|
114
|
+
right: 6px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.tn-code-action {
|
|
118
|
+
width: 28px;
|
|
119
|
+
height: 28px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.tn-code-action img {
|
|
123
|
+
width: 14px;
|
|
124
|
+
height: 14px;
|
|
125
|
+
}
|
|
126
|
+
}
|