@slidev/client 0.48.0-beta.2 → 0.48.0-beta.21
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/App.vue +7 -0
- package/builtin/Arrow.vue +2 -4
- package/builtin/CodeBlockWrapper.vue +14 -6
- package/builtin/KaTexBlockWrapper.vue +5 -4
- package/builtin/Mermaid.vue +4 -3
- package/builtin/Monaco.vue +109 -92
- package/builtin/RenderWhen.vue +3 -3
- package/builtin/ShikiMagicMove.vue +50 -0
- package/builtin/SlideCurrentNo.vue +2 -3
- package/builtin/SlidesTotal.vue +3 -4
- package/builtin/SlidevVideo.vue +9 -7
- package/builtin/Toc.vue +4 -4
- package/builtin/TocList.vue +4 -3
- package/builtin/Tweet.vue +3 -22
- package/builtin/VClick.ts +2 -1
- package/builtin/VClickGap.vue +3 -5
- package/builtin/VClicks.ts +1 -1
- package/composables/useClicks.ts +39 -20
- package/composables/useContext.ts +4 -9
- package/composables/useNav.ts +182 -44
- package/composables/useSwipeControls.ts +40 -0
- package/composables/useTocTree.ts +63 -0
- package/constants.ts +59 -10
- package/context.ts +73 -0
- package/env.ts +3 -12
- package/internals/ClicksSlider.vue +93 -0
- package/internals/Controls.vue +2 -2
- package/internals/DrawingControls.vue +39 -9
- package/internals/DrawingLayer.vue +3 -3
- package/internals/Goto.vue +7 -6
- package/internals/IconButton.vue +7 -3
- package/internals/InfoDialog.vue +1 -1
- package/internals/Modal.vue +1 -1
- package/internals/NavControls.vue +11 -10
- package/internals/NoteDisplay.vue +131 -8
- package/internals/NoteEditable.vue +128 -0
- package/internals/NoteStatic.vue +8 -6
- package/internals/PrintContainer.vue +8 -6
- package/internals/PrintSlide.vue +10 -11
- package/internals/PrintSlideClick.vue +14 -18
- package/internals/{SlidesOverview.vue → QuickOverview.vue} +31 -20
- package/internals/RecordingControls.vue +1 -1
- package/internals/RecordingDialog.vue +5 -6
- package/internals/{Editor.vue → SideEditor.vue} +9 -5
- package/internals/SlideContainer.vue +12 -9
- package/internals/SlideLoading.vue +19 -0
- package/internals/SlideWrapper.ts +32 -16
- package/internals/SlidesShow.vue +20 -18
- package/layouts/error.vue +5 -0
- package/layouts/two-cols-header.vue +9 -3
- package/logic/drawings.ts +13 -10
- package/logic/nav-state.ts +20 -0
- package/logic/nav.ts +51 -258
- package/logic/note.ts +9 -9
- package/logic/overview.ts +2 -2
- package/logic/route.ts +10 -1
- package/logic/slides.ts +19 -0
- package/logic/transition.ts +50 -0
- package/main.ts +8 -4
- package/modules/context.ts +7 -13
- package/modules/mermaid.ts +6 -7
- package/modules/{directives.ts → v-click.ts} +15 -15
- package/modules/v-mark.ts +159 -0
- package/package.json +27 -16
- package/{internals/EntrySelect.vue → pages/entry.vue} +7 -0
- package/{internals/NotesView.vue → pages/notes.vue} +7 -6
- package/pages/overview.vue +227 -0
- package/{internals/Play.vue → pages/play.vue} +17 -13
- package/{internals/PresenterPrint.vue → pages/presenter/print.vue} +13 -8
- package/{internals/Presenter.vue → pages/presenter.vue} +114 -105
- package/{internals/Print.vue → pages/print.vue} +3 -4
- package/routes.ts +28 -60
- package/setup/codemirror.ts +8 -3
- package/setup/monaco.ts +108 -44
- package/setup/root.ts +8 -9
- package/setup/shortcuts.ts +2 -1
- package/shim-vue.d.ts +38 -0
- package/shim.d.ts +1 -13
- package/state/index.ts +10 -10
- package/styles/code.css +7 -3
- package/styles/index.css +68 -7
- package/styles/katex.css +1 -1
- package/styles/layouts-base.css +17 -12
- package/styles/monaco.css +27 -0
- package/styles/vars.css +1 -0
- package/uno.config.ts +14 -2
- package/utils.ts +15 -2
- package/iframes/monaco/index.css +0 -28
- package/iframes/monaco/index.html +0 -7
- package/iframes/monaco/index.ts +0 -260
- package/internals/NoteEditor.vue +0 -88
package/modules/mermaid.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import mermaid from 'mermaid/dist/mermaid.esm.mjs'
|
|
2
|
-
import
|
|
3
|
-
import { decode } from 'js-base64'
|
|
2
|
+
import lz from 'lz-string'
|
|
4
3
|
import { clearUndefined } from '@antfu/utils'
|
|
5
4
|
import setupMermaid from '../setup/mermaid'
|
|
5
|
+
import { makeId } from '../logic/utils'
|
|
6
6
|
|
|
7
7
|
mermaid.startOnLoad = false
|
|
8
8
|
mermaid.initialize({ startOnLoad: false })
|
|
9
9
|
|
|
10
|
-
const nanoid = customAlphabet('abcedfghicklmn', 10)
|
|
11
10
|
const cache = new Map<string, string>()
|
|
12
11
|
|
|
13
|
-
export async function renderMermaid(
|
|
14
|
-
const key =
|
|
12
|
+
export async function renderMermaid(lzEncoded: string, options: any) {
|
|
13
|
+
const key = lzEncoded + JSON.stringify(options)
|
|
15
14
|
const _cache = cache.get(key)
|
|
16
15
|
if (_cache)
|
|
17
16
|
return _cache
|
|
@@ -21,8 +20,8 @@ export async function renderMermaid(encoded: string, options: any) {
|
|
|
21
20
|
...clearUndefined(setupMermaid() || {}),
|
|
22
21
|
...clearUndefined(options),
|
|
23
22
|
})
|
|
24
|
-
const code =
|
|
25
|
-
const id =
|
|
23
|
+
const code = lz.decompressFromBase64(lzEncoded)
|
|
24
|
+
const id = makeId()
|
|
26
25
|
const { svg } = await mermaid.render(id, code)
|
|
27
26
|
cache.set(key, svg)
|
|
28
27
|
return svg
|
|
@@ -11,19 +11,21 @@ import {
|
|
|
11
11
|
injectionClicksContext,
|
|
12
12
|
} from '../constants'
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
export type VClickValue = string | [string | number, string | number] | boolean
|
|
15
|
+
|
|
16
|
+
export function dirInject<T = unknown>(dir: DirectiveBinding<any>, key: InjectionKey<T> | string, defaultValue?: T): T | undefined {
|
|
15
17
|
return (dir.instance?.$ as any).provides[key as any] ?? defaultValue
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export
|
|
20
|
+
export function createVClickDirectives() {
|
|
19
21
|
return {
|
|
20
22
|
install(app: App) {
|
|
21
|
-
app.directive('click', {
|
|
23
|
+
app.directive<HTMLElement, VClickValue>('click', {
|
|
22
24
|
// @ts-expect-error extra prop
|
|
23
25
|
name: 'v-click',
|
|
24
26
|
|
|
25
|
-
mounted(el
|
|
26
|
-
const resolved = resolveClick(el, dir)
|
|
27
|
+
mounted(el, dir) {
|
|
28
|
+
const resolved = resolveClick(el, dir, dir.value)
|
|
27
29
|
if (resolved == null)
|
|
28
30
|
return
|
|
29
31
|
|
|
@@ -55,12 +57,12 @@ export default function createDirectives() {
|
|
|
55
57
|
unmounted,
|
|
56
58
|
})
|
|
57
59
|
|
|
58
|
-
app.directive('after', {
|
|
60
|
+
app.directive<HTMLElement, VClickValue>('after', {
|
|
59
61
|
// @ts-expect-error extra prop
|
|
60
62
|
name: 'v-after',
|
|
61
63
|
|
|
62
|
-
mounted(el
|
|
63
|
-
const resolved = resolveClick(el, dir, true)
|
|
64
|
+
mounted(el, dir) {
|
|
65
|
+
const resolved = resolveClick(el, dir, dir.value, true)
|
|
64
66
|
if (resolved == null)
|
|
65
67
|
return
|
|
66
68
|
|
|
@@ -86,12 +88,12 @@ export default function createDirectives() {
|
|
|
86
88
|
unmounted,
|
|
87
89
|
})
|
|
88
90
|
|
|
89
|
-
app.directive('click-hide', {
|
|
91
|
+
app.directive<HTMLElement, VClickValue>('click-hide', {
|
|
90
92
|
// @ts-expect-error extra prop
|
|
91
93
|
name: 'v-click-hide',
|
|
92
94
|
|
|
93
|
-
mounted(el
|
|
94
|
-
const resolved = resolveClick(el, dir, false, true)
|
|
95
|
+
mounted(el, dir) {
|
|
96
|
+
const resolved = resolveClick(el, dir, dir.value, false, true)
|
|
95
97
|
if (resolved == null)
|
|
96
98
|
return
|
|
97
99
|
|
|
@@ -127,14 +129,12 @@ function isCurrent(thisClick: number | [number, number], clicks: number) {
|
|
|
127
129
|
: thisClick === clicks
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
function resolveClick(el: Element, dir: DirectiveBinding<any>, clickAfter = false, flagHide = false): ResolvedClicksInfo | null {
|
|
132
|
+
export function resolveClick(el: Element, dir: DirectiveBinding<any>, value: VClickValue, clickAfter = false, flagHide = false): ResolvedClicksInfo | null {
|
|
131
133
|
const ctx = dirInject(dir, injectionClicksContext)?.value
|
|
132
134
|
|
|
133
135
|
if (!el || !ctx || ctx.disabled)
|
|
134
136
|
return null
|
|
135
137
|
|
|
136
|
-
let value = dir.value
|
|
137
|
-
|
|
138
138
|
if (value === false || value === 'false')
|
|
139
139
|
return null
|
|
140
140
|
|
|
@@ -153,7 +153,7 @@ function resolveClick(el: Element, dir: DirectiveBinding<any>, clickAfter = fals
|
|
|
153
153
|
// range (absolute)
|
|
154
154
|
delta = 0
|
|
155
155
|
thisClick = value as [number, number]
|
|
156
|
-
maxClick = value[1]
|
|
156
|
+
maxClick = +value[1]
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
159
|
({ start: thisClick, end: maxClick, delta } = ctx.resolve(value))
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { RoughAnnotationConfig } from '@slidev/rough-notation'
|
|
2
|
+
import { annotate } from '@slidev/rough-notation'
|
|
3
|
+
import type { App } from 'vue'
|
|
4
|
+
import { computed, watchEffect } from 'vue'
|
|
5
|
+
import type { VClickValue } from './v-click'
|
|
6
|
+
import { resolveClick } from './v-click'
|
|
7
|
+
|
|
8
|
+
export interface RoughDirectiveOptions extends Partial<RoughAnnotationConfig> {
|
|
9
|
+
at: VClickValue
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type RoughDirectiveValue = VClickValue | RoughDirectiveOptions
|
|
13
|
+
|
|
14
|
+
function addClass(options: RoughDirectiveOptions, cls: string) {
|
|
15
|
+
options.class = [options.class, cls].filter(Boolean).join(' ')
|
|
16
|
+
return options
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Definitions of supported modifiers
|
|
20
|
+
const vMarkModifiers: Record<string, (options: RoughDirectiveOptions, value?: any) => RoughDirectiveOptions> = {
|
|
21
|
+
// Types
|
|
22
|
+
'box': options => Object.assign(options, { type: 'box' }),
|
|
23
|
+
'circle': options => Object.assign(options, { type: 'circle' }),
|
|
24
|
+
'underline': options => Object.assign(options, { type: 'underline' }),
|
|
25
|
+
'highlight': options => Object.assign(options, { type: 'highlight' }),
|
|
26
|
+
'strike-through': options => Object.assign(options, { type: 'strike-through' }),
|
|
27
|
+
'crossed-off': options => Object.assign(options, { type: 'crossed-off' }),
|
|
28
|
+
'bracket': options => Object.assign(options, { type: 'bracket' }),
|
|
29
|
+
|
|
30
|
+
// Type Aliases
|
|
31
|
+
'strike': options => Object.assign(options, { type: 'strike-through' }),
|
|
32
|
+
'cross': options => Object.assign(options, { type: 'crossed-off' }),
|
|
33
|
+
'crossed': options => Object.assign(options, { type: 'crossed-off' }),
|
|
34
|
+
'linethrough': options => Object.assign(options, { type: 'strike-through' }),
|
|
35
|
+
'line-through': options => Object.assign(options, { type: 'strike-through' }),
|
|
36
|
+
|
|
37
|
+
// Colors
|
|
38
|
+
// @unocss-include
|
|
39
|
+
'black': options => addClass(options, 'text-black'),
|
|
40
|
+
'blue': options => addClass(options, 'text-blue'),
|
|
41
|
+
'cyan': options => addClass(options, 'text-cyan'),
|
|
42
|
+
'gray': options => addClass(options, 'text-gray'),
|
|
43
|
+
'green': options => addClass(options, 'text-green'),
|
|
44
|
+
'indigo': options => addClass(options, 'text-indigo'),
|
|
45
|
+
'lime': options => addClass(options, 'text-lime'),
|
|
46
|
+
'orange': options => addClass(options, 'text-orange'),
|
|
47
|
+
'pink': options => addClass(options, 'text-pink'),
|
|
48
|
+
'purple': options => addClass(options, 'text-purple'),
|
|
49
|
+
'red': options => addClass(options, 'text-red'),
|
|
50
|
+
'teal': options => addClass(options, 'text-teal'),
|
|
51
|
+
'white': options => addClass(options, 'text-white'),
|
|
52
|
+
'yellow': options => addClass(options, 'text-yellow'),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const vMarkModifiersDynamic: [RegExp, (match: RegExpMatchArray, options: RoughDirectiveOptions, value?: any) => RoughDirectiveOptions][] = [
|
|
56
|
+
// Support setting delay like `v-mark.delay300="1"`
|
|
57
|
+
[/^delay-?(\d+)?$/, (match, options, value) => {
|
|
58
|
+
const ms = (match[1] ? Number.parseInt(match[1]) : value) || 300
|
|
59
|
+
options.delay = ms
|
|
60
|
+
return options
|
|
61
|
+
}],
|
|
62
|
+
// Support setting opacity like `v-mark.op50="1"`
|
|
63
|
+
[/^(?:op|opacity)-?(\d+)?$/, (match, options, value) => {
|
|
64
|
+
const opacity = (match[1] ? Number.parseInt(match[1]) : value) || 100
|
|
65
|
+
options.opacity = opacity / 100
|
|
66
|
+
return options
|
|
67
|
+
}],
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* This supports v-mark directive to add notations to elements, powered by `rough-notation`.
|
|
72
|
+
*/
|
|
73
|
+
export function createVMarkDirective() {
|
|
74
|
+
return {
|
|
75
|
+
install(app: App) {
|
|
76
|
+
app.directive<HTMLElement, RoughDirectiveValue>('mark', {
|
|
77
|
+
// @ts-expect-error extra prop
|
|
78
|
+
name: 'v-mark',
|
|
79
|
+
|
|
80
|
+
mounted: (el, binding) => {
|
|
81
|
+
const options = computed(() => {
|
|
82
|
+
const bindingOptions = (typeof binding.value === 'object' && !Array.isArray(binding.value))
|
|
83
|
+
? { ...binding.value }
|
|
84
|
+
: { at: binding.value }
|
|
85
|
+
|
|
86
|
+
let modifierOptions: RoughDirectiveOptions = { at: bindingOptions.at }
|
|
87
|
+
const unknownModifiers = Object.entries(binding.modifiers)
|
|
88
|
+
.filter(([k, v]) => {
|
|
89
|
+
if (vMarkModifiers[k]) {
|
|
90
|
+
modifierOptions = vMarkModifiers[k](modifierOptions, v)
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
for (const [re, fn] of vMarkModifiersDynamic) {
|
|
94
|
+
const match = k.match(re)
|
|
95
|
+
if (match) {
|
|
96
|
+
modifierOptions = fn(match, modifierOptions, v)
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
if (unknownModifiers.length)
|
|
104
|
+
console.warn('[Slidev] Invalid modifiers for v-mark:', unknownModifiers)
|
|
105
|
+
|
|
106
|
+
const options = {
|
|
107
|
+
...modifierOptions,
|
|
108
|
+
...bindingOptions,
|
|
109
|
+
}
|
|
110
|
+
options.type ||= 'underline'
|
|
111
|
+
|
|
112
|
+
return options
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const annotation = annotate(el, options.value as RoughAnnotationConfig)
|
|
116
|
+
|
|
117
|
+
const resolvedClick = resolveClick(el, binding, options.value.at)
|
|
118
|
+
if (!resolvedClick) {
|
|
119
|
+
console.error('[Slidev] Invalid value for v-mark:', options.value.at)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
watchEffect(() => {
|
|
124
|
+
let shouldShow: boolean | undefined
|
|
125
|
+
|
|
126
|
+
if (options.value.class)
|
|
127
|
+
annotation.class = options.value.class
|
|
128
|
+
if (options.value.color)
|
|
129
|
+
annotation.color = options.value.color
|
|
130
|
+
|
|
131
|
+
const at = options.value.at
|
|
132
|
+
|
|
133
|
+
if (at === true) {
|
|
134
|
+
shouldShow = true
|
|
135
|
+
}
|
|
136
|
+
else if (at === false) {
|
|
137
|
+
shouldShow = false
|
|
138
|
+
}
|
|
139
|
+
else if (resolvedClick) {
|
|
140
|
+
shouldShow = resolvedClick.isActive.value
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.error('[Slidev] Invalid value for v-mark:', at)
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (shouldShow == null)
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
if (shouldShow)
|
|
151
|
+
annotation.show()
|
|
152
|
+
else
|
|
153
|
+
annotation.hide()
|
|
154
|
+
})
|
|
155
|
+
},
|
|
156
|
+
})
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slidev/client",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.48.0-beta.21",
|
|
4
5
|
"description": "Presentation slides for developers",
|
|
5
6
|
"author": "antfu <anthonyfu117@hotmail.com>",
|
|
6
7
|
"license": "MIT",
|
|
@@ -13,6 +14,12 @@
|
|
|
13
14
|
"bugs": "https://github.com/slidevjs/slidev/issues",
|
|
14
15
|
"exports": {
|
|
15
16
|
"./package.json": "./package.json",
|
|
17
|
+
"./constants": "./constants.ts",
|
|
18
|
+
"./context": "./context.ts",
|
|
19
|
+
"./env": "./env.ts",
|
|
20
|
+
"./layoutHelper": "./layoutHelper.ts",
|
|
21
|
+
"./routes": "./routes.ts",
|
|
22
|
+
"./utils": "./utils.ts",
|
|
16
23
|
"./*": "./*"
|
|
17
24
|
},
|
|
18
25
|
"engines": {
|
|
@@ -22,34 +29,38 @@
|
|
|
22
29
|
"@antfu/utils": "^0.7.7",
|
|
23
30
|
"@iconify-json/carbon": "^1.1.30",
|
|
24
31
|
"@iconify-json/ph": "^1.1.11",
|
|
25
|
-
"@
|
|
32
|
+
"@iconify-json/svg-spinners": "^1.1.2",
|
|
33
|
+
"@shikijs/monaco": "^1.1.7",
|
|
34
|
+
"@shikijs/vitepress-twoslash": "^1.1.7",
|
|
35
|
+
"@slidev/rough-notation": "^0.1.0",
|
|
36
|
+
"@typescript/ata": "^0.9.4",
|
|
26
37
|
"@unhead/vue": "^1.8.10",
|
|
27
38
|
"@unocss/reset": "^0.58.5",
|
|
28
|
-
"@vueuse/core": "^10.
|
|
29
|
-
"@vueuse/math": "^10.
|
|
30
|
-
"@vueuse/motion": "^2.
|
|
39
|
+
"@vueuse/core": "^10.9.0",
|
|
40
|
+
"@vueuse/math": "^10.9.0",
|
|
41
|
+
"@vueuse/motion": "^2.1.0",
|
|
31
42
|
"codemirror": "^5.65.16",
|
|
32
|
-
"
|
|
33
|
-
"drauu": "^0.3.7",
|
|
43
|
+
"drauu": "^0.4.0",
|
|
34
44
|
"file-saver": "^2.0.5",
|
|
35
45
|
"floating-vue": "^5.2.2",
|
|
36
46
|
"fuse.js": "^7.0.0",
|
|
37
|
-
"js-base64": "^3.7.6",
|
|
38
47
|
"js-yaml": "^4.1.0",
|
|
39
48
|
"katex": "^0.16.9",
|
|
49
|
+
"lz-string": "^1.5.0",
|
|
40
50
|
"mermaid": "^10.8.0",
|
|
41
|
-
"monaco-editor": "^0.
|
|
42
|
-
"nanoid": "^5.0.5",
|
|
51
|
+
"monaco-editor": "^0.46.0",
|
|
43
52
|
"prettier": "^3.2.5",
|
|
44
53
|
"recordrtc": "^5.6.2",
|
|
45
|
-
"
|
|
54
|
+
"shiki": "^1.1.7",
|
|
55
|
+
"shiki-magic-move": "^0.1.0",
|
|
56
|
+
"typescript": "^5.3.3",
|
|
46
57
|
"unocss": "^0.58.5",
|
|
47
|
-
"vue": "^3.4.
|
|
48
|
-
"vue-router": "^4.
|
|
49
|
-
"@slidev/
|
|
50
|
-
"@slidev/
|
|
58
|
+
"vue": "^3.4.21",
|
|
59
|
+
"vue-router": "^4.3.0",
|
|
60
|
+
"@slidev/types": "0.48.0-beta.21",
|
|
61
|
+
"@slidev/parser": "0.48.0-beta.21"
|
|
51
62
|
},
|
|
52
63
|
"devDependencies": {
|
|
53
|
-
"vite": "^5.1.
|
|
64
|
+
"vite": "^5.1.4"
|
|
54
65
|
}
|
|
55
66
|
}
|
|
@@ -21,5 +21,12 @@
|
|
|
21
21
|
<carbon:catalog class="text-3em op50" />
|
|
22
22
|
Notes
|
|
23
23
|
</RouterLink>
|
|
24
|
+
<RouterLink
|
|
25
|
+
to="/overview"
|
|
26
|
+
class="flex flex-col gap-2 items-center justify-center h-40 min-w-40 rounded bg-gray:10 p4 hover:bg-gray/20"
|
|
27
|
+
>
|
|
28
|
+
<carbon:list-boxes class="text-3em op50" />
|
|
29
|
+
Overview
|
|
30
|
+
</RouterLink>
|
|
24
31
|
</div>
|
|
25
32
|
</template>
|
|
@@ -5,10 +5,9 @@ import { useLocalStorage } from '@vueuse/core'
|
|
|
5
5
|
import { configs } from '../env'
|
|
6
6
|
import { sharedState } from '../state/shared'
|
|
7
7
|
import { fullscreen } from '../state'
|
|
8
|
-
import { total } from '../logic/nav'
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import IconButton from './IconButton.vue'
|
|
8
|
+
import { slides, total } from '../logic/nav'
|
|
9
|
+
import NoteDisplay from '../internals/NoteDisplay.vue'
|
|
10
|
+
import IconButton from '../internals/IconButton.vue'
|
|
12
11
|
|
|
13
12
|
const slideTitle = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
|
|
14
13
|
useHead({
|
|
@@ -20,7 +19,7 @@ const { isFullscreen, toggle: toggleFullscreen } = fullscreen
|
|
|
20
19
|
const scroller = ref<HTMLDivElement>()
|
|
21
20
|
const fontSize = useLocalStorage('slidev-notes-font-size', 18)
|
|
22
21
|
const pageNo = computed(() => sharedState.lastUpdate?.type === 'viewer' ? sharedState.viewerPage : sharedState.page)
|
|
23
|
-
const currentRoute = computed(() =>
|
|
22
|
+
const currentRoute = computed(() => slides.value.find(i => i.no === pageNo.value))
|
|
24
23
|
|
|
25
24
|
watch(pageNo, () => {
|
|
26
25
|
scroller.value?.scrollTo({ left: 0, top: 0, behavior: 'smooth' })
|
|
@@ -51,9 +50,11 @@ function decreaseFontSize() {
|
|
|
51
50
|
:note="currentRoute?.meta?.slide?.note"
|
|
52
51
|
:note-html="currentRoute?.meta?.slide?.noteHTML"
|
|
53
52
|
:placeholder="`No notes for Slide ${pageNo}.`"
|
|
53
|
+
:clicks-context="currentRoute?.meta?.__clicksContext"
|
|
54
|
+
:auto-scroll="true"
|
|
54
55
|
/>
|
|
55
56
|
</div>
|
|
56
|
-
<div class="flex-none border-t border-
|
|
57
|
+
<div class="flex-none border-t border-main">
|
|
57
58
|
<div class="flex gap-1 items-center px-6 py-3">
|
|
58
59
|
<IconButton :title="isFullscreen ? 'Close fullscreen' : 'Enter fullscreen'" @click="toggleFullscreen">
|
|
59
60
|
<carbon:minimize v-if="isFullscreen" />
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
|
|
3
|
+
import { useHead } from '@unhead/vue'
|
|
4
|
+
import type { ClicksContext, SlideRoute } from '@slidev/types'
|
|
5
|
+
import { configs } from '../env'
|
|
6
|
+
import { getSlidePath, openInEditor, slides } from '../logic/nav'
|
|
7
|
+
import { useFixedClicks } from '../composables/useClicks'
|
|
8
|
+
import { isColorSchemaConfigured, isDark, toggleDark } from '../logic/dark'
|
|
9
|
+
import { getSlideClass } from '../utils'
|
|
10
|
+
import SlideContainer from '../internals/SlideContainer.vue'
|
|
11
|
+
import SlideWrapper from '../internals/SlideWrapper'
|
|
12
|
+
import DrawingPreview from '../internals/DrawingPreview.vue'
|
|
13
|
+
import IconButton from '../internals/IconButton.vue'
|
|
14
|
+
import NoteEditable from '../internals/NoteEditable.vue'
|
|
15
|
+
import ClicksSlider from '../internals/ClicksSlider.vue'
|
|
16
|
+
import { CLICKS_MAX } from '../constants'
|
|
17
|
+
|
|
18
|
+
const cardWidth = 450
|
|
19
|
+
|
|
20
|
+
const slideTitle = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
|
|
21
|
+
useHead({
|
|
22
|
+
title: `Overview - ${slideTitle}`,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const blocks: Map<number, HTMLElement> = reactive(new Map())
|
|
26
|
+
const activeBlocks = ref<number[]>([])
|
|
27
|
+
const edittingNote = ref<number | null>(null)
|
|
28
|
+
const wordCounts = computed(() => slides.value.map(route => wordCount(route.meta?.slide?.note || '')))
|
|
29
|
+
const totalWords = computed(() => wordCounts.value.reduce((a, b) => a + b, 0))
|
|
30
|
+
const totalClicks = computed(() => slides.value.map(route => getSlideClicks(route)).reduce((a, b) => a + b, 0))
|
|
31
|
+
|
|
32
|
+
const clicksContextMap = new WeakMap<SlideRoute, ClicksContext>()
|
|
33
|
+
function getClicksContext(route: SlideRoute) {
|
|
34
|
+
// We create a local clicks context to calculate the total clicks of the slide
|
|
35
|
+
if (!clicksContextMap.has(route))
|
|
36
|
+
clicksContextMap.set(route, useFixedClicks(route, CLICKS_MAX))
|
|
37
|
+
return clicksContextMap.get(route)!
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getSlideClicks(route: SlideRoute) {
|
|
41
|
+
return route.meta?.clicks || getClicksContext(route)?.total
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function wordCount(str: string) {
|
|
45
|
+
return str.match(/[\w\d\’\'-]+/gi)?.length || 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isElementInViewport(el: HTMLElement) {
|
|
49
|
+
const rect = el.getBoundingClientRect()
|
|
50
|
+
const delta = 20
|
|
51
|
+
return (
|
|
52
|
+
rect.top >= 0 - delta
|
|
53
|
+
&& rect.left >= 0 - delta
|
|
54
|
+
&& rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + delta
|
|
55
|
+
&& rect.right <= (window.innerWidth || document.documentElement.clientWidth) + delta
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function checkActiveBlocks() {
|
|
60
|
+
const active: number[] = []
|
|
61
|
+
Array.from(blocks.entries())
|
|
62
|
+
.forEach(([idx, el]) => {
|
|
63
|
+
if (isElementInViewport(el))
|
|
64
|
+
active.push(idx)
|
|
65
|
+
})
|
|
66
|
+
activeBlocks.value = active
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function openSlideInNewTab(path: string) {
|
|
70
|
+
const a = document.createElement('a')
|
|
71
|
+
a.target = '_blank'
|
|
72
|
+
a.href = path
|
|
73
|
+
a.click()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function scrollToSlide(idx: number) {
|
|
77
|
+
const el = blocks.get(idx)
|
|
78
|
+
if (el)
|
|
79
|
+
el.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function onMarkerClick(e: MouseEvent, clicks: number, route: SlideRoute) {
|
|
83
|
+
const ctx = getClicksContext(route)
|
|
84
|
+
if (ctx.current === clicks)
|
|
85
|
+
ctx.current = CLICKS_MAX
|
|
86
|
+
else
|
|
87
|
+
ctx.current = clicks
|
|
88
|
+
e.preventDefault()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
onMounted(() => {
|
|
92
|
+
nextTick(() => {
|
|
93
|
+
checkActiveBlocks()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<template>
|
|
99
|
+
<div class="h-screen w-screen of-hidden flex">
|
|
100
|
+
<nav class="h-full flex flex-col border-r border-main p2 select-none">
|
|
101
|
+
<div class="flex flex-col flex-auto items-center justify-center group gap-1">
|
|
102
|
+
<div
|
|
103
|
+
v-for="(route, idx) of slides"
|
|
104
|
+
:key="route.no"
|
|
105
|
+
class="relative"
|
|
106
|
+
>
|
|
107
|
+
<button
|
|
108
|
+
class="relative transition duration-300 w-8 h-8 rounded hover:bg-active hover:op100"
|
|
109
|
+
:class="activeBlocks.includes(idx) ? 'op100 text-primary bg-gray:5' : 'op20'"
|
|
110
|
+
@click="scrollToSlide(idx)"
|
|
111
|
+
>
|
|
112
|
+
<div>{{ idx + 1 }}</div>
|
|
113
|
+
</button>
|
|
114
|
+
<div
|
|
115
|
+
v-if="route.meta?.slide?.title"
|
|
116
|
+
class="pointer-events-none select-none absolute left-110% bg-main top-50% translate-y--50% ws-nowrap z-10 px2 shadow-xl rounded border border-main transition duration-400 op0 group-hover:op100"
|
|
117
|
+
:class="activeBlocks.includes(idx) ? 'text-primary' : 'text-main important-text-op-50'"
|
|
118
|
+
>
|
|
119
|
+
{{ route.meta?.slide?.title }}
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
<IconButton
|
|
124
|
+
v-if="!isColorSchemaConfigured"
|
|
125
|
+
:title="isDark ? 'Switch to light mode theme' : 'Switch to dark mode theme'"
|
|
126
|
+
@click="toggleDark()"
|
|
127
|
+
>
|
|
128
|
+
<carbon-moon v-if="isDark" />
|
|
129
|
+
<carbon-sun v-else />
|
|
130
|
+
</IconButton>
|
|
131
|
+
</nav>
|
|
132
|
+
<main
|
|
133
|
+
class="flex-1 h-full of-auto"
|
|
134
|
+
:style="`grid-template-columns: repeat(auto-fit,minmax(${cardWidth}px,1fr))`"
|
|
135
|
+
@scroll="checkActiveBlocks"
|
|
136
|
+
>
|
|
137
|
+
<div
|
|
138
|
+
v-for="(route, idx) of slides"
|
|
139
|
+
:key="route.no"
|
|
140
|
+
:ref="el => blocks.set(idx, el as any)"
|
|
141
|
+
class="relative border-t border-main of-hidden flex gap-4 min-h-50 group"
|
|
142
|
+
>
|
|
143
|
+
<div class="select-none w-13 text-right my4 flex flex-col gap-1 items-end">
|
|
144
|
+
<div class="text-3xl op20 mb2">
|
|
145
|
+
{{ idx + 1 }}
|
|
146
|
+
</div>
|
|
147
|
+
<IconButton
|
|
148
|
+
class="mr--3 op0 group-hover:op80"
|
|
149
|
+
title="Play in new tab"
|
|
150
|
+
@click="openSlideInNewTab(getSlidePath(route, false))"
|
|
151
|
+
>
|
|
152
|
+
<carbon:presentation-file />
|
|
153
|
+
</IconButton>
|
|
154
|
+
<IconButton
|
|
155
|
+
v-if="route.meta?.slide"
|
|
156
|
+
class="mr--3 op0 group-hover:op80"
|
|
157
|
+
title="Open in editor"
|
|
158
|
+
@click="openInEditor(`${route.meta.slide.filepath}:${route.meta.slide.start}`)"
|
|
159
|
+
>
|
|
160
|
+
<carbon:cics-program />
|
|
161
|
+
</IconButton>
|
|
162
|
+
</div>
|
|
163
|
+
<div class="flex flex-col gap-2 my5">
|
|
164
|
+
<div
|
|
165
|
+
class="border rounded border-main overflow-hidden bg-main select-none h-max"
|
|
166
|
+
@dblclick="openSlideInNewTab(getSlidePath(route, false))"
|
|
167
|
+
>
|
|
168
|
+
<SlideContainer
|
|
169
|
+
:key="route.no"
|
|
170
|
+
:width="cardWidth"
|
|
171
|
+
:clicks-disabled="true"
|
|
172
|
+
class="pointer-events-none important:[&_*]:select-none"
|
|
173
|
+
>
|
|
174
|
+
<SlideWrapper
|
|
175
|
+
:is="route.component!"
|
|
176
|
+
:clicks-context="getClicksContext(route)"
|
|
177
|
+
:class="getSlideClass(route)"
|
|
178
|
+
:route="route"
|
|
179
|
+
render-context="overview"
|
|
180
|
+
/>
|
|
181
|
+
<DrawingPreview :page="route.no" />
|
|
182
|
+
</SlideContainer>
|
|
183
|
+
</div>
|
|
184
|
+
<ClicksSlider
|
|
185
|
+
v-if="getSlideClicks(route)"
|
|
186
|
+
mt-2
|
|
187
|
+
:clicks-context="getClicksContext(route)"
|
|
188
|
+
class="w-full"
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
<div class="py3 mt-0.5 mr--8 ml--4 op0 transition group-hover:op100">
|
|
192
|
+
<IconButton
|
|
193
|
+
title="Edit Note"
|
|
194
|
+
class="rounded-full w-9 h-9 text-sm"
|
|
195
|
+
:class="edittingNote === idx ? 'important:op0' : ''"
|
|
196
|
+
@click="edittingNote = idx"
|
|
197
|
+
>
|
|
198
|
+
<carbon:pen />
|
|
199
|
+
</IconButton>
|
|
200
|
+
</div>
|
|
201
|
+
<NoteEditable
|
|
202
|
+
:no="idx"
|
|
203
|
+
class="max-w-250 w-250 text-lg rounded p3"
|
|
204
|
+
:auto-height="true"
|
|
205
|
+
:editing="edittingNote === idx"
|
|
206
|
+
:clicks-context="getClicksContext(route)"
|
|
207
|
+
@dblclick="edittingNote !== idx ? edittingNote = idx : null"
|
|
208
|
+
@update:editing="edittingNote = null"
|
|
209
|
+
@marker-click="(e, clicks) => onMarkerClick(e, clicks, route)"
|
|
210
|
+
/>
|
|
211
|
+
<div
|
|
212
|
+
v-if="wordCounts[idx] > 0"
|
|
213
|
+
class="select-none absolute bottom-0 right-0 bg-main rounded-tl p2 op35 text-xs"
|
|
214
|
+
>
|
|
215
|
+
{{ wordCounts[idx] }} words
|
|
216
|
+
</div>
|
|
217
|
+
</div>
|
|
218
|
+
</main>
|
|
219
|
+
<div class="absolute top-0 right-0 px3 py1.5 border-b border-l rounded-lb bg-main border-main select-none">
|
|
220
|
+
<div class="text-xs op50">
|
|
221
|
+
{{ slides.length }} slides ·
|
|
222
|
+
{{ totalClicks + slides.length - 1 }} clicks ·
|
|
223
|
+
{{ totalWords }} words
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|