@slidev/client 0.48.0-beta.8 → 0.48.0

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.
Files changed (98) hide show
  1. package/App.vue +7 -0
  2. package/builtin/Arrow.vue +2 -4
  3. package/builtin/CodeBlockWrapper.vue +33 -28
  4. package/builtin/KaTexBlockWrapper.vue +1 -1
  5. package/builtin/Link.vue +3 -1
  6. package/builtin/Mermaid.vue +4 -3
  7. package/builtin/Monaco.vue +166 -93
  8. package/builtin/ShikiMagicMove.vue +103 -0
  9. package/builtin/SlidevVideo.vue +1 -1
  10. package/builtin/Toc.vue +1 -1
  11. package/builtin/TocList.vue +4 -3
  12. package/builtin/Tweet.vue +12 -9
  13. package/builtin/VClick.ts +2 -1
  14. package/composables/useClicks.ts +19 -32
  15. package/composables/useDarkMode.ts +9 -0
  16. package/composables/useDrawings.ts +181 -0
  17. package/composables/useNav.ts +346 -44
  18. package/{logic/note.ts → composables/useSlideInfo.ts} +13 -16
  19. package/composables/useSwipeControls.ts +43 -0
  20. package/composables/useTocTree.ts +81 -0
  21. package/composables/useViewTransition.ts +7 -4
  22. package/constants.ts +4 -3
  23. package/context.ts +13 -6
  24. package/env.ts +7 -16
  25. package/index.html +1 -0
  26. package/index.ts +12 -0
  27. package/internals/ClicksSlider.vue +93 -0
  28. package/internals/CodeRunner.vue +142 -0
  29. package/internals/Controls.vue +2 -2
  30. package/internals/DomElement.vue +18 -0
  31. package/internals/DrawingControls.vue +15 -17
  32. package/internals/DrawingLayer.vue +6 -5
  33. package/internals/DrawingPreview.vue +4 -2
  34. package/internals/Goto.vue +9 -6
  35. package/internals/IconButton.vue +7 -3
  36. package/internals/NavControls.vue +31 -12
  37. package/internals/NoteDisplay.vue +131 -8
  38. package/internals/NoteEditable.vue +129 -0
  39. package/internals/NoteStatic.vue +8 -6
  40. package/internals/PrintContainer.vue +11 -8
  41. package/internals/PrintSlide.vue +11 -12
  42. package/internals/PrintSlideClick.vue +14 -19
  43. package/internals/{SlidesOverview.vue → QuickOverview.vue} +35 -22
  44. package/internals/RecordingControls.vue +1 -1
  45. package/internals/RecordingDialog.vue +5 -6
  46. package/internals/{Editor.vue → SideEditor.vue} +26 -17
  47. package/internals/SlideContainer.vue +13 -9
  48. package/internals/SlideLoading.vue +19 -0
  49. package/internals/SlideWrapper.vue +79 -0
  50. package/internals/SlidesShow.vue +36 -22
  51. package/layouts/error.vue +5 -0
  52. package/layouts/two-cols-header.vue +9 -3
  53. package/logic/overview.ts +2 -2
  54. package/logic/route.ts +16 -5
  55. package/logic/slides.ts +20 -0
  56. package/logic/transition.ts +50 -0
  57. package/logic/utils.ts +24 -1
  58. package/main.ts +3 -15
  59. package/{setup → modules}/codemirror.ts +1 -3
  60. package/modules/context.ts +1 -46
  61. package/modules/mermaid.ts +9 -8
  62. package/package.json +21 -15
  63. package/{internals/EntrySelect.vue → pages/entry.vue} +7 -0
  64. package/{internals/NotesView.vue → pages/notes.vue} +9 -6
  65. package/pages/overview.vue +231 -0
  66. package/{internals/Play.vue → pages/play.vue} +22 -15
  67. package/{internals/PresenterPrint.vue → pages/presenter/print.vue} +15 -8
  68. package/{internals/Presenter.vue → pages/presenter.vue} +129 -107
  69. package/{internals/Print.vue → pages/print.vue} +6 -5
  70. package/routes.ts +26 -57
  71. package/setup/code-runners.ts +164 -0
  72. package/setup/main.ts +39 -9
  73. package/setup/mermaid.ts +5 -6
  74. package/setup/monaco.ts +114 -51
  75. package/setup/root.ts +62 -18
  76. package/setup/shortcuts.ts +15 -12
  77. package/shim-vue.d.ts +34 -0
  78. package/shim.d.ts +1 -13
  79. package/state/index.ts +2 -2
  80. package/styles/code.css +9 -5
  81. package/styles/index.css +63 -7
  82. package/styles/katex.css +1 -1
  83. package/styles/layouts-base.css +17 -12
  84. package/styles/shiki-twoslash.css +1 -1
  85. package/styles/vars.css +1 -0
  86. package/uno.config.ts +14 -2
  87. package/utils.ts +15 -2
  88. package/composables/useContext.ts +0 -17
  89. package/composables/useTweetScript.ts +0 -17
  90. package/iframes/monaco/index.css +0 -28
  91. package/iframes/monaco/index.html +0 -7
  92. package/iframes/monaco/index.ts +0 -260
  93. package/internals/NoteEditor.vue +0 -88
  94. package/internals/SlideWrapper.ts +0 -58
  95. package/logic/drawings.ts +0 -161
  96. package/logic/nav.ts +0 -278
  97. package/setup/prettier.ts +0 -43
  98. /package/{composables → logic}/hmr.ts +0 -0
@@ -0,0 +1,20 @@
1
+ import type { SlideRoute } from '@slidev/types'
2
+ import { slides } from '#slidev/slides'
3
+
4
+ export { slides }
5
+
6
+ export function getSlide(no: number | string) {
7
+ return slides.value.find(
8
+ s => (s.no === +no || s.meta.slide?.frontmatter.routeAlias === no),
9
+ )
10
+ }
11
+
12
+ export function getSlidePath(
13
+ route: SlideRoute | number | string,
14
+ presenter: boolean,
15
+ ) {
16
+ if (typeof route === 'number' || typeof route === 'string')
17
+ route = getSlide(route)!
18
+ const no = route.meta.slide?.frontmatter.routeAlias ?? route.no
19
+ return presenter ? `/presenter/${no}` : `/${no}`
20
+ }
@@ -0,0 +1,50 @@
1
+ import type { SlideRoute } from '@slidev/types'
2
+ import type { TransitionGroupProps } from 'vue'
3
+ import { configs } from '../env'
4
+
5
+ const transitionResolveMap: Record<string, string | undefined> = {
6
+ 'slide-left': 'slide-left | slide-right',
7
+ 'slide-right': 'slide-right | slide-left',
8
+ 'slide-up': 'slide-up | slide-down',
9
+ 'slide-down': 'slide-down | slide-up',
10
+ }
11
+
12
+ export function resolveTransition(transition?: string | TransitionGroupProps, isBackward = false): TransitionGroupProps | undefined {
13
+ if (!transition)
14
+ return undefined
15
+ if (typeof transition === 'string') {
16
+ transition = {
17
+ name: transition,
18
+ }
19
+ }
20
+
21
+ if (!transition.name)
22
+ return undefined
23
+
24
+ let name = transition.name.includes('|')
25
+ ? transition.name
26
+ : (transitionResolveMap[transition.name] || transition.name)
27
+
28
+ if (name.includes('|')) {
29
+ const [forward, backward] = name.split('|').map(i => i.trim())
30
+ name = isBackward ? backward : forward
31
+ }
32
+
33
+ if (!name)
34
+ return undefined
35
+
36
+ return {
37
+ ...transition,
38
+ name,
39
+ }
40
+ }
41
+
42
+ export function getCurrentTransition(direction: number, currentRoute?: SlideRoute, prevRoute?: SlideRoute) {
43
+ let transition = direction > 0
44
+ ? prevRoute?.meta?.transition
45
+ : currentRoute?.meta?.transition
46
+ if (!transition)
47
+ transition = configs.transition
48
+
49
+ return resolveTransition(transition, direction < 0)
50
+ }
package/logic/utils.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { parseRangeString } from '@slidev/parser/core'
1
2
  import { useTimestamp } from '@vueuse/core'
2
3
  import { computed, ref } from 'vue'
3
4
 
@@ -24,7 +25,7 @@ export function useTimer() {
24
25
 
25
26
  export function makeId(length = 5) {
26
27
  const result = []
27
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
28
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
28
29
  const charactersLength = characters.length
29
30
  for (let i = 0; i < length; i++)
30
31
  result.push(characters.charAt(Math.floor(Math.random() * charactersLength)))
@@ -48,3 +49,25 @@ export function normalizeAtProp(at: string | number = '+1'): [isRelative: boolea
48
49
  n,
49
50
  ]
50
51
  }
52
+
53
+ export function updateCodeHighlightRange(
54
+ rangeStr: string,
55
+ linesCount: number,
56
+ startLine: number,
57
+ getTokenOfLine: (line: number) => Element[],
58
+ ) {
59
+ const highlights: number[] = parseRangeString(linesCount + startLine - 1, rangeStr)
60
+ for (let line = 0; line < linesCount; line++) {
61
+ const tokens = getTokenOfLine(line)
62
+ const isHighlighted = highlights.includes(line + startLine)
63
+ for (const token of tokens) {
64
+ // token.classList.toggle(CLASS_VCLICK_TARGET, true)
65
+ token.classList.toggle('slidev-code-highlighted', isHighlighted)
66
+ token.classList.toggle('slidev-code-dishonored', !isHighlighted)
67
+
68
+ // for backward compatibility
69
+ token.classList.toggle('highlighted', isHighlighted)
70
+ token.classList.toggle('dishonored', !isHighlighted)
71
+ }
72
+ }
73
+ }
package/main.ts CHANGED
@@ -1,21 +1,9 @@
1
+ /// <reference types="@slidev/types/client" />
2
+
1
3
  import { createApp } from 'vue'
2
- import { createHead } from '@unhead/vue'
3
4
  import App from './App.vue'
4
5
  import setupMain from './setup/main'
5
- import { router } from './routes'
6
- import { createVClickDirectives } from './modules/v-click'
7
- import { createVMarkDirective } from './modules/v-mark'
8
- import { createSlidevContext } from './modules/context'
9
-
10
- import '/@slidev/styles'
11
6
 
12
7
  const app = createApp(App)
13
- app.use(router)
14
- app.use(createHead())
15
- app.use(createVClickDirectives())
16
- app.use(createVMarkDirective())
17
- app.use(createSlidevContext())
18
-
19
- setupMain({ app, router })
20
-
8
+ setupMain(app)
21
9
  app.mount('#app')
@@ -1,7 +1,7 @@
1
1
  import type { Ref, WritableComputedRef } from 'vue'
2
2
  import { onClickOutside } from '@vueuse/core'
3
3
  import { watch } from 'vue'
4
- import * as _CodeMirror from 'codemirror'
4
+ import CodeMirror from 'codemirror'
5
5
  import 'codemirror/mode/javascript/javascript'
6
6
  import 'codemirror/mode/css/css'
7
7
  import 'codemirror/mode/markdown/markdown'
@@ -10,8 +10,6 @@ import 'codemirror/mode/htmlmixed/htmlmixed'
10
10
  import 'codemirror/addon/display/placeholder'
11
11
  import 'codemirror/lib/codemirror.css'
12
12
 
13
- const CodeMirror = _CodeMirror.default ?? ('fromTextArea' in _CodeMirror ? _CodeMirror : globalThis.CodeMirror)
14
-
15
13
  export async function useCodeMirror(
16
14
  textarea: Ref<HTMLTextAreaElement | null | undefined>,
17
15
  input: Ref<string> | WritableComputedRef<string>,
@@ -1,54 +1,9 @@
1
- import type { App } from 'vue'
2
- import { computed, reactive, ref } from 'vue'
3
- import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router'
4
1
  import type { ComputedRef } from '@vue/reactivity'
5
2
  import type { configs } from '../env'
6
- import * as nav from '../logic/nav'
7
- import { route } from '../logic/nav'
8
- import { isDark } from '../logic/dark'
9
- import { injectionCurrentPage, injectionRenderContext, injectionSlidevContext } from '../constants'
10
- import { useContext } from '../composables/useContext'
11
-
12
- export type SlidevContextNavKey = 'path' | 'total' | 'clicksContext' | 'clicks' | 'clicksTotal' | 'currentPage' | 'currentPath' | 'currentRoute' | 'currentSlideId' | 'currentLayout' | 'nextRoute' | 'rawTree' | 'treeWithActiveStatuses' | 'tree' | 'downloadPDF' | 'next' | 'nextSlide' | 'openInEditor' | 'prev' | 'prevSlide' | 'rawRoutes' | 'go'
13
-
14
- export interface SlidevContextNav extends Pick<typeof nav, SlidevContextNavKey> {
15
- route: ComputedRef<RouteRecordRaw | RouteLocationNormalizedLoaded>
16
- }
3
+ import type { SlidevContextNav } from '../composables/useNav'
17
4
 
18
5
  export interface SlidevContext {
19
6
  nav: SlidevContextNav
20
7
  configs: typeof configs
21
8
  themeConfigs: ComputedRef<typeof configs['themeConfig']>
22
9
  }
23
-
24
- export function createSlidevContext() {
25
- return {
26
- install(app: App) {
27
- const context = reactive(useContext(route))
28
- app.provide(injectionRenderContext, ref('none'))
29
- app.provide(injectionSlidevContext, context)
30
- app.provide(injectionCurrentPage, computed(() => context.nav.currentPage))
31
-
32
- // allows controls from postMessages
33
- if (__DEV__) {
34
- // @ts-expect-error expose global
35
- window.__slidev__ = context
36
- window.addEventListener('message', ({ data }) => {
37
- if (data && data.target === 'slidev') {
38
- if (data.type === 'navigate') {
39
- nav.go(+data.no, +data.clicks || 0)
40
- }
41
- else if (data.type === 'css-vars') {
42
- const root = document.documentElement
43
- for (const [key, value] of Object.entries(data.vars || {}))
44
- root.style.setProperty(key, value as any)
45
- }
46
- else if (data.type === 'color-schema') {
47
- isDark.value = data.color === 'dark'
48
- }
49
- }
50
- })
51
- }
52
- },
53
- }
54
- }
@@ -1,17 +1,18 @@
1
1
  import mermaid from 'mermaid/dist/mermaid.esm.mjs'
2
- import { customAlphabet } from 'nanoid'
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>()
11
+ let containerElement: Element | undefined
12
12
 
13
- export async function renderMermaid(encoded: string, options: any) {
14
- const key = encoded + JSON.stringify(options)
13
+ export async function renderMermaid(lzEncoded: string, options: any) {
14
+ containerElement ??= document.getElementById('mermaid-rendering-container')!
15
+ const key = lzEncoded + JSON.stringify(options)
15
16
  const _cache = cache.get(key)
16
17
  if (_cache)
17
18
  return _cache
@@ -21,9 +22,9 @@ export async function renderMermaid(encoded: string, options: any) {
21
22
  ...clearUndefined(setupMermaid() || {}),
22
23
  ...clearUndefined(options),
23
24
  })
24
- const code = decode(encoded)
25
- const id = nanoid()
26
- const { svg } = await mermaid.render(id, code)
25
+ const code = lz.decompressFromBase64(lzEncoded)
26
+ const id = makeId()
27
+ const { svg } = await mermaid.render(id, code, containerElement)
27
28
  cache.set(key, svg)
28
29
  return svg
29
30
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slidev/client",
3
3
  "type": "module",
4
- "version": "0.48.0-beta.8",
4
+ "version": "0.48.0",
5
5
  "description": "Presentation slides for developers",
6
6
  "author": "antfu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -13,6 +13,7 @@
13
13
  },
14
14
  "bugs": "https://github.com/slidevjs/slidev/issues",
15
15
  "exports": {
16
+ ".": "./index.ts",
16
17
  "./package.json": "./package.json",
17
18
  "./constants": "./constants.ts",
18
19
  "./context": "./context.ts",
@@ -22,42 +23,47 @@
22
23
  "./utils": "./utils.ts",
23
24
  "./*": "./*"
24
25
  },
26
+ "main": "./public.ts",
25
27
  "engines": {
26
28
  "node": ">=18.0.0"
27
29
  },
28
30
  "dependencies": {
29
31
  "@antfu/utils": "^0.7.7",
30
- "@iconify-json/carbon": "^1.1.30",
32
+ "@iconify-json/carbon": "^1.1.31",
31
33
  "@iconify-json/ph": "^1.1.11",
34
+ "@iconify-json/svg-spinners": "^1.1.2",
35
+ "@shikijs/monaco": "^1.1.7",
32
36
  "@shikijs/vitepress-twoslash": "^1.1.7",
33
37
  "@slidev/rough-notation": "^0.1.0",
34
- "@unhead/vue": "^1.8.10",
38
+ "@typescript/ata": "^0.9.4",
39
+ "@unhead/vue": "^1.8.11",
35
40
  "@unocss/reset": "^0.58.5",
36
- "@vueuse/core": "^10.8.0",
37
- "@vueuse/math": "^10.8.0",
41
+ "@vueuse/core": "^10.9.0",
42
+ "@vueuse/math": "^10.9.0",
38
43
  "@vueuse/motion": "^2.1.0",
39
44
  "codemirror": "^5.65.16",
40
- "defu": "^6.1.4",
41
45
  "drauu": "^0.4.0",
42
46
  "file-saver": "^2.0.5",
43
47
  "floating-vue": "^5.2.2",
44
48
  "fuse.js": "^7.0.0",
45
- "js-base64": "^3.7.7",
46
49
  "js-yaml": "^4.1.0",
47
50
  "katex": "^0.16.9",
48
- "mermaid": "^10.8.0",
49
- "monaco-editor": "^0.37.1",
50
- "nanoid": "^5.0.6",
51
+ "lz-string": "^1.5.0",
52
+ "mermaid": "^10.9.0",
53
+ "monaco-editor": "^0.46.0",
51
54
  "prettier": "^3.2.5",
52
55
  "recordrtc": "^5.6.2",
53
- "resolve": "^1.22.8",
56
+ "shiki": "^1.1.7",
57
+ "shiki-magic-move": "^0.3.4",
58
+ "typescript": "^5.4.2",
54
59
  "unocss": "^0.58.5",
55
- "vue": "^3.4.19",
60
+ "vue": "^3.4.21",
61
+ "vue-demi": "^0.14.7",
56
62
  "vue-router": "^4.3.0",
57
- "@slidev/parser": "0.48.0-beta.8",
58
- "@slidev/types": "0.48.0-beta.8"
63
+ "@slidev/parser": "0.48.0",
64
+ "@slidev/types": "0.48.0"
59
65
  },
60
66
  "devDependencies": {
61
- "vite": "^5.1.4"
67
+ "vite": "^5.1.5"
62
68
  }
63
69
  }
@@ -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,22 +5,23 @@ 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 { rawRoutes } from '../routes'
10
- import NoteDisplay from './NoteDisplay.vue'
11
- import IconButton from './IconButton.vue'
8
+
9
+ import NoteDisplay from '../internals/NoteDisplay.vue'
10
+ import IconButton from '../internals/IconButton.vue'
11
+ import { useNav } from '../composables/useNav'
12
12
 
13
13
  const slideTitle = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
14
14
  useHead({
15
15
  title: `Notes - ${slideTitle}`,
16
16
  })
17
17
 
18
+ const { slides, total } = useNav()
18
19
  const { isFullscreen, toggle: toggleFullscreen } = fullscreen
19
20
 
20
21
  const scroller = ref<HTMLDivElement>()
21
22
  const fontSize = useLocalStorage('slidev-notes-font-size', 18)
22
23
  const pageNo = computed(() => sharedState.lastUpdate?.type === 'viewer' ? sharedState.viewerPage : sharedState.page)
23
- const currentRoute = computed(() => rawRoutes.find(i => i.path === `${pageNo.value}`))
24
+ const currentRoute = computed(() => slides.value.find(i => i.no === pageNo.value))
24
25
 
25
26
  watch(pageNo, () => {
26
27
  scroller.value?.scrollTo({ left: 0, top: 0, behavior: 'smooth' })
@@ -51,9 +52,11 @@ function decreaseFontSize() {
51
52
  :note="currentRoute?.meta?.slide?.note"
52
53
  :note-html="currentRoute?.meta?.slide?.noteHTML"
53
54
  :placeholder="`No notes for Slide ${pageNo}.`"
55
+ :clicks-context="currentRoute?.meta?.__clicksContext"
56
+ :auto-scroll="true"
54
57
  />
55
58
  </div>
56
- <div class="flex-none border-t border-gray-400 border-opacity-20">
59
+ <div class="flex-none border-t border-main">
57
60
  <div class="flex gap-1 items-center px-6 py-3">
58
61
  <IconButton :title="isFullscreen ? 'Close fullscreen' : 'Enter fullscreen'" @click="toggleFullscreen">
59
62
  <carbon:minimize v-if="isFullscreen" />
@@ -0,0 +1,231 @@
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 } from '../logic/slides'
7
+ import { createFixedClicks } 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.vue'
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
+ import { useNav } from '../composables/useNav'
18
+
19
+ const cardWidth = 450
20
+
21
+ const slideTitle = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
22
+ useHead({
23
+ title: `Overview - ${slideTitle}`,
24
+ })
25
+
26
+ const { openInEditor, slides } = useNav()
27
+
28
+ const blocks: Map<number, HTMLElement> = reactive(new Map())
29
+ const activeBlocks = ref<number[]>([])
30
+ const edittingNote = ref<number | null>(null)
31
+ const wordCounts = computed(() => slides.value.map(route => wordCount(route.meta?.slide?.note || '')))
32
+ const totalWords = computed(() => wordCounts.value.reduce((a, b) => a + b, 0))
33
+ const totalClicks = computed(() => slides.value.map(route => getSlideClicks(route)).reduce((a, b) => a + b, 0))
34
+
35
+ const clicksContextMap = new WeakMap<SlideRoute, ClicksContext>()
36
+ function getClicksContext(route: SlideRoute) {
37
+ // We create a local clicks context to calculate the total clicks of the slide
38
+ if (!clicksContextMap.has(route))
39
+ clicksContextMap.set(route, createFixedClicks(route, CLICKS_MAX))
40
+ return clicksContextMap.get(route)!
41
+ }
42
+
43
+ function getSlideClicks(route: SlideRoute) {
44
+ return route.meta?.clicks || getClicksContext(route)?.total
45
+ }
46
+
47
+ function wordCount(str: string) {
48
+ return str.match(/[\w\d\’\'-]+/gi)?.length || 0
49
+ }
50
+
51
+ function isElementInViewport(el: HTMLElement) {
52
+ const rect = el.getBoundingClientRect()
53
+ const delta = 20
54
+ return (
55
+ rect.top >= 0 - delta
56
+ && rect.left >= 0 - delta
57
+ && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + delta
58
+ && rect.right <= (window.innerWidth || document.documentElement.clientWidth) + delta
59
+ )
60
+ }
61
+
62
+ function checkActiveBlocks() {
63
+ const active: number[] = []
64
+ Array.from(blocks.entries())
65
+ .forEach(([idx, el]) => {
66
+ if (isElementInViewport(el))
67
+ active.push(idx)
68
+ })
69
+ activeBlocks.value = active
70
+ }
71
+
72
+ function openSlideInNewTab(path: string) {
73
+ const a = document.createElement('a')
74
+ a.target = '_blank'
75
+ a.href = path
76
+ a.click()
77
+ }
78
+
79
+ function scrollToSlide(idx: number) {
80
+ const el = blocks.get(idx)
81
+ if (el)
82
+ el.scrollIntoView({ behavior: 'smooth', block: 'start' })
83
+ }
84
+
85
+ function onMarkerClick(e: MouseEvent, clicks: number, route: SlideRoute) {
86
+ const ctx = getClicksContext(route)
87
+ if (ctx.current === clicks)
88
+ ctx.current = CLICKS_MAX
89
+ else
90
+ ctx.current = clicks
91
+ e.preventDefault()
92
+ }
93
+
94
+ onMounted(() => {
95
+ nextTick(() => {
96
+ checkActiveBlocks()
97
+ })
98
+ })
99
+ </script>
100
+
101
+ <template>
102
+ <div class="h-screen w-screen of-hidden flex">
103
+ <nav class="h-full flex flex-col border-r border-main p2 select-none">
104
+ <div class="flex flex-col flex-auto items-center justify-center group gap-1">
105
+ <div
106
+ v-for="(route, idx) of slides"
107
+ :key="route.no"
108
+ class="relative"
109
+ >
110
+ <button
111
+ class="relative transition duration-300 w-8 h-8 rounded hover:bg-active hover:op100"
112
+ :class="activeBlocks.includes(idx) ? 'op100 text-primary bg-gray:5' : 'op20'"
113
+ @click="scrollToSlide(idx)"
114
+ >
115
+ <div>{{ idx + 1 }}</div>
116
+ </button>
117
+ <div
118
+ v-if="route.meta?.slide?.title"
119
+ 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"
120
+ :class="activeBlocks.includes(idx) ? 'text-primary' : 'text-main important-text-op-50'"
121
+ >
122
+ {{ route.meta?.slide?.title }}
123
+ </div>
124
+ </div>
125
+ </div>
126
+ <IconButton
127
+ v-if="!isColorSchemaConfigured"
128
+ :title="isDark ? 'Switch to light mode theme' : 'Switch to dark mode theme'"
129
+ @click="toggleDark()"
130
+ >
131
+ <carbon-moon v-if="isDark" />
132
+ <carbon-sun v-else />
133
+ </IconButton>
134
+ </nav>
135
+ <main
136
+ class="flex-1 h-full of-auto"
137
+ :style="`grid-template-columns: repeat(auto-fit,minmax(${cardWidth}px,1fr))`"
138
+ @scroll="checkActiveBlocks"
139
+ >
140
+ <div
141
+ v-for="(route, idx) of slides"
142
+ :key="route.no"
143
+ :ref="el => blocks.set(idx, el as any)"
144
+ class="relative border-t border-main of-hidden flex gap-4 min-h-50 group"
145
+ :class="idx === 0 ? 'pt5' : ''"
146
+ >
147
+ <div class="select-none w-13 text-right my4 flex flex-col gap-1 items-end">
148
+ <div class="text-3xl op20 mb2">
149
+ {{ idx + 1 }}
150
+ </div>
151
+ <IconButton
152
+ class="mr--3 op0 group-hover:op80"
153
+ title="Play in new tab"
154
+ @click="openSlideInNewTab(getSlidePath(route, false))"
155
+ >
156
+ <carbon:presentation-file />
157
+ </IconButton>
158
+ <IconButton
159
+ v-if="route.meta?.slide"
160
+ class="mr--3 op0 group-hover:op80"
161
+ title="Open in editor"
162
+ @click="openInEditor(`${route.meta.slide.filepath}:${route.meta.slide.start}`)"
163
+ >
164
+ <carbon:cics-program />
165
+ </IconButton>
166
+ </div>
167
+ <div class="flex flex-col gap-2 my5">
168
+ <div
169
+ class="border rounded border-main overflow-hidden bg-main select-none h-max"
170
+ @dblclick="openSlideInNewTab(getSlidePath(route, false))"
171
+ >
172
+ <SlideContainer
173
+ :key="route.no"
174
+ :width="cardWidth"
175
+ :clicks-disabled="true"
176
+ class="pointer-events-none important:[&_*]:select-none"
177
+ >
178
+ <SlideWrapper
179
+ :is="route.component!"
180
+ :clicks-context="getClicksContext(route)"
181
+ :class="getSlideClass(route)"
182
+ :route="route"
183
+ render-context="overview"
184
+ />
185
+ <DrawingPreview :page="route.no" />
186
+ </SlideContainer>
187
+ </div>
188
+ <ClicksSlider
189
+ v-if="getSlideClicks(route)"
190
+ mt-2
191
+ :clicks-context="getClicksContext(route)"
192
+ class="w-full"
193
+ />
194
+ </div>
195
+ <div class="py3 mt-0.5 mr--8 ml--4 op0 transition group-hover:op100">
196
+ <IconButton
197
+ title="Edit Note"
198
+ class="rounded-full w-9 h-9 text-sm"
199
+ :class="edittingNote === route.no ? 'important:op0' : ''"
200
+ @click="edittingNote = route.no"
201
+ >
202
+ <carbon:pen />
203
+ </IconButton>
204
+ </div>
205
+ <NoteEditable
206
+ :no="route.no"
207
+ class="max-w-250 w-250 text-lg rounded p3"
208
+ :auto-height="true"
209
+ :editing="edittingNote === route.no"
210
+ :clicks-context="getClicksContext(route)"
211
+ @dblclick="edittingNote !== route.no ? edittingNote = route.no : null"
212
+ @update:editing="edittingNote = null"
213
+ @marker-click="(e, clicks) => onMarkerClick(e, clicks, route)"
214
+ />
215
+ <div
216
+ v-if="wordCounts[idx] > 0"
217
+ class="select-none absolute bottom-0 right-0 bg-main rounded-tl p2 op35 text-xs"
218
+ >
219
+ {{ wordCounts[idx] }} words
220
+ </div>
221
+ </div>
222
+ </main>
223
+ <div class="absolute top-0 right-0 px3 py1.5 border-b border-l rounded-lb bg-main border-main select-none">
224
+ <div class="text-xs op50">
225
+ {{ slides.length }} slides ·
226
+ {{ totalClicks + slides.length - 1 }} clicks ·
227
+ {{ totalWords }} words
228
+ </div>
229
+ </div>
230
+ </div>
231
+ </template>