@slidev/client 0.49.0-beta.3 → 0.49.0-beta.5

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.
@@ -3,12 +3,11 @@ import { useHead } from '@unhead/vue'
3
3
  import { computed, onMounted, reactive, ref, shallowRef, watch } from 'vue'
4
4
  import { useMouse, useWindowFocus } from '@vueuse/core'
5
5
  import { useSwipeControls } from '../composables/useSwipeControls'
6
- import { decreasePresenterFontSize, increasePresenterFontSize, presenterLayout, presenterNotesFontSize, showEditor, showOverview, showPresenterCursor } from '../state'
7
- import { configs } from '../env'
6
+ import { decreasePresenterFontSize, increasePresenterFontSize, presenterLayout, presenterNotesFontSize, showEditor, showPresenterCursor } from '../state'
7
+ import { slidesTitle } from '../env'
8
8
  import { sharedState } from '../state/shared'
9
9
  import { registerShortcuts } from '../logic/shortcuts'
10
10
  import { onContextMenu } from '../logic/contextMenu'
11
- import { getSlideClass } from '../utils'
12
11
  import { useTimer } from '../logic/utils'
13
12
  import { createFixedClicks } from '../composables/useClicks'
14
13
  import SlideWrapper from '../internals/SlideWrapper.vue'
@@ -44,10 +43,7 @@ const {
44
43
  } = useNav()
45
44
  const { isDrawing } = useDrawings()
46
45
 
47
- const slideTitle = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
48
- useHead({
49
- title: `Presenter - ${slideTitle}`,
50
- })
46
+ useHead({ title: `Presenter - ${slidesTitle}` })
51
47
 
52
48
  const notesEditing = ref(false)
53
49
 
@@ -113,12 +109,11 @@ onMounted(() => {
113
109
  <div ref="main" class="relative grid-section main flex flex-col">
114
110
  <SlideContainer
115
111
  key="main"
116
- class="h-full w-full p-2 lg:p-4 flex-auto"
112
+ class="p-2 lg:p-4 flex-auto"
113
+ is-main
117
114
  @contextmenu="onContextMenu"
118
115
  >
119
- <template #default>
120
- <SlidesShow render-context="presenter" />
121
- </template>
116
+ <SlidesShow render-context="presenter" />
122
117
  </SlideContainer>
123
118
  <ClicksSlider
124
119
  :key="currentSlideRoute?.no"
@@ -130,16 +125,10 @@ onMounted(() => {
130
125
  </div>
131
126
  </div>
132
127
  <div class="relative grid-section next flex flex-col p-2 lg:p-4">
133
- <SlideContainer
134
- v-if="nextFrame && nextFrameClicksCtx"
135
- key="next"
136
- class="h-full w-full"
137
- >
128
+ <SlideContainer v-if="nextFrame && nextFrameClicksCtx" key="next">
138
129
  <SlideWrapper
139
- :is="nextFrame[0].component!"
140
130
  :key="nextFrame[0].no"
141
131
  :clicks-context="nextFrameClicksCtx"
142
- :class="getSlideClass(nextFrame[0])"
143
132
  :route="nextFrame[0]"
144
133
  render-context="previewNext"
145
134
  />
@@ -148,8 +137,7 @@ onMounted(() => {
148
137
  Next
149
138
  </div>
150
139
  </div>
151
- <!-- Notes -->
152
- <div v-if="__DEV__ && __SLIDEV_FEATURE_EDITOR__ && SideEditor && showEditor" class="grid-section note of-auto">
140
+ <div v-if="SideEditor && showEditor" class="grid-section note of-auto">
153
141
  <SideEditor />
154
142
  </div>
155
143
  <div v-else class="grid-section note grid grid-rows-[1fr_min-content] overflow-hidden">
@@ -206,12 +194,12 @@ onMounted(() => {
206
194
  <div class="progress-bar">
207
195
  <div
208
196
  class="progress h-3px bg-primary transition-all"
209
- :style="{ width: `${(currentSlideNo - 1) / (total - 1) * 100}%` }"
197
+ :style="{ width: `${(currentSlideNo - 1) / (total - 1) * 100 + 1}%` }"
210
198
  />
211
199
  </div>
212
200
  </div>
213
201
  <Goto />
214
- <QuickOverview v-model="showOverview" />
202
+ <QuickOverview />
215
203
  <ContextMenu />
216
204
  </template>
217
205
 
@@ -227,10 +215,6 @@ onMounted(() => {
227
215
  opacity: 1;
228
216
  }
229
217
 
230
- .section-title {
231
- --uno: px-4 py-2 text-xl;
232
- }
233
-
234
218
  .grid-container {
235
219
  --uno: bg-gray/20;
236
220
  height: 100%;
@@ -303,4 +287,4 @@ onMounted(() => {
303
287
  .grid-section.bottom {
304
288
  grid-area: bottom;
305
289
  }
306
- </style>../composables/drawings
290
+ </style>
@@ -1,8 +1,9 @@
1
- import { createSingletonPromise, ensurePrefix, slash } from '@antfu/utils'
2
- import type { CodeRunner, CodeRunnerContext, CodeRunnerOutput, CodeRunnerOutputText, CodeRunnerOutputs } from '@slidev/types'
1
+ import { createSingletonPromise } from '@antfu/utils'
2
+ import type { CodeRunner, CodeRunnerOutput, CodeRunnerOutputText, CodeRunnerOutputs } from '@slidev/types'
3
3
  import type { CodeToHastOptions } from 'shiki'
4
4
  import type ts from 'typescript'
5
5
  import { isDark } from '../logic/dark'
6
+ import deps from '#slidev/monaco-run-deps'
6
7
  import setups from '#slidev/setups/code-runners'
7
8
 
8
9
  export default createSingletonPromise(async () => {
@@ -25,18 +26,6 @@ export default createSingletonPromise(async () => {
25
26
  ...options,
26
27
  })
27
28
 
28
- const resolveId = async (specifier: string) => {
29
- if (!'./'.includes(specifier[0]) && !/^(@[^\/:]+?\/)?[^\/:]+$/.test(specifier))
30
- return specifier // this might be a url or something else
31
- const res = await fetch(`/@slidev/resolve-id?specifier=${specifier}`)
32
- if (!res.ok)
33
- return null
34
- const id = await res.text()
35
- if (!id)
36
- return null
37
- return `/@fs${ensurePrefix('/', slash(id))}`
38
- }
39
-
40
29
  const run = async (code: string, lang: string, options: Record<string, unknown>): Promise<CodeRunnerOutputs> => {
41
30
  try {
42
31
  const runner = runners[lang]
@@ -47,7 +36,6 @@ export default createSingletonPromise(async () => {
47
36
  {
48
37
  options,
49
38
  highlight,
50
- resolveId,
51
39
  run: async (code, lang) => {
52
40
  return await run(code, lang, options)
53
41
  },
@@ -85,16 +73,20 @@ async function runJavaScript(code: string): Promise<CodeRunnerOutputs> {
85
73
  replace.clear = () => allLogs.length = 0
86
74
  const vmConsole = Object.assign({}, console, replace)
87
75
  try {
88
- const safeJS = `return async (console) => {
89
- window.console = console
76
+ const safeJS = `return async (console, __slidev_import) => {
90
77
  ${sanitizeJS(code)}
91
78
  }`
92
79
  // eslint-disable-next-line no-new-func
93
- await (new Function(safeJS)())(vmConsole)
80
+ await (new Function(safeJS)())(vmConsole, (specifier: string) => {
81
+ const mod = deps[specifier]
82
+ if (!mod)
83
+ throw new Error(`Module not found: ${specifier}.\nAvailable modules: ${Object.keys(deps).join(', ')}. Please refer to https://sli.dev/custom/config-code-runners#additional-runner-dependencies`)
84
+ return mod
85
+ })
94
86
  }
95
87
  catch (error) {
96
88
  return {
97
- error: `ERROR: ${error}`,
89
+ error: String(error),
98
90
  }
99
91
  }
100
92
 
@@ -175,7 +167,7 @@ async function runJavaScript(code: string): Promise<CodeRunnerOutputs> {
175
167
 
176
168
  let tsModule: typeof import('typescript') | undefined
177
169
 
178
- export async function runTypeScript(code: string, context: CodeRunnerContext) {
170
+ export async function runTypeScript(code: string) {
179
171
  tsModule ??= await import('typescript')
180
172
 
181
173
  code = tsModule.transpileModule(code, {
@@ -188,11 +180,8 @@ export async function runTypeScript(code: string, context: CodeRunnerContext) {
188
180
  },
189
181
  }).outputText
190
182
 
191
- const importRegex = /import\s*\(\s*(['"])(.+?)['"]\s*\)/g
192
- const idMap: Record<string, string> = {}
193
- for (const [,,specifier] of code.matchAll(importRegex)!)
194
- idMap[specifier] = await context.resolveId(specifier) ?? specifier
195
- code = code.replace(importRegex, (_full, quote, specifier) => `import(${quote}${idMap[specifier] ?? specifier}${quote})`)
183
+ const importRegex = /import\s*\((.+)\)/g
184
+ code = code.replace(importRegex, (_full, specifier) => `__slidev_import(${specifier})`)
196
185
 
197
186
  return await runJavaScript(code)
198
187
  }
package/setup/root.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { computed, getCurrentInstance, reactive, ref, shallowRef, watch } from 'vue'
2
2
  import { useHead } from '@unhead/vue'
3
3
  import { useRouter } from 'vue-router'
4
- import { configs } from '../env'
4
+ import { configs, slidesTitle } from '../env'
5
5
  import { initSharedState, onPatch, patch } from '../state/shared'
6
6
  import { initDrawingState } from '../state/drawings'
7
7
  import { TRUST_ORIGINS, injectionClicksContext, injectionCurrentPage, injectionRenderContext, injectionSlidevContext } from '../constants'
@@ -51,8 +51,6 @@ export default function setupRoot() {
51
51
  for (const setup of setups)
52
52
  setup()
53
53
 
54
- const title = configs.titleTemplate.replace('%s', configs.title || 'Slidev')
55
-
56
54
  const {
57
55
  clicksContext,
58
56
  currentSlideNo,
@@ -62,12 +60,12 @@ export default function setupRoot() {
62
60
  } = useNav()
63
61
 
64
62
  useHead({
65
- title,
63
+ title: slidesTitle,
66
64
  htmlAttrs: configs.htmlAttrs,
67
65
  })
68
66
 
69
- initSharedState(`${title} - shared`)
70
- initDrawingState(`${title} - drawings`)
67
+ initSharedState(`${slidesTitle} - shared`)
68
+ initDrawingState(`${slidesTitle} - drawings`)
71
69
 
72
70
  const id = `${location.origin}_${makeId()}`
73
71
 
package/styles/index.css CHANGED
@@ -49,6 +49,10 @@ html {
49
49
  user-select: none !important;
50
50
  }
51
51
 
52
+ .slidev-vclick-display-none {
53
+ display: none !important;
54
+ }
55
+
52
56
  .slidev-vclick-fade {
53
57
  opacity: 0.5;
54
58
  }
@@ -116,3 +120,7 @@ html {
116
120
  .rough-annotation {
117
121
  transform: scale(calc(1 / var(--slidev-slide-scale)));
118
122
  }
123
+
124
+ #twoslash-container {
125
+ position: fixed;
126
+ }
package/uno.config.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  transformerVariantGroup,
10
10
  } from 'unocss'
11
11
  import { variantMatcher } from '@unocss/preset-mini/utils'
12
+ import extractorMdc from '@unocss/extractor-mdc'
12
13
 
13
14
  export default defineConfig({
14
15
  safelist: [
@@ -48,4 +49,7 @@ export default defineConfig({
48
49
  transformerDirectives({ enforce: 'pre' }),
49
50
  transformerVariantGroup(),
50
51
  ],
52
+ extractors: [
53
+ extractorMdc(),
54
+ ],
51
55
  })