| 1 | import type { Component } from 'vue' |
| 2 | import type { RouteComponent, RouteMeta } from 'vue-router' |
| 3 | import type YAML from 'yaml' |
| 4 | import type { SlidevConfig } from './config' |
| 5 | |
| 6 | export type FrontmatterStyle = 'frontmatter' | 'yaml' |
| 7 | |
| 8 | export interface SlideInfoBase { |
| 9 | revision: string |
| 10 | frontmatter: Record<string, any> |
| 11 | content: string |
| 12 | frontmatterRaw?: string |
| 13 | note?: string |
| 14 | title?: string |
| 15 | level?: number |
| 16 | /** |
| 17 | * Image URLs extracted from the slide content (frontmatter, markdown, Vue components, CSS). |
| 18 | * Populated at parse time to survive build-mode content stripping. |
| 19 | */ |
| 20 | images?: string[] |
| 21 | } |
| 22 | |
| 23 | export interface SourceSlideInfo extends SlideInfoBase { |
| 24 | /** |
| 25 | * The filepath of the markdown file |
| 26 | */ |
| 27 | filepath: string |
| 28 | /** |
| 29 | * The index of the slide in the markdown file |
| 30 | */ |
| 31 | index: number |
| 32 | /** |
| 33 | * The range of the slide in the markdown file |
| 34 | */ |
| 35 | start: number |
| 36 | contentStart: number |
| 37 | end: number |
| 38 | raw: string |
| 39 | /** |
| 40 | * Raw content before being processed by preparsers (if any) |
| 41 | */ |
| 42 | contentRaw: string |
| 43 | /** |
| 44 | * Slides imported by this slide. |
| 45 | */ |
| 46 | imports?: SourceSlideInfo[] |
| 47 | frontmatterDoc?: YAML.Document<YAML.Node, true> |
| 48 | frontmatterStyle?: FrontmatterStyle |
| 49 | } |
| 50 | |
| 51 | export interface SlideInfo extends SlideInfoBase { |
| 52 | /** |
| 53 | * The index of the slide in the presentation |
| 54 | */ |
| 55 | index: number |
| 56 | /** |
| 57 | * The importers of this slide. `[]` if this slide is the entry markdown file |
| 58 | */ |
| 59 | importChain?: SourceSlideInfo[] |
| 60 | /** |
| 61 | * The source slide where the content is from |
| 62 | */ |
| 63 | source: SourceSlideInfo |
| 64 | noteHTML?: string |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Editable fields for a slide |
| 69 | */ |
| 70 | export type SlidePatch = Partial<Pick<SlideInfoBase, 'content' | 'note' | 'frontmatterRaw'>> & { |
| 71 | skipHmr?: boolean |
| 72 | /** |
| 73 | * The frontmatter patch (only the changed fields) |
| 74 | * `null` to remove a field |
| 75 | */ |
| 76 | frontmatter?: Record<string, any> |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Metadata for "slidev" field in themes' package.json |
| 81 | */ |
| 82 | export interface SlidevThemeMeta { |
| 83 | defaults?: Partial<SlidevConfig> |
| 84 | colorSchema?: 'dark' | 'light' | 'both' |
| 85 | highlighter?: 'shiki' |
| 86 | } |
| 87 | |
| 88 | export type SlidevThemeConfig = Record<string, string | number> |
| 89 | |
| 90 | export interface SlidevDetectedFeatures { |
| 91 | katex: boolean |
| 92 | /** |
| 93 | * `false` or referenced module specifiers |
| 94 | */ |
| 95 | monaco: false | { |
| 96 | types: string[] |
| 97 | deps: string[] |
| 98 | } |
| 99 | tweet: boolean |
| 100 | bluesky: boolean |
| 101 | mermaid: boolean |
| 102 | } |
| 103 | |
| 104 | export interface SlidevMarkdown { |
| 105 | filepath: string |
| 106 | raw: string |
| 107 | /** |
| 108 | * All slides in this markdown file |
| 109 | */ |
| 110 | slides: SourceSlideInfo[] |
| 111 | errors?: { row: number, message: string }[] |
| 112 | } |
| 113 | |
| 114 | export interface SlidevData { |
| 115 | /** |
| 116 | * Slides that should be rendered (disabled slides excluded) |
| 117 | */ |
| 118 | slides: SlideInfo[] |
| 119 | entry: SlidevMarkdown |
| 120 | config: SlidevConfig |
| 121 | headmatter: Record<string, unknown> |
| 122 | features: SlidevDetectedFeatures |
| 123 | themeMeta?: SlidevThemeMeta |
| 124 | markdownFiles: Record<string, SlidevMarkdown> |
| 125 | /** |
| 126 | * From watched files to indexes of slides that must be reloaded regardless of the loaded content |
| 127 | */ |
| 128 | watchFiles: Record<string, Set<number>> |
| 129 | } |
| 130 | |
| 131 | export interface SlidevPreparserExtension { |
| 132 | name?: string |
| 133 | transformRawLines?: (lines: string[]) => Promise<void> | void |
| 134 | transformSlide?: (content: string, frontmatter: any) => Promise<string | undefined> |
| 135 | transformNote?: (note: string | undefined, frontmatter: any) => Promise<string | undefined> |
| 136 | } |
| 137 | |
| 138 | export type PreparserExtensionLoader = (roots: string[], headmatter: Record<string, unknown>, filepath: string, mode?: string) => Promise<SlidevPreparserExtension[]> |
| 139 | |
| 140 | export type RenderContext = 'none' | 'slide' | 'overview' | 'presenter' | 'previewNext' |
| 141 | |
| 142 | export interface SlideRoute { |
| 143 | no: number |
| 144 | meta: RouteMeta & Required<Pick<RouteMeta, 'slide'>> |
| 145 | /** |
| 146 | * load the slide component itself |
| 147 | */ |
| 148 | load: () => Promise<{ default: RouteComponent }> |
| 149 | /** |
| 150 | * Wrapped async component |
| 151 | */ |
| 152 | component: Component |
| 153 | } |
| 154 |