Skip to content

Commit f9e1c65

Browse files
authored
feat!: migrate to shiki v1 (#1265)
1 parent d8dd15f commit f9e1c65

File tree

24 files changed

+1138
-754
lines changed

24 files changed

+1138
-754
lines changed

cypress/fixtures/basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
},
88
"devDependencies": {
99
"@slidev/cli": "workspace:*",
10-
"@slidev/theme-default": "^0.21.2",
11-
"@slidev/theme-seriph": "^0.21.3",
10+
"@slidev/theme-default": "^0.24.0",
11+
"@slidev/theme-seriph": "^0.24.0",
1212
"@slidev/types": "workspace:*",
1313
"nodemon": "^3.0.3"
1414
}

demo/composable-vue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"@iconify-json/mdi": "^1.1.64",
1111
"@iconify-json/ri": "^1.1.19",
1212
"@slidev/cli": "workspace:*",
13-
"@slidev/theme-default": "^0.21.2",
14-
"@slidev/theme-seriph": "^0.21.3",
13+
"@slidev/theme-default": "^0.24.0",
14+
"@slidev/theme-seriph": "^0.24.0",
1515
"@slidev/types": "workspace:*",
1616
"nodemon": "^3.0.3"
1717
}

demo/starter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
},
99
"devDependencies": {
1010
"@slidev/cli": "workspace:*",
11-
"@slidev/theme-default": "^0.21.2",
12-
"@slidev/theme-seriph": "^0.21.3",
11+
"@slidev/theme-default": "^0.24.0",
12+
"@slidev/theme-seriph": "^0.24.0",
1313
"@slidev/types": "workspace:*",
1414
"nodemon": "^3.0.3"
1515
}

demo/starter/slides.md

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
theme: seriph
33
background: https://source.unsplash.com/collection/94734566/1920x1080
44
class: text-center
5-
highlighter: shikiji
5+
highlighter: shiki
66
lineNumbers: false
77
info: |
88
## Slidev Starter Template
@@ -130,32 +130,20 @@ image: https://source.unsplash.com/collection/94734566/1920x1080
130130

131131
Use code snippets and get the highlighting directly, and even types hover![^1]
132132

133-
```ts {all|5|1-6|9|all} twoslash
134-
// TwoSlash enables TypeScript hover information and errors in markdown code blocks
135-
// Learn more at https://www.typescriptlang.org/dev/twoslash/
136-
function getUser(id: number): User {
137-
return undefined as any
138-
}
139-
function saveUser(id: number, user: User) {
140-
// ...
141-
}
142-
// ---cut---
143-
interface User {
144-
id: number
145-
firstName: string
146-
lastName: string
147-
role: string
148-
// ^?
149-
}
133+
```ts {all|5|7|7-8|10|all} twoslash
134+
// TwoSlash enables TypeScript hover information
135+
// and errors in markdown code blocks
136+
// More at https://shiki.style/packages/twoslash
150137

151-
function updateUser(id: number, update: User) {
152-
const user = getUser(id)
153-
const newUser = { ...user, ...update }
154-
saveUser(id, newUser)
155-
}
138+
import { computed, ref } from 'vue'
139+
140+
const count = ref(0)
141+
const doubled = computed(() => count.value * 2)
142+
143+
doubled.value = 2
156144
```
157145

158-
<arrow v-click="[3, 4]" x1="400" y1="420" x2="230" y2="330" color="#564" width="3" arrowSize="1" />
146+
<arrow v-click="[4, 5]" x1="350" y1="310" x2="195" y2="334" color="#953" width="2" arrowSize="1" />
159147

160148
[^1]: [Learn More](https://sli.dev/guide/syntax.html#line-highlighting)
161149

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "module",
33
"version": "0.46.3",
44
"private": true,
5-
"packageManager": "pnpm@8.14.2",
5+
"packageManager": "pnpm@8.15.1",
66
"engines": {
77
"node": ">=18.0.0"
88
},
@@ -26,6 +26,7 @@
2626
"@antfu/eslint-config": "^2.6.3",
2727
"@antfu/ni": "^0.21.12",
2828
"@antfu/utils": "^0.7.7",
29+
"@shikijs/markdown-it": "^1.0.0-beta.3",
2930
"@slidev/cli": "workspace:*",
3031
"@slidev/parser": "workspace:*",
3132
"@slidev/types": "workspace:*",
@@ -39,7 +40,7 @@
3940
"@types/katex": "^0.16.7",
4041
"@types/localtunnel": "^2.0.4",
4142
"@types/markdown-it": "^13.0.7",
42-
"@types/node": "^20.11.5",
43+
"@types/node": "^20.11.16",
4344
"@types/prismjs": "^1.26.3",
4445
"@types/prompts": "^2.4.9",
4546
"@types/recordrtc": "^5.6.14",
@@ -53,19 +54,18 @@
5354
"eslint": "^8.56.0",
5455
"esno": "^4.0.0",
5556
"katex": "^0.16.9",
56-
"lint-staged": "^15.2.0",
57-
"markdown-it-shikiji": "^0.10.0",
58-
"mermaid": "^10.7.0",
59-
"playwright-chromium": "^1.41.1",
60-
"pnpm": "^8.14.2",
57+
"lint-staged": "^15.2.1",
58+
"mermaid": "^10.8.0",
59+
"playwright-chromium": "^1.41.2",
60+
"pnpm": "^8.15.1",
6161
"rimraf": "^5.0.5",
62-
"shikiji": "^0.10.0",
62+
"shiki": "^1.0.0-beta.3",
6363
"simple-git-hooks": "^2.9.0",
6464
"tsup": "^8.0.1",
6565
"typescript": "^5.3.3",
6666
"vite": "^5.0.12",
6767
"vite-plugin-windicss": "^1.9.3",
68-
"vitest": "^1.2.1",
68+
"vitest": "^1.2.2",
6969
"vue-tsc": "^1.8.27",
7070
"zx": "^7.2.3"
7171
},

packages/client/internals/Play.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ if (__SLIDEV_FEATURE_DRAWINGS__)
4848
:style="{ background: 'var(--slidev-slide-container-background, black)' }"
4949
:width="isPrintMode ? windowSize.width.value : undefined"
5050
:scale="slideScale"
51+
:is-main="true"
5152
@pointerdown="onClick"
5253
>
5354
<template #default>

packages/client/internals/SlideContainer.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { useElementSize } from '@vueuse/core'
2+
import { useElementSize, useStyleTag } from '@vueuse/core'
33
import { computed, provide, ref, watchEffect } from 'vue'
44
import { configs, slideAspect, slideHeight, slideWidth } from '../env'
55
import { injectionSlideScale } from '../constants'
@@ -15,6 +15,10 @@ const props = defineProps({
1515
scale: {
1616
type: [Number, String],
1717
},
18+
isMain: {
19+
type: Boolean,
20+
default: false,
21+
},
1822
})
1923
2024
const root = ref<HTMLDivElement>()
@@ -52,6 +56,14 @@ const className = computed(() => ({
5256
'select-none': !configs.selectable,
5357
}))
5458
59+
if (props.isMain) {
60+
useStyleTag(computed(() => `
61+
:root {
62+
--slidev-slide-scale: ${scale.value};
63+
}
64+
`))
65+
}
66+
5567
provide(injectionSlideScale, scale as any)
5668
</script>
5769

packages/client/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@
2020
},
2121
"dependencies": {
2222
"@antfu/utils": "^0.7.7",
23+
"@shikijs/vitepress-twoslash": "^1.0.0-beta.3",
2324
"@slidev/parser": "workspace:*",
2425
"@slidev/types": "workspace:*",
2526
"@unhead/vue": "^1.8.10",
26-
"@unocss/reset": "^0.58.3",
27+
"@unocss/reset": "^0.58.4",
2728
"@vueuse/core": "^10.7.2",
2829
"@vueuse/math": "^10.7.2",
2930
"@vueuse/motion": "^2.0.0",
3031
"codemirror": "^5.65.5",
3132
"defu": "^6.1.4",
3233
"drauu": "^0.3.7",
3334
"file-saver": "^2.0.5",
34-
"floating-vue": "^5.2.0",
35+
"floating-vue": "^5.2.2",
3536
"fuse.js": "^7.0.0",
3637
"js-base64": "^3.7.6",
3738
"js-yaml": "^4.1.0",
3839
"katex": "^0.16.9",
39-
"mermaid": "^10.7.0",
40+
"mermaid": "^10.8.0",
4041
"monaco-editor": "^0.37.1",
41-
"nanoid": "^5.0.4",
42+
"nanoid": "^5.0.5",
4243
"prettier": "^3.2.4",
4344
"recordrtc": "^5.6.2",
4445
"resolve": "^1.22.8",
45-
"unocss": "^0.58.3",
46+
"unocss": "^0.58.4",
4647
"vite-plugin-windicss": "^1.9.3",
4748
"vue": "^3.4.15",
4849
"vue-router": "^4.2.5",

packages/client/setup/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { AppContext } from '@slidev/types'
44
import { MotionPlugin } from '@vueuse/motion'
55
import StarportPlugin from 'vue-starport'
6+
import TwoSlashFloatingVue from '@shikijs/vitepress-twoslash/client'
67

78
export default function setupMain(context: AppContext) {
89
function setMaxHeight() {
@@ -15,6 +16,7 @@ export default function setupMain(context: AppContext) {
1516

1617
context.app.use(MotionPlugin)
1718
context.app.use(StarportPlugin({ keepAlive: true }))
19+
context.app.use(TwoSlashFloatingVue as any)
1820

1921
// @ts-expect-error inject in runtime
2022
// eslint-disable-next-line unused-imports/no-unused-vars

packages/client/styles/code.css

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,24 @@ html.dark:root {
33
}
44

55
/* Shiki */
6-
html.dark .shiki-light {
7-
display: none;
8-
}
9-
10-
html:not(.dark) .shiki-dark {
11-
display: none;
12-
}
13-
14-
.shiki-container {
15-
@apply relative flex flex-col;
16-
}
17-
18-
.shiki-container > .shiki {
19-
@apply h-full;
20-
}
21-
22-
/* Shikiji */
23-
html.dark .shikiji {
6+
html.dark .shiki {
247
color: var(--shiki-dark, inherit);
25-
background: var(--shiki-dark-bg, inherit);
268
--twoslash-popup-bg: var(--shiki-dark-bg, inherit);
279
}
2810

29-
html.dark .shikiji span {
11+
html.dark .shiki span {
3012
color: var(--shiki-dark);
3113
}
3214

33-
html:not(.dark) .shikiji {
15+
html:not(.dark) .shiki {
3416
color: var(--shiki-light, inherit);
35-
background: var(--shiki-light-bg, inherit);
3617
--twoslash-popup-bg: var(--shiki-light-bg, inherit);
3718
}
3819

39-
html:not(.dark) .shikiji span {
20+
html:not(.dark) .shiki span {
4021
color: var(--shiki-light);
4122
}
4223

43-
.shikiji.twoslash {
44-
/* Do not set overflow so the hover popover can be displayed */
45-
overflow: inherit;
46-
}
47-
4824
.twoslash-meta-line.twoslash-popover-line {
4925
margin-top: -10px;
5026
}
@@ -64,6 +40,7 @@ html:not(.dark) .shikiji span {
6440
font-size: var(--slidev-code-font-size) !important;
6541
line-height: var(--slidev-code-line-height) !important;
6642
border-radius: var(--slidev-code-radius) !important;
43+
background: var(--slidev-code-background);
6744
overflow: auto;
6845
}
6946

@@ -85,6 +62,18 @@ html:not(.dark) .shikiji span {
8562
@apply w-4 mr-6 inline-block text-right text-gray-400 dark:text-gray-600;
8663
}
8764

65+
/* Inline Code */
66+
.slidev-layout :not(pre) > code {
67+
font-size: 0.9em;
68+
background: var(--slidev-code-background);
69+
border-radius: var(--slidev-code-radius);
70+
@apply font-light py-0.5 px-1.5;
71+
}
72+
73+
.slidev-layout :not(pre) > code:before {
74+
margin-right: -0.08em;
75+
}
76+
8877
/* Revert CSS reset for KaTex */
8978
.katex,
9079
.katex :after,

0 commit comments

Comments
 (0)