diff --git a/cli/src/generate.ts b/cli/src/generate.ts index ab566d9e..34fe594c 100644 --- a/cli/src/generate.ts +++ b/cli/src/generate.ts @@ -8,7 +8,11 @@ import { createPackageJson } from './packageJson.js' import { createRender } from './render.js' import { getTemplate, readFiles, readJsonFile, writeFiles } from './utils/index.js' -export async function generate(mode: Mode, data: ResolvedData, cwd = process.cwd()): Promise { +export async function generate( + mode: Mode, + data: ResolvedData, + cwd: string = process.cwd(), +): Promise { let userPkg: Record = {} if (mode === Mode.init) { const pkgPath = path.join(cwd, 'package.json') diff --git a/cli/src/run.ts b/cli/src/run.ts index 17b5e8e8..92d11818 100644 --- a/cli/src/run.ts +++ b/cli/src/run.ts @@ -11,7 +11,7 @@ import { prompt } from './prompt.js' import { t } from './translate.js' import { getPackageManager } from './utils/index.js' -export async function run(mode: Mode, root?: string) { +export async function run(mode: Mode, root?: string): Promise { intro(colors.cyan('Welcome to VuePress and vuepress-theme-plume !')) const result = await prompt(mode, root) diff --git a/cli/src/translate.ts b/cli/src/translate.ts index 9fdf0aa4..dfa0fd18 100644 --- a/cli/src/translate.ts +++ b/cli/src/translate.ts @@ -1,15 +1,23 @@ import type { Langs, Locale } from './types.js' import { locales } from './locales/index.js' -function createTranslate(lang?: Langs) { +interface Translate { + setLang: (lang: Langs) => void + t: (key: keyof Locale) => string +} + +function createTranslate(lang?: Langs): Translate { let current: Langs = lang || 'en-US' return { - setLang: (lang: Langs) => { + setLang: (lang) => { current = lang }, - t: (key: keyof Locale) => locales[current][key], + t: key => locales[current][key], } } -export const { t, setLang } = createTranslate() +const translate = createTranslate() + +export const t: Translate['t'] = translate.t +export const setLang: Translate['setLang'] = translate.setLang diff --git a/cli/src/utils/fs.ts b/cli/src/utils/fs.ts index dd8d0dde..0be5b96a 100644 --- a/cli/src/utils/fs.ts +++ b/cli/src/utils/fs.ts @@ -22,7 +22,7 @@ export async function writeFiles( files: File[], target: string, rewrite?: (path: string) => string, -) { +): Promise { for (const { filepath, content } of files) { let root = path.join(target, filepath).replace(/\.handlebars$/, '') if (rewrite) diff --git a/cli/src/utils/index.ts b/cli/src/utils/index.ts index badbda4a..d28afa05 100644 --- a/cli/src/utils/index.ts +++ b/cli/src/utils/index.ts @@ -1,11 +1,11 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' -export const __dirname = path.dirname(fileURLToPath(import.meta.url)) +export const __dirname: string = path.dirname(fileURLToPath(import.meta.url)) -export const resolve = (...args: string[]) => path.resolve(__dirname, '../', ...args) +export const resolve = (...args: string[]): string => path.resolve(__dirname, '../', ...args) -export const getTemplate = (dir: string) => resolve('templates', dir) +export const getTemplate = (dir: string): string => resolve('templates', dir) export * from './fs.js' export * from './getPackageManager.js' diff --git a/docs/.vuepress/client.ts b/docs/.vuepress/client.ts index 1aa5976f..a24581b2 100644 --- a/docs/.vuepress/client.ts +++ b/docs/.vuepress/client.ts @@ -1,3 +1,4 @@ +import type { ClientConfig } from 'vuepress/client' import { h } from 'vue' import { Layout } from 'vuepress-theme-plume/client' import { defineClientConfig } from 'vuepress/client' @@ -13,4 +14,4 @@ export default defineClientConfig({ 'aside-outline-after': () => h(AsideNav), }), }, -}) +}) as ClientConfig diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index 27eb67a4..ab981aa6 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -1,3 +1,4 @@ +import type { UserConfig } from 'vuepress' import fs from 'node:fs' import path from 'node:path' import { viteBundler } from '@vuepress/bundler-vite' @@ -48,4 +49,4 @@ export default defineUserConfig({ shouldPrefetch: false, theme, -}) +}) as UserConfig diff --git a/docs/.vuepress/navbar.ts b/docs/.vuepress/navbar.ts index 61175400..0c310390 100644 --- a/docs/.vuepress/navbar.ts +++ b/docs/.vuepress/navbar.ts @@ -1,7 +1,8 @@ +import type { ThemeNavItem } from 'vuepress-theme-plume' import { defineNavbarConfig } from 'vuepress-theme-plume' import { version } from '../../package.json' -export const zhNavbar = defineNavbarConfig([ +export const zhNavbar: ThemeNavItem[] = defineNavbarConfig([ { text: '指南', icon: 'icon-park-outline:guide-board', @@ -54,7 +55,7 @@ export const zhNavbar = defineNavbarConfig([ }, ]) -export const enNavbar = defineNavbarConfig([ +export const enNavbar: ThemeNavItem[] = defineNavbarConfig([ { text: 'Guide', icon: 'icon-park-outline:guide-board', diff --git a/docs/.vuepress/notes/en/index.ts b/docs/.vuepress/notes/en/index.ts index 579c6a81..af7fd886 100644 --- a/docs/.vuepress/notes/en/index.ts +++ b/docs/.vuepress/notes/en/index.ts @@ -1,8 +1,9 @@ +import type { ThemeNoteListOptions } from 'vuepress-theme-plume' import { defineNotesConfig } from 'vuepress-theme-plume' import { themeConfig } from './theme-config' import { themeGuide } from './theme-guide' -export const enNotes = defineNotesConfig({ +export const enNotes: ThemeNoteListOptions = defineNotesConfig({ dir: 'en/notes', link: '/', notes: [ diff --git a/docs/.vuepress/notes/en/theme-config.ts b/docs/.vuepress/notes/en/theme-config.ts index a28c4599..0f34ec4f 100644 --- a/docs/.vuepress/notes/en/theme-config.ts +++ b/docs/.vuepress/notes/en/theme-config.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const themeConfig = defineNoteConfig({ +export const themeConfig: ThemeNote = defineNoteConfig({ dir: 'theme/config', link: '/config/', sidebar: [ diff --git a/docs/.vuepress/notes/en/theme-guide.ts b/docs/.vuepress/notes/en/theme-guide.ts index f439b565..91637f65 100644 --- a/docs/.vuepress/notes/en/theme-guide.ts +++ b/docs/.vuepress/notes/en/theme-guide.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const themeGuide = defineNoteConfig({ +export const themeGuide: ThemeNote = defineNoteConfig({ dir: 'theme/guide', link: '/guide/', sidebar: [ diff --git a/docs/.vuepress/notes/zh/index.ts b/docs/.vuepress/notes/zh/index.ts index 62247b24..4061e77d 100644 --- a/docs/.vuepress/notes/zh/index.ts +++ b/docs/.vuepress/notes/zh/index.ts @@ -1,10 +1,11 @@ +import type { ThemeNoteListOptions } from 'vuepress-theme-plume' import { defineNotesConfig } from 'vuepress-theme-plume' // import { plugins } from './plugins' import { themeConfig } from './theme-config' import { themeGuide } from './theme-guide' import { tools } from './tools' -export const zhNotes = defineNotesConfig({ +export const zhNotes: ThemeNoteListOptions = defineNotesConfig({ dir: 'notes', link: '/', notes: [ diff --git a/docs/.vuepress/notes/zh/plugins.ts b/docs/.vuepress/notes/zh/plugins.ts index 87379775..24d7828c 100644 --- a/docs/.vuepress/notes/zh/plugins.ts +++ b/docs/.vuepress/notes/zh/plugins.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const plugins = defineNoteConfig({ +export const plugins: ThemeNote = defineNoteConfig({ dir: 'plugins', link: '/plugins/', sidebar: [ diff --git a/docs/.vuepress/notes/zh/theme-config.ts b/docs/.vuepress/notes/zh/theme-config.ts index 514f4ed1..f85b554b 100644 --- a/docs/.vuepress/notes/zh/theme-config.ts +++ b/docs/.vuepress/notes/zh/theme-config.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const themeConfig = defineNoteConfig({ +export const themeConfig: ThemeNote = defineNoteConfig({ dir: 'theme/config', link: '/config/', sidebar: [ diff --git a/docs/.vuepress/notes/zh/theme-guide.ts b/docs/.vuepress/notes/zh/theme-guide.ts index 70859eea..72363a24 100644 --- a/docs/.vuepress/notes/zh/theme-guide.ts +++ b/docs/.vuepress/notes/zh/theme-guide.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const themeGuide = defineNoteConfig({ +export const themeGuide: ThemeNote = defineNoteConfig({ dir: 'theme/guide', link: '/guide/', sidebar: [ diff --git a/docs/.vuepress/notes/zh/tools.ts b/docs/.vuepress/notes/zh/tools.ts index 769c3d61..8e1924d3 100644 --- a/docs/.vuepress/notes/zh/tools.ts +++ b/docs/.vuepress/notes/zh/tools.ts @@ -1,6 +1,7 @@ +import type { ThemeNote } from 'vuepress-theme-plume' import { defineNoteConfig } from 'vuepress-theme-plume' -export const tools = defineNoteConfig({ +export const tools: ThemeNote = defineNoteConfig({ dir: 'tools', link: '/tools/', sidebar: [ diff --git a/docs/.vuepress/plume.config.ts b/docs/.vuepress/plume.config.ts index 8544c7b3..61a1d0ad 100644 --- a/docs/.vuepress/plume.config.ts +++ b/docs/.vuepress/plume.config.ts @@ -1,3 +1,4 @@ +import type { ThemeConfig } from 'vuepress-theme-plume' import path from 'node:path' import { defineThemeConfig } from 'vuepress-theme-plume' import { enNavbar, zhNavbar } from './navbar.js' @@ -49,4 +50,4 @@ export default defineThemeConfig({ contentFile: path.join(__dirname, 'bulletin.md'), enablePage: page => page.path === '/guide/features/bulletin/', }, -}) +}) as ThemeConfig diff --git a/docs/.vuepress/themes/composables/caniuse.ts b/docs/.vuepress/themes/composables/caniuse.ts index 87481786..8bafff15 100644 --- a/docs/.vuepress/themes/composables/caniuse.ts +++ b/docs/.vuepress/themes/composables/caniuse.ts @@ -1,4 +1,4 @@ -import type { Ref } from 'vue' +import type { ComputedRef, Ref } from 'vue' import { onClickOutside, useDebounceFn, useEventListener, useLocalStorage } from '@vueuse/core' import { computed, onMounted, readonly, ref, watch } from 'vue' @@ -35,7 +35,14 @@ const embedTypes: SelectItem[] = [ { label: 'image', value: 'image' }, ] -export function useCaniuseVersionSelect() { +export function useCaniuseVersionSelect(): { + past: Ref + future: Ref + embedType: Ref + pastList: Readonly + futureList: Readonly + embedTypeList: Readonly +} { const past = ref('2') const future = ref('1') const embedType = ref('') @@ -57,7 +64,12 @@ export function useCaniuseVersionSelect() { export function useCaniuseFeaturesSearch( inputEl: Ref, listEl: Ref, -) { +): { + featureList: Ref + isFocus: Ref + feature: ComputedRef + onSelect: (item: Feature) => void + } { const features = useLocalStorage('plume:caniuse-feature-list', [] as Feature[]) const featuresUpdated = useLocalStorage('plume:caniuse-feature-list-updated', Date.now()) const maxAge = 1000 * 60 * 60 * 24 * 3 // 3 days @@ -104,7 +116,7 @@ export function useCaniuseFeaturesSearch( isFocus.value = true }) - function onSelect(item: Feature) { + function onSelect(item: Feature): void { selected.value = item isFocus.value = false if (inputEl.value) @@ -124,7 +136,10 @@ export function useCaniuse({ feature, embedType, past, future }: { embedType: Ref past: Ref future: Ref -}) { +}): { + output: ComputedRef + rendered: ComputedRef + } { const output = computed(() => { let content = '@[caniuse' if (embedType.value) diff --git a/docs/.vuepress/themes/composables/theme-colors.ts b/docs/.vuepress/themes/composables/theme-colors.ts index 95ab7ed4..9201dc60 100644 --- a/docs/.vuepress/themes/composables/theme-colors.ts +++ b/docs/.vuepress/themes/composables/theme-colors.ts @@ -2,6 +2,8 @@ import type { InjectionKey, Ref } from 'vue' import { useSessionStorage, useStyleTag } from '@vueuse/core' import { inject, provide, watch } from 'vue' +declare const __VUEPRESS_DEV__: boolean + export interface ThemeColor { name: string key: string @@ -82,14 +84,16 @@ const preset: ThemeColorsGroup[] = [ }, ] -const themeColorSymbol: InjectionKey<{ +interface ThemeColorResult { lightColors: Ref darkColors: Ref css: Ref reset: () => void -}> = Symbol(__VUEPRESS_DEV__ ? 'theme-color' : '') +} -export function setupThemeColors() { +const themeColorSymbol: InjectionKey = Symbol(__VUEPRESS_DEV__ ? 'theme-color' : '') + +export function setupThemeColors(): void { const lightColors = useSessionStorage('custom-theme-colors-light', resolveDefaultColors('light')) const darkColors = useSessionStorage('custom-theme-colors-dark', resolveDefaultColors('dark')) @@ -138,7 +142,7 @@ function resolveDefaultColors(type: 'light' | 'dark') { })) } -export function useThemeColors() { +export function useThemeColors(): ThemeColorResult { const result = inject(themeColorSymbol) if (!result) { diff --git a/plugins/plugin-fonts/tsup.config.ts b/plugins/plugin-fonts/tsup.config.ts index 1368098a..e4343cc4 100644 --- a/plugins/plugin-fonts/tsup.config.ts +++ b/plugins/plugin-fonts/tsup.config.ts @@ -38,4 +38,4 @@ export default defineConfig(() => { ]) } return options -}) +}) as Options[] diff --git a/plugins/plugin-md-power/src/client/composables/audio.ts b/plugins/plugin-md-power/src/client/composables/audio.ts index c2ed9bcd..1fd19b44 100644 --- a/plugins/plugin-md-power/src/client/composables/audio.ts +++ b/plugins/plugin-md-power/src/client/composables/audio.ts @@ -1,4 +1,4 @@ -import type { MaybeRef } from 'vue' +import type { MaybeRef, Ref } from 'vue' import { onMounted, onUnmounted, ref, toValue, watch } from 'vue' const mimeTypes = { @@ -36,9 +36,23 @@ export interface AudioPlayerOptions { onwaiting?: HTMLAudioElement['onwaiting'] } +interface UseAudioPlayerResult { + player: HTMLAudioElement | null + isSupported: Ref + loaded: Ref + paused: Ref + currentTime: Ref + duration: Ref + play: () => void + pause: () => void + seek: (time: number) => void + setVolume: (volume: number) => void + destroy: () => void +} + const playerList: HTMLAudioElement[] = [] -export function useAudioPlayer(source: MaybeRef, options: AudioPlayerOptions = {}) { +export function useAudioPlayer(source: MaybeRef, options: AudioPlayerOptions = {}): UseAudioPlayerResult { let player: HTMLAudioElement | null = null let unknownSupport = false @@ -194,7 +208,7 @@ export function useAudioPlayer(source: MaybeRef, options: AudioPlayerOpt return false } - function destroy() { + function destroy(): void { player?.pause() player?.remove() playerList.splice(playerList.indexOf(player!), 1) diff --git a/plugins/plugin-md-power/src/client/composables/codeRepl.ts b/plugins/plugin-md-power/src/client/composables/codeRepl.ts index 5cab6db2..6342aec3 100644 --- a/plugins/plugin-md-power/src/client/composables/codeRepl.ts +++ b/plugins/plugin-md-power/src/client/composables/codeRepl.ts @@ -38,7 +38,10 @@ export function resolveCode(el: HTMLElement): string { return clone.textContent || '' } -export function resolveCodeInfo(el: HTMLDivElement) { +export function resolveCodeInfo(el: HTMLDivElement): { + lang: Lang + code: string +} { const wrapper = el.querySelector('div[class*=language-]') const lang = wrapper?.className.match(RE_LANGUAGE)?.[1] const codeEl = wrapper?.querySelector('pre') as HTMLElement @@ -50,7 +53,20 @@ export function resolveCodeInfo(el: HTMLDivElement) { return { lang: resolveLang(lang) as Lang, code } } -export function useCodeRepl(el: Ref) { +interface UseCodeReplResult { + lang: Ref + loaded: Ref + firstRun: Ref + finished: Ref + stdout: Ref + stderr: Ref + error: Ref + backendVersion: Ref + onCleanRun: () => void + onRunCode: () => Promise +} + +export function useCodeRepl(el: Ref): UseCodeReplResult { const lang = ref() const loaded = ref(true) const firstRun = ref(true) @@ -74,7 +90,7 @@ export function useCodeRepl(el: Ref) { rust: executeRust, } - function onCleanRun() { + function onCleanRun(): void { loaded.value = false finished.value = false stdout.value = [] @@ -84,7 +100,7 @@ export function useCodeRepl(el: Ref) { backendVersion.value = '' } - async function onRunCode() { + async function onRunCode(): Promise { if (!el.value || !loaded.value) return const info = resolveCodeInfo(el.value) diff --git a/plugins/plugin-md-power/src/client/composables/demo.ts b/plugins/plugin-md-power/src/client/composables/demo.ts index 1a887c5d..ea376082 100644 --- a/plugins/plugin-md-power/src/client/composables/demo.ts +++ b/plugins/plugin-md-power/src/client/composables/demo.ts @@ -1,4 +1,4 @@ -import type { MaybeRefOrGetter, ShallowRef } from 'vue' +import type { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from 'vue' import { onClickOutside, useEventListener } from '@vueuse/core' import { computed, getCurrentInstance, onMounted, ref, toValue, useId, watch } from 'vue' import { isPlainObject } from 'vuepress/shared' @@ -11,7 +11,7 @@ export interface DemoConfig { cssLib: string[] } -export function useExpand(defaultExpand = true) { +export function useExpand(defaultExpand = true): readonly [Ref, () => void] { const expanded = ref(defaultExpand) function toggle() { expanded.value = !expanded.value @@ -19,11 +19,24 @@ export function useExpand(defaultExpand = true) { return [expanded, toggle] as const } -export function useResources(el: ShallowRef, config: MaybeRefOrGetter) { - const resources = computed<{ - name: string - items: { name: string, url: string }[] - }[]>(() => { +interface ResourceItem { + name: string + items: SubResourceItem[] +} + +interface SubResourceItem { + name: string + url: string +} + +interface UseResourcesResult { + resources: ComputedRef + showResources: Ref + toggleResources: () => void +} + +export function useResources(el: ShallowRef, config: MaybeRefOrGetter): UseResourcesResult { + const resources = computed(() => { const conf = toValue(config) if (!conf) return [] @@ -39,7 +52,7 @@ export function useResources(el: ShallowRef, config: Mayb const showResources = ref(false) - function toggleResources() { + function toggleResources(): void { showResources.value = !showResources.value } @@ -54,14 +67,16 @@ export function useResources(el: ShallowRef, config: Mayb } } -export function useFence(fence: ShallowRef, config: MaybeRefOrGetter) { - const data = ref<{ - js: string - css: string - html: string - jsType: string - cssType: string - }>({ js: '', css: '', html: '', jsType: '', cssType: '' }) +interface FenceData { + js: string + css: string + html: string + jsType: string + cssType: string +} + +export function useFence(fence: ShallowRef, config: MaybeRefOrGetter): Ref { + const data = ref({ js: '', css: '', html: '', jsType: '', cssType: '' }) onMounted(() => { if (!fence.value) @@ -93,7 +108,7 @@ export function useNormalDemo( draw: ShallowRef, title: MaybeRefOrGetter, config: MaybeRefOrGetter, -) { +): { id: string, height: Ref } { const current = getCurrentInstance() const id = useId() const isDark = computed(() => current?.appContext.config.globalProperties.$isDark.value) @@ -157,7 +172,7 @@ function createHTMLTemplate(title: string, id: string, config?: DemoConfig): str ` } -export function parseData(data: any) { +export function parseData(data: any): any { try { if (typeof data === 'string') { return JSON.parse(data) diff --git a/plugins/plugin-md-power/src/client/composables/rustRepl.ts b/plugins/plugin-md-power/src/client/composables/rustRepl.ts index 11228dea..2366fe3e 100644 --- a/plugins/plugin-md-power/src/client/composables/rustRepl.ts +++ b/plugins/plugin-md-power/src/client/composables/rustRepl.ts @@ -66,7 +66,7 @@ function send(type: string, payload: Record, meta: Record { await connect() const meta = { sequenceNumber: uuid++ } const payload = { diff --git a/plugins/plugin-md-power/src/client/options.ts b/plugins/plugin-md-power/src/client/options.ts index 7b135abd..dd8bcb3e 100644 --- a/plugins/plugin-md-power/src/client/options.ts +++ b/plugins/plugin-md-power/src/client/options.ts @@ -5,15 +5,19 @@ declare const __MD_POWER_DASHJS_INSTALLED__: boolean declare const __MD_POWER_HLSJS_INSTALLED__: boolean declare const __MD_POWER_MPEGTSJS_INSTALLED__: boolean -export const pluginOptions = __MD_POWER_INJECT_OPTIONS__ +export const pluginOptions: MarkdownPowerPluginOptions = __MD_POWER_INJECT_OPTIONS__ -export const installed = { +export const installed: { + dashjs: boolean + hlsjs: boolean + mpegtsjs: boolean +} = { dashjs: __MD_POWER_DASHJS_INSTALLED__, hlsjs: __MD_POWER_HLSJS_INSTALLED__, mpegtsjs: __MD_POWER_MPEGTSJS_INSTALLED__, } -export const ART_PLAYER_SUPPORTED_VIDEO_TYPES = ['mp4', 'mp3', 'webm', 'ogg'] +export const ART_PLAYER_SUPPORTED_VIDEO_TYPES: string[] = ['mp4', 'mp3', 'webm', 'ogg'] if (installed.dashjs) { ART_PLAYER_SUPPORTED_VIDEO_TYPES.push('mpd', 'dash') @@ -27,10 +31,10 @@ if (installed.mpegtsjs) { ART_PLAYER_SUPPORTED_VIDEO_TYPES.push('ts', 'flv') } -export const INJECT_TIMELINE_KEY = Symbol( +export const INJECT_TIMELINE_KEY: symbol = Symbol( __VUEPRESS_DEV__ ? 'timeline' : '', ) -export const INJECT_COLLAPSE_KEY = Symbol( +export const INJECT_COLLAPSE_KEY: symbol = Symbol( __VUEPRESS_DEV__ ? 'collapse' : '', ) diff --git a/plugins/plugin-md-power/src/node/container/card.ts b/plugins/plugin-md-power/src/node/container/card.ts index c41b4af0..d3455b50 100644 --- a/plugins/plugin-md-power/src/node/container/card.ts +++ b/plugins/plugin-md-power/src/node/container/card.ts @@ -13,7 +13,7 @@ interface CardMasonryAttrs { gap?: number } -export function cardPlugin(md: Markdown) { +export function cardPlugin(md: Markdown): void { /** * ::: card title="xxx" icon="xxx" * xxx diff --git a/plugins/plugin-md-power/src/node/container/codeTree.ts b/plugins/plugin-md-power/src/node/container/codeTree.ts index 28233cad..9d1a86dd 100644 --- a/plugins/plugin-md-power/src/node/container/codeTree.ts +++ b/plugins/plugin-md-power/src/node/container/codeTree.ts @@ -111,7 +111,7 @@ function parseFileNodes(files: string[]): FileTreeNode[] { return nodes } -export function codeTreePlugin(md: Markdown, app: App, options: CodeTreeOptions = {}) { +export function codeTreePlugin(md: Markdown, app: App, options: CodeTreeOptions = {}): void { const getIcon = (filename: string, type: 'folder' | 'file', mode?: FileTreeIconMode): string => { mode ||= options.icon || 'colored' if (mode === 'simple') diff --git a/plugins/plugin-md-power/src/node/container/createContainer.ts b/plugins/plugin-md-power/src/node/container/createContainer.ts index 6fa2304a..04dc578f 100644 --- a/plugins/plugin-md-power/src/node/container/createContainer.ts +++ b/plugins/plugin-md-power/src/node/container/createContainer.ts @@ -15,7 +15,7 @@ export function createContainerPlugin( md: Markdown, type: string, { before, after }: ContainerOptions = {}, -) { +): void { const render: RenderRule = (tokens, index, options, env): string => { const token = tokens[index] const info = token.info.trim().slice(type.length).trim() || '' @@ -51,7 +51,7 @@ export function createContainerSyntaxPlugin( md: Markdown, type: string, render?: RenderRule, -) { +): void { const maker = ':' const markerMinLen = 3 diff --git a/plugins/plugin-md-power/src/node/container/field.ts b/plugins/plugin-md-power/src/node/container/field.ts index ada9dd79..05e83163 100644 --- a/plugins/plugin-md-power/src/node/container/field.ts +++ b/plugins/plugin-md-power/src/node/container/field.ts @@ -12,7 +12,7 @@ interface FieldAttrs { default?: string } -export function fieldPlugin(md: Markdown) { +export function fieldPlugin(md: Markdown): void { createContainerPlugin(md, 'field', { before: (info) => { const { attrs } = resolveAttrs(info) diff --git a/plugins/plugin-md-power/src/node/container/fileTree.ts b/plugins/plugin-md-power/src/node/container/fileTree.ts index 8180853c..b3ad34ee 100644 --- a/plugins/plugin-md-power/src/node/container/fileTree.ts +++ b/plugins/plugin-md-power/src/node/container/fileTree.ts @@ -94,7 +94,7 @@ export function parseFileTreeNodeInfo(info: string): FileTreeNodeProps { return { filename, comment, focus, expanded, type, diff } } -export function fileTreePlugin(md: Markdown, options: FileTreeOptions = {}) { +export function fileTreePlugin(md: Markdown, options: FileTreeOptions = {}): void { const getIcon = (filename: string, type: 'folder' | 'file', mode?: FileTreeIconMode): string => { mode ||= options.icon || 'colored' if (mode === 'simple') diff --git a/plugins/plugin-md-power/src/node/container/index.ts b/plugins/plugin-md-power/src/node/container/index.ts index eb7facde..6e70c5c0 100644 --- a/plugins/plugin-md-power/src/node/container/index.ts +++ b/plugins/plugin-md-power/src/node/container/index.ts @@ -21,7 +21,7 @@ export async function containerPlugin( app: App, md: Markdown, options: MarkdownPowerPluginOptions, -) { +): Promise { // ::: left / right / center / justify alignPlugin(md) // ::: tabs diff --git a/plugins/plugin-md-power/src/node/container/langRepl.ts b/plugins/plugin-md-power/src/node/container/langRepl.ts index 8514e115..c77b83e5 100644 --- a/plugins/plugin-md-power/src/node/container/langRepl.ts +++ b/plugins/plugin-md-power/src/node/container/langRepl.ts @@ -18,7 +18,7 @@ export async function langReplPlugin(app: App, md: markdownIt, { go = false, kotlin = false, rust = false, -}: ReplOptions) { +}: ReplOptions): Promise { const container = (lang: string): void => createContainerPlugin(md, `${lang}-repl`, { before(info) { const { attrs } = resolveAttrs(info) diff --git a/plugins/plugin-md-power/src/node/container/steps.ts b/plugins/plugin-md-power/src/node/container/steps.ts index ef3b8759..112b4383 100644 --- a/plugins/plugin-md-power/src/node/container/steps.ts +++ b/plugins/plugin-md-power/src/node/container/steps.ts @@ -10,7 +10,7 @@ import { createContainerPlugin } from './createContainer.js' * 3. ... * ::: */ -export function stepsPlugin(md: Markdown) { +export function stepsPlugin(md: Markdown): void { createContainerPlugin(md, 'steps', { before: () => '
', }) diff --git a/plugins/plugin-md-power/src/node/container/timeline.ts b/plugins/plugin-md-power/src/node/container/timeline.ts index c0d6d7d2..cc2c8c85 100644 --- a/plugins/plugin-md-power/src/node/container/timeline.ts +++ b/plugins/plugin-md-power/src/node/container/timeline.ts @@ -40,7 +40,7 @@ const RE_KEY = /(\w+)=\s*/ const RE_SEARCH_KEY = /\s+\w+=\s*|$/ const RE_CLEAN_VALUE = /(?["'])(.*?)(\k)/ -export function timelinePlugin(md: Markdown) { +export function timelinePlugin(md: Markdown): void { createContainerPlugin(md, 'timeline', { before(info, tokens, index) { parseTimeline(tokens, index) diff --git a/plugins/plugin-md-power/src/node/demo/demo.ts b/plugins/plugin-md-power/src/node/demo/demo.ts index e53e7e41..0d868e19 100644 --- a/plugins/plugin-md-power/src/node/demo/demo.ts +++ b/plugins/plugin-md-power/src/node/demo/demo.ts @@ -11,7 +11,7 @@ import { normalContainerRender, normalEmbed } from './normal.js' import { normalizeAlias } from './supports/alias.js' import { vueContainerRender, vueEmbed } from './vue.js' -export function demoEmbed(app: App, md: Markdown) { +export function demoEmbed(app: App, md: Markdown): void { createEmbedRuleBlock(md, { type: 'demo', syntaxPattern: /^@\[demo(?:\s(vue|normal|markdown))?\s?(.*)\]\((.*)\)/, @@ -50,7 +50,7 @@ const renderMap: Record = { markdown: markdownContainerRender, } -export function demoContainer(app: App, md: Markdown) { +export function demoContainer(app: App, md: Markdown): void { let currentRender: DemoContainerRender | undefined const render: RenderRule = ( tokens: Token[], diff --git a/plugins/plugin-md-power/src/node/demo/index.ts b/plugins/plugin-md-power/src/node/demo/index.ts index 2acf2c8c..eba10b44 100644 --- a/plugins/plugin-md-power/src/node/demo/index.ts +++ b/plugins/plugin-md-power/src/node/demo/index.ts @@ -3,7 +3,7 @@ import type { Markdown } from 'vuepress/markdown' import { demoContainer, demoEmbed } from './demo.js' import { createDemoRender } from './watcher.js' -export function demoPlugin(app: App, md: Markdown) { +export function demoPlugin(app: App, md: Markdown): void { createDemoRender() demoEmbed(app, md) demoContainer(app, md) diff --git a/plugins/plugin-md-power/src/node/demo/normal.ts b/plugins/plugin-md-power/src/node/demo/normal.ts index 2cc5cc44..70d1d1d3 100644 --- a/plugins/plugin-md-power/src/node/demo/normal.ts +++ b/plugins/plugin-md-power/src/node/demo/normal.ts @@ -67,7 +67,7 @@ function codeToHtml(md: Markdown, source: NormalCode, info: string): string { return md.render(content, {}) } -export async function compileCode(code: NormalCode, output: string) { +export async function compileCode(code: NormalCode, output: string): Promise { markDemoRender() const res = { jsLib: [], cssLib: [], script: '', css: '', html: '' } if (!fs.existsSync(output)) diff --git a/plugins/plugin-md-power/src/node/demo/supports/insertScript.ts b/plugins/plugin-md-power/src/node/demo/supports/insertScript.ts index 19ad5c0b..4b8efccb 100644 --- a/plugins/plugin-md-power/src/node/demo/supports/insertScript.ts +++ b/plugins/plugin-md-power/src/node/demo/supports/insertScript.ts @@ -2,7 +2,7 @@ import type { DemoFile, MarkdownDemoEnv } from '../../../shared/demo.js' const SCRIPT_RE = // -export function insertSetupScript({ export: name, path }: DemoFile, env: MarkdownDemoEnv) { +export function insertSetupScript({ export: name, path }: DemoFile, env: MarkdownDemoEnv): void { const imports = `import ${name ? `${name} from ` : ''}'${path}';` const scriptSetup = env.sfcBlocks!.scriptSetup ??= { type: 'script', diff --git a/plugins/plugin-md-power/src/node/demo/watcher.ts b/plugins/plugin-md-power/src/node/demo/watcher.ts index 332c66a4..fb66e943 100644 --- a/plugins/plugin-md-power/src/node/demo/watcher.ts +++ b/plugins/plugin-md-power/src/node/demo/watcher.ts @@ -14,13 +14,13 @@ let renderDone: null | ((...args: any[]) => void) = null let renderCount = 0 let renderPromise!: Promise -export function createDemoRender() { +export function createDemoRender(): void { renderPromise = new Promise((resolve) => { renderDone = resolve }) } -export async function waitDemoRender() { +export async function waitDemoRender(): Promise { if (renderCount === 0) { renderDone?.() renderDone = null @@ -28,11 +28,11 @@ export async function waitDemoRender() { await renderPromise } -export function markDemoRender() { +export function markDemoRender(): void { renderCount++ } -export function checkDemoRender() { +export function checkDemoRender(): void { if (renderCount > 0) { renderCount-- } @@ -47,7 +47,7 @@ let watcher: FSWatcher | null = null const tasks: Record = {} const target = 'md-power/demo/watcher.txt' -export function demoWatcher(app: App, watchers: any[]) { +export function demoWatcher(app: App, watchers: any[]): void { if (!watcher) { watcher = watch([], { ignoreInitial: true }) } @@ -89,7 +89,7 @@ export function demoWatcher(app: App, watchers: any[]) { }) } -export function addTask(app: App, path: string, output: string) { +export function addTask(app: App, path: string, output: string): void { if (tasks[path]) return tasks[path] = output diff --git a/plugins/plugin-md-power/src/node/embed/index.ts b/plugins/plugin-md-power/src/node/embed/index.ts index 59b269ce..a9f3f93d 100644 --- a/plugins/plugin-md-power/src/node/embed/index.ts +++ b/plugins/plugin-md-power/src/node/embed/index.ts @@ -11,7 +11,7 @@ import { artPlayerPlugin } from './video/artPlayer.js' import { bilibiliPlugin } from './video/bilibili.js' import { youtubePlugin } from './video/youtube.js' -export function embedSyntaxPlugin(md: Markdown, options: MarkdownPowerPluginOptions) { +export function embedSyntaxPlugin(md: Markdown, options: MarkdownPowerPluginOptions): void { if (options.caniuse) { const caniuse = options.caniuse === true ? {} : options.caniuse // @[caniuse](feature_name) diff --git a/plugins/plugin-md-power/src/node/enhance/imageSize.ts b/plugins/plugin-md-power/src/node/enhance/imageSize.ts index ab715ae6..41d2f9aa 100644 --- a/plugins/plugin-md-power/src/node/enhance/imageSize.ts +++ b/plugins/plugin-md-power/src/node/enhance/imageSize.ts @@ -32,7 +32,7 @@ export async function imageSizePlugin( app: App, md: Markdown, type: boolean | 'local' | 'all' = false, -) { +): Promise { if (!app.env.isBuild || !type) return @@ -159,7 +159,7 @@ function resolveImageUrl(src: string, env: MarkdownEnv, app: App): string { return path.resolve(src) } -export async function scanRemoteImageSize(app: App) { +export async function scanRemoteImageSize(app: App): Promise { if (!app.env.isBuild) return const cwd = app.dir.source() diff --git a/plugins/plugin-md-power/src/node/prepareConfigFile.ts b/plugins/plugin-md-power/src/node/prepareConfigFile.ts index 77bf767e..9cd0aaf8 100644 --- a/plugins/plugin-md-power/src/node/prepareConfigFile.ts +++ b/plugins/plugin-md-power/src/node/prepareConfigFile.ts @@ -10,7 +10,7 @@ const CLIENT_FOLDER = ensureEndingSlash( path.resolve(__dirname, '../client'), ) -export async function prepareConfigFile(app: App, options: MarkdownPowerPluginOptions) { +export async function prepareConfigFile(app: App, options: MarkdownPowerPluginOptions): Promise { const imports = new Set() const enhances = new Set() diff --git a/plugins/plugin-md-power/src/node/utils/nanoid.ts b/plugins/plugin-md-power/src/node/utils/nanoid.ts index 2b647dc9..d177694e 100644 --- a/plugins/plugin-md-power/src/node/utils/nanoid.ts +++ b/plugins/plugin-md-power/src/node/utils/nanoid.ts @@ -1,3 +1,3 @@ import { customAlphabet } from 'nanoid' -export const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5) +export const nanoid: (size?: number) => string = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5) diff --git a/plugins/plugin-md-power/tsup.config.ts b/plugins/plugin-md-power/tsup.config.ts index 3a136c85..2371140a 100644 --- a/plugins/plugin-md-power/tsup.config.ts +++ b/plugins/plugin-md-power/tsup.config.ts @@ -51,4 +51,4 @@ export default defineConfig(() => { }) as Options)) } return options -}) +}) as Options[] diff --git a/plugins/plugin-replace-assets/src/constants.ts b/plugins/plugin-replace-assets/src/constants.ts index 0f12ddb1..2693cdb6 100644 --- a/plugins/plugin-replace-assets/src/constants.ts +++ b/plugins/plugin-replace-assets/src/constants.ts @@ -1,6 +1,6 @@ export const PLUGIN_NAME = 'vuepress-plugin-replace-assets' -export const KNOWN_IMAGE_EXTENSIONS = [ +export const KNOWN_IMAGE_EXTENSIONS: string[] = [ 'png', 'jpg', 'jpeg', @@ -10,7 +10,7 @@ export const KNOWN_IMAGE_EXTENSIONS = [ 'avif', ] -export const KNOWN_MEDIA_EXTENSIONS = [ +export const KNOWN_MEDIA_EXTENSIONS: string[] = [ 'mp4', 'webm', 'ogg', @@ -25,7 +25,7 @@ export const KNOWN_MEDIA_EXTENSIONS = [ 'pdf', ] -export const KNOWN_ASSET_EXTENSIONS = [ +export const KNOWN_ASSET_EXTENSIONS: string[] = [ ...KNOWN_IMAGE_EXTENSIONS, ...KNOWN_MEDIA_EXTENSIONS, ] diff --git a/plugins/plugin-replace-assets/src/unplugin/index.ts b/plugins/plugin-replace-assets/src/unplugin/index.ts index a1229091..46974136 100644 --- a/plugins/plugin-replace-assets/src/unplugin/index.ts +++ b/plugins/plugin-replace-assets/src/unplugin/index.ts @@ -1,10 +1,18 @@ +import type { VitePlugin, WebpackPluginInstance } from 'unplugin' +import type { ReplacementRule } from '../options.js' import { createVitePlugin as _createVitePlugin, createWebpackPlugin as _createWebpackPlugin, + } from 'unplugin' import { unpluginFactory } from './factory.js' -export const createVitePlugin = () => _createVitePlugin(unpluginFactory) -export const createWebpackPlugin = () => _createWebpackPlugin(unpluginFactory) +export const createVitePlugin: () => ( + options: ReplacementRule[] +) => VitePlugin | VitePlugin[] = () => _createVitePlugin(unpluginFactory) + +export const createWebpackPlugin: () => ( + options: ReplacementRule[] +) => WebpackPluginInstance = () => _createWebpackPlugin(unpluginFactory) export * from './transform.js' diff --git a/plugins/plugin-replace-assets/src/unplugin/utils.ts b/plugins/plugin-replace-assets/src/unplugin/utils.ts index aef989db..75c89198 100644 --- a/plugins/plugin-replace-assets/src/unplugin/utils.ts +++ b/plugins/plugin-replace-assets/src/unplugin/utils.ts @@ -1,6 +1,6 @@ import { removeEndingSlash, removeLeadingSlash } from '@vuepress/helper' -export function createAssetPattern(prefix: string) { +export function createAssetPattern(prefix: string): RegExp { const s = `(${prefix}.*?)` return new RegExp( [ @@ -17,7 +17,7 @@ export function createAssetPattern(prefix: string) { const htmlLangRE = /\.(?:html|htm)$/ -export const isHTMLRequest = (request: string) => htmlLangRE.test(request) +export const isHTMLRequest = (request: string): boolean => htmlLangRE.test(request) const nonJsRe = /\.json(?:$|\?)/ diff --git a/plugins/plugin-replace-assets/tsup.config.ts b/plugins/plugin-replace-assets/tsup.config.ts index cf0ae11f..78ec2d27 100644 --- a/plugins/plugin-replace-assets/tsup.config.ts +++ b/plugins/plugin-replace-assets/tsup.config.ts @@ -21,4 +21,4 @@ export default defineConfig(() => { } return options -}) +}) as Options[] diff --git a/plugins/plugin-search/src/client/composables/locale.ts b/plugins/plugin-search/src/client/composables/locale.ts index 6bdf7a42..7e13589b 100644 --- a/plugins/plugin-search/src/client/composables/locale.ts +++ b/plugins/plugin-search/src/client/composables/locale.ts @@ -1,5 +1,5 @@ -import type { MaybeRef } from 'vue' -import type { SearchBoxLocales } from '../../shared/index.js' +import type { ComputedRef, MaybeRef } from 'vue' +import type { SearchBoxLocales, SearchLocaleOptions } from '../../shared/index.js' import { computed, toRef } from 'vue' import { useRouteLocale } from 'vuepress/client' @@ -21,7 +21,7 @@ const defaultLocales: SearchBoxLocales = { }, } -export function useLocale(locales: MaybeRef) { +export function useLocale(locales: MaybeRef): ComputedRef> { const localesRef = toRef(locales) const routeLocale = useRouteLocale() diff --git a/plugins/plugin-search/src/client/composables/searchIndex.ts b/plugins/plugin-search/src/client/composables/searchIndex.ts index 5b136422..91b77f32 100644 --- a/plugins/plugin-search/src/client/composables/searchIndex.ts +++ b/plugins/plugin-search/src/client/composables/searchIndex.ts @@ -1,11 +1,14 @@ +import type { ShallowRef } from 'vue' import { searchIndex } from '@internal/minisearchIndex' import { shallowRef } from 'vue' declare const __VUE_HMR_RUNTIME__: Record -const searchIndexData = shallowRef(searchIndex) +type SearchIndexData = Record Promise<{ default: string }>> -export function useSearchIndex() { +const searchIndexData = shallowRef(searchIndex) + +export function useSearchIndex(): ShallowRef { return searchIndexData } diff --git a/plugins/plugin-search/src/node/prepareSearchIndex.ts b/plugins/plugin-search/src/node/prepareSearchIndex.ts index 10ae1414..02372aac 100644 --- a/plugins/plugin-search/src/node/prepareSearchIndex.ts +++ b/plugins/plugin-search/src/node/prepareSearchIndex.ts @@ -47,7 +47,7 @@ export async function prepareSearchIndex({ app, isSearchable, searchOptions, -}: SearchIndexOptions) { +}: SearchIndexOptions): Promise { const start = performance.now() const pages = isSearchable ? app.pages.filter(isSearchable) : app.pages await pMap(pages, p => indexFile(p, searchOptions), { @@ -69,7 +69,7 @@ export async function onSearchIndexUpdated( isSearchable, searchOptions, }: SearchIndexOptions, -) { +): Promise { const pages = isSearchable ? app.pages.filter(isSearchable) : app.pages if (pages.some(p => p.filePathRelative?.endsWith(filepath))) { await indexFile(app.pages.find(p => p.filePathRelative?.endsWith(filepath))!, searchOptions) @@ -84,7 +84,7 @@ export async function onSearchIndexRemoved( isSearchable, searchOptions, }: SearchIndexOptions, -) { +): Promise { const pages = isSearchable ? app.pages.filter(isSearchable) : app.pages if (pages.some(p => p.filePathRelative?.endsWith(filepath))) { const page = app.pages.find(p => p.filePathRelative?.endsWith(filepath))! diff --git a/plugins/plugin-search/tsup.config.ts b/plugins/plugin-search/tsup.config.ts index a7f4c1c7..229a41eb 100644 --- a/plugins/plugin-search/tsup.config.ts +++ b/plugins/plugin-search/tsup.config.ts @@ -78,4 +78,4 @@ export default defineConfig(() => { } return options -}) +}) as Options[] diff --git a/theme/src/client/components/Blog/VPCategoriesGroup.vue b/theme/src/client/components/Blog/VPCategoriesGroup.vue index 3cb9a77b..0f5c3e2f 100644 --- a/theme/src/client/components/Blog/VPCategoriesGroup.vue +++ b/theme/src/client/components/Blog/VPCategoriesGroup.vue @@ -1,12 +1,12 @@