Skip to content

Commit 08434b8

Browse files
committed
feat: new theme
1 parent 80c04c3 commit 08434b8

File tree

26 files changed

+392
-63
lines changed

26 files changed

+392
-63
lines changed

demo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@slidev/cli": "workspace:*",
11-
"@slidev/theme-default": "workspace:*"
11+
"@slidev/theme-default": "workspace:*",
12+
"@slidev/theme-seriph": "workspace:*"
1213
}
1314
}

demo/slides.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: cover
3+
theme: '@slidev/theme-default'
34
---
45

56
# Composable Vue
@@ -12,15 +13,15 @@ Anthony Fu
1213

1314
<div class="abs-bl mx-14 my-12 flex">
1415
<img src="https://2020.vueday.it/img/themes/vueday/vueday-logo.png" class="h-8">
15-
<div class="ml-3 flex flex-col">
16+
<div class="ml-3 flex flex-col text-left">
1617
<div><b>Vue</b>Day</div>
1718
<div class="text-sm opacity-50">Apr. 29th, 2021</div>
1819
</div>
1920
</div>
2021

2122

2223
---
23-
layout: cover
24+
layout: intro
2425
---
2526

2627
# Anthony Fu

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"eslint-plugin-jest": "^24.3.5",
2727
"esno": "^0.5.0",
2828
"jest": "^26.6.3",
29-
"pnpm": "^6.2.0",
29+
"pnpm": "^6.2.1",
3030
"ts-jest": "^26.5.5",
3131
"typescript": "^4.2.4",
3232
"vite-plugin-pwa": "^0.7.2",

packages/client/builtin/Monaco.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type * as monaco from 'monaco-editor'
1010
import { formatCode } from '../setup/prettier'
1111
import setupMonaco from '../setup/monaco'
1212
import { isDark } from '../logic/dark'
13-
import { paused } from '../logic/nav'
1413
1514
const props = defineProps({
1615
code: {
@@ -127,16 +126,19 @@ setupMonaco()
127126
128127
onUnmounted(() => editor?.dispose())
129128
</script>
129+
130130
<style lang="postcss">
131131
.vue-monaco {
132132
background: var(--prism-background);
133133
padding: var(--prism-block-padding-y) var(--prism-block-padding-x);
134134
margin: var(--prism-block-margin-y) var(--prism-block-margin-x);
135-
@apply rounded p-2;
135+
border-radius: var(--prism-block-radius);
136+
@apply p-2;
136137
}
137138
138139
.monaco-editor .monaco-hover {
139-
@apply rounded overflow-hidden shadow border-none outline-none;
140+
border-radius: var(--prism-block-radius);
141+
@apply overflow-hidden shadow border-none outline-none;
140142
}
141143
142144
.monaco-editor .lines-content,

packages/client/windi.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export default defineConfig({
1616
safelist: [
1717
'!opacity-0',
1818
],
19+
shortcuts: {
20+
'abs-t': 'absolute bottom-0 left-0 right-0',
21+
'abs-tl': 'absolute top-0 left-0',
22+
'abs-tr': 'absolute top-0 right-0',
23+
'abs-b': 'absolute bottom-0 left-0 right-0',
24+
'abs-bl': 'absolute bottom-0 left-0',
25+
'abs-br': 'absolute bottom-0 right-0',
26+
},
1927
darkMode: 'class',
2028
preflight: {
2129
includeAll: true,

packages/slidev/node/build.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { getIndexHtml } from './common'
55
import { resolveOptions } from './plugins/options'
66

77
export async function build(entry: string, config: InlineConfig = {}) {
8-
await fs.writeFile('index.html', await getIndexHtml(resolveOptions(entry)), 'utf-8')
8+
const options = await resolveOptions(entry)
9+
await fs.writeFile('index.html', await getIndexHtml(options), 'utf-8')
910
try {
1011
await viteBuild(
1112
mergeConfig(
1213
config,
1314
{
1415
plugins: [
15-
ViteSlidevPlugin({
16-
entry,
16+
await ViteSlidevPlugin({
17+
resolved: options,
1718
}),
1819
],
1920
},

packages/slidev/node/plugins/loaders.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { basename } from 'path'
22
import { ModuleNode, Update, ViteDevServer, Plugin } from 'vite'
3-
import { notNullish, objectMap } from '@antfu/utils'
3+
import { isTruthy, notNullish, objectMap } from '@antfu/utils'
44
import type { Connect } from 'vite'
55
import fg from 'fast-glob'
66
import * as parser from '../parser'
@@ -41,18 +41,13 @@ export function sendHmrReload(server: ViteDevServer, modules: ModuleNode[]) {
4141
})
4242
}
4343

44-
export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: ResolvedSlidevOptions): Plugin[] {
45-
let data: parser.SlidesMarkdown
44+
export function createSlidesLoader({ data, entry, clientRoot, themeRoot, userRoot }: ResolvedSlidevOptions): Plugin[] {
4645
let skipNext = false
4746

4847
return [
4948
{
5049
name: 'slidev:loader',
5150

52-
async configResolved() {
53-
data = await parser.load(entry)
54-
},
55-
5651
configureServer(server) {
5752
server.watcher.add(entry)
5853

@@ -97,17 +92,24 @@ export function createSlidesLoader({ entry, clientRoot, themeRoot, userRoot }: R
9792
skipNext = false
9893
return
9994
}
100-
data = await parser.load(entry)
95+
const newData = await parser.load(entry)
96+
97+
if (data.config.theme !== newData.config.theme)
98+
console.log('Theme changed')
99+
// TODO: restart the server
101100

102101
const moduleEntries = [
103-
'/@slidev/routes',
104-
'/@slidev/configs',
102+
data.slides.length !== newData.slides.length && '/@slidev/routes',
103+
JSON.stringify(data.config) !== JSON.stringify(newData.config) && '/@slidev/configs',
105104
...data.slides.map((i, idx) => `${entry}?id=${idx}.md`),
106105
...data.slides.map((i, idx) => `${entry}?id=${idx}.json`),
107106
]
108-
.map(id => ctx.server.moduleGraph.getModuleById(id))
107+
.filter(isTruthy)
108+
.map(id => ctx.server.moduleGraph.getModuleById(id as string))
109109
.filter(notNullish)
110110

111+
data = newData
112+
111113
moduleEntries.map(m => ctx.server.moduleGraph.invalidateModule(m))
112114
return moduleEntries
113115
}

packages/slidev/node/plugins/options.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Markdown from 'vite-plugin-md'
66
import WindiCSS from 'vite-plugin-windicss'
77
import RemoteAssets from 'vite-plugin-remote-assets'
88
import { ArgumentsType } from '@antfu/utils'
9+
import * as parser from '../parser'
910

1011
export interface SlidevOptions {
1112
/**
@@ -22,16 +23,8 @@ export interface SlidevOptions {
2223
theme?: string
2324
}
2425

25-
export interface SlidevPluginOptions extends SlidevOptions {
26-
vue?: ArgumentsType<typeof Vue>[0]
27-
markdown?: ArgumentsType<typeof Markdown>[0]
28-
components?: ArgumentsType<typeof ViteComponents>[0]
29-
windicss?: ArgumentsType<typeof WindiCSS>[0]
30-
icons?: ArgumentsType<typeof ViteIcons>[0]
31-
remoteAssets?: ArgumentsType<typeof RemoteAssets>[0]
32-
}
33-
3426
export interface ResolvedSlidevOptions {
27+
data: parser.SlidesMarkdown
3528
entry: string
3629
userRoot: string
3730
cliRoot: string
@@ -40,6 +33,16 @@ export interface ResolvedSlidevOptions {
4033
themeRoot: string
4134
}
4235

36+
export interface SlidevPluginOptions extends SlidevOptions {
37+
vue?: ArgumentsType<typeof Vue>[0]
38+
markdown?: ArgumentsType<typeof Markdown>[0]
39+
components?: ArgumentsType<typeof ViteComponents>[0]
40+
windicss?: ArgumentsType<typeof WindiCSS>[0]
41+
icons?: ArgumentsType<typeof ViteIcons>[0]
42+
remoteAssets?: ArgumentsType<typeof RemoteAssets>[0]
43+
resolved?: ResolvedSlidevOptions
44+
}
45+
4346
export function getClientRoot() {
4447
return dirname(require.resolve('@slidev/client/package.json'))
4548
}
@@ -52,9 +55,12 @@ export function getThemeRoot(name: string) {
5255
return dirname(require.resolve(`${name}/package.json`))
5356
}
5457

55-
export function resolveOptions(entry = 'slides.md', userRoot = process.cwd()): ResolvedSlidevOptions {
56-
const theme = '@slidev/theme-default'
58+
export async function resolveOptions(entry = 'slides.md', userRoot = process.cwd()): Promise<ResolvedSlidevOptions> {
59+
const data = await parser.load(entry)
60+
const theme = data.config.theme
61+
5762
return {
63+
data,
5864
entry: resolve(userRoot, entry),
5965
theme,
6066
userRoot,

packages/slidev/node/plugins/preset.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ViteComponents from 'vite-plugin-components'
77
import Markdown from 'vite-plugin-md'
88
import WindiCSS, { defaultConfigureFiles } from 'vite-plugin-windicss'
99
import Prism from 'markdown-it-prism'
10-
import RemoteAssets from 'vite-plugin-remote-assets'
10+
import RemoteAssets, { DefaultRules } from 'vite-plugin-remote-assets'
1111
import { createConfigPlugin } from './config'
1212
import { createSlidesLoader } from './loaders'
1313
import { createMonacoLoader, transformMarkdownMonaco } from './monaco'
@@ -17,18 +17,21 @@ import { createSetupPlugin } from './setups'
1717
import VitePluginVueFactory, { VueFactoryResolver } from './factory'
1818
import VitePluginServerRef from './server-ref'
1919

20-
export function ViteSlidevPlugin(options: SlidevPluginOptions = {}): Plugin[] {
20+
export async function ViteSlidevPlugin(pluginOptions: SlidevPluginOptions = {}): Promise<Plugin[]> {
2121
const {
2222
vue: vueOptions = {},
2323
markdown: mdOptions = {},
2424
components: componentsOptions = {},
2525
icons: iconsOptions = {},
2626
remoteAssets: remoteAssetsOptions = {},
2727
windicss: windiOptions = {},
28-
} = options
28+
} = pluginOptions
2929

30-
const slidesOptions = resolveOptions()
31-
const { themeRoot, clientRoot } = slidesOptions
30+
const options = pluginOptions.resolved || await resolveOptions(pluginOptions.entry)
31+
const {
32+
themeRoot,
33+
clientRoot,
34+
} = options
3235

3336
return [
3437
Vue({
@@ -107,6 +110,14 @@ export function ViteSlidevPlugin(options: SlidevPluginOptions = {}): Plugin[] {
107110
),
108111

109112
RemoteAssets({
113+
rules: [
114+
...DefaultRules,
115+
{
116+
match: /\b(https?:\/\/\w+\.unsplash\.com.*?)(?=[`'")\]])/ig,
117+
ext: '.png',
118+
},
119+
],
120+
resolveMode: '@fs',
110121
...remoteAssetsOptions,
111122
}),
112123

@@ -120,10 +131,10 @@ export function ViteSlidevPlugin(options: SlidevPluginOptions = {}): Plugin[] {
120131
},
121132
},
122133
}),
123-
createConfigPlugin(slidesOptions),
124-
createEntryPlugin(slidesOptions),
125-
createSlidesLoader(slidesOptions),
126-
createSetupPlugin(slidesOptions),
134+
createConfigPlugin(options),
135+
createEntryPlugin(options),
136+
createSlidesLoader(options),
137+
createSetupPlugin(options),
127138
createMonacoLoader(),
128139
].flat()
129140
}

packages/slidev/node/server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { createServer as createViteServer, InlineConfig, mergeConfig } from 'vite'
2+
import { resolveOptions } from './plugins/options'
23
import { ViteSlidevPlugin } from './plugins/preset'
34

45
export async function createServer(entry?: string, config: InlineConfig = {}) {
5-
return await createViteServer(
6+
const options = await resolveOptions(entry)
7+
const server = await createViteServer(
68
mergeConfig(
79
config,
810
{
911
plugins: [
10-
ViteSlidevPlugin({
11-
entry,
12+
await ViteSlidevPlugin({
13+
resolved: options,
1214
}),
1315
],
1416
},
1517
),
1618
)
19+
20+
console.log('theme: ', options.theme)
21+
22+
return server
1723
}

0 commit comments

Comments
 (0)