@slidev/types 0.48.0-beta.9 → 0.48.0

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.
package/client.d.ts CHANGED
@@ -1,5 +1,106 @@
1
- declare module '/@slidev/configs' {
2
- import { SlidevConfig } from './types'
1
+ // Types for virtual modules
2
+ // `#slidev/*` is an alias for `/@slidev/*`, because TS will consider `/@slidev/*` as an absolute path that we can't override
3
3
 
4
- export default SlidevConfig
4
+ declare module '#slidev/configs' {
5
+ import type { SlidevConfig } from '@slidev/types'
6
+
7
+ const configs: SlidevConfig
8
+ export default configs
9
+ }
10
+
11
+ declare module '#slidev/global-components/top' {
12
+ import type { ComponentOptions } from 'vue'
13
+
14
+ const component: ComponentOptions
15
+ export default component
16
+ }
17
+
18
+ declare module '#slidev/global-components/bottom' {
19
+ import type { ComponentOptions } from 'vue'
20
+
21
+ const component: ComponentOptions
22
+ export default component
23
+ }
24
+
25
+ declare module '#slidev/slides' {
26
+ import type { ShallowRef } from 'vue'
27
+ import type { SlideRoute } from '@slidev/types'
28
+
29
+ const slides: ShallowRef<SlideRoute[]>
30
+ export { slides }
31
+ }
32
+
33
+ declare module '#slidev/title-renderer' {
34
+ import type { ComponentOptions } from 'vue'
35
+
36
+ const component: ComponentOptions
37
+ export default component
38
+ }
39
+
40
+ declare module '#slidev/custom-nav-controls' {
41
+ import type { ComponentOptions } from 'vue'
42
+
43
+ const component: ComponentOptions
44
+ export default component
45
+ }
46
+
47
+ declare module '#slidev/shiki' {
48
+ import type { ShikiHighlighterCore } from 'shiki/core'
49
+ import type { BundledLanguage, BundledTheme } from 'shiki'
50
+
51
+ export { shikiToMonaco } from '@shikijs/monaco'
52
+
53
+ export const langs: BundledLanguage[]
54
+ export const themes: BundledTheme | Record<string, BundledTheme>
55
+ export const shiki: Promise<ShikiHighlighterCore>
56
+ }
57
+
58
+ declare module '#slidev/setups/monaco' {
59
+ import type { MonacoSetup } from '@slidev/types'
60
+
61
+ const setups: MonacoSetup[]
62
+ export default setups
63
+ }
64
+
65
+ declare module '#slidev/setups/code-runners' {
66
+ import type { CodeRunnersSetup } from '@slidev/types'
67
+
68
+ const setups: CodeRunnersSetup[]
69
+ export default setups
70
+ }
71
+
72
+ declare module '#slidev/setups/mermaid' {
73
+ import type { MermaidSetup } from '@slidev/types'
74
+
75
+ const setups: MermaidSetup[]
76
+ export default setups
77
+ }
78
+
79
+ declare module '#slidev/setups/main' {
80
+ import type { AppSetup } from '@slidev/types'
81
+
82
+ const setups: AppSetup[]
83
+ export default setups
84
+ }
85
+
86
+ declare module '#slidev/setups/root' {
87
+ import type { RootSetup } from '@slidev/types'
88
+
89
+ const setups: RootSetup[]
90
+ export default setups
91
+ }
92
+
93
+ declare module '#slidev/setups/shortcuts' {
94
+ import type { ShortcutsSetup } from '@slidev/types'
95
+
96
+ const setups: ShortcutsSetup[]
97
+ export default setups
98
+ }
99
+
100
+ declare module '#slidev/styles' {
101
+ // side-effects only
102
+ }
103
+
104
+ declare module '#slidev/monaco-types' {
105
+ // side-effects only
5
106
  }
package/dist/index.d.mts CHANGED
@@ -1,28 +1,34 @@
1
- import { ComputedRef } from '@vue/reactivity';
2
- import { TransitionGroupProps, App, Ref } from 'vue';
3
- import { Awaitable } from '@antfu/utils';
1
+ import { TransitionGroupProps, ComputedRef, App, Ref } from 'vue';
2
+ import { RouteMeta, RouteComponent, Router } from 'vue-router';
3
+ import { Arrayable, Awaitable, ArgumentsType } from '@antfu/utils';
4
4
  import * as monaco from 'monaco-editor';
5
- import { Router } from 'vue-router';
6
5
  import mermaid from 'mermaid';
7
6
  import { KatexOptions } from 'katex';
8
- import { CodeToHastOptions, Highlighter } from 'shiki';
7
+ import { CodeToHastOptions, CodeToHastOptionsCommon, BuiltinLanguage, CodeOptionsThemes, BuiltinTheme, CodeOptionsMeta, Highlighter, LanguageInput } from 'shiki';
9
8
  import { VitePluginConfig } from 'unocss/vite';
9
+ import Vue from '@vitejs/plugin-vue';
10
+ import VueJsx from '@vitejs/plugin-vue-jsx';
11
+ import Icons from 'unplugin-icons/vite';
12
+ import Components from 'unplugin-vue-components/vite';
13
+ import Markdown from 'unplugin-vue-markdown/vite';
14
+ import RemoteAssets from 'vite-plugin-remote-assets';
15
+ import ServerRef from 'vite-plugin-vue-server-ref';
10
16
 
11
17
  interface CommonArgs {
12
18
  entry: string;
13
19
  theme?: string;
14
20
  }
15
21
  interface ExportArgs extends CommonArgs {
16
- output?: string;
17
- format?: string;
18
- timeout?: number;
19
- range?: string;
20
- dark?: boolean;
22
+ 'output'?: string;
23
+ 'format'?: string;
24
+ 'timeout'?: number;
25
+ 'range'?: string;
26
+ 'dark'?: boolean;
21
27
  'with-clicks'?: boolean;
22
28
  'executable-path'?: string;
23
29
  'with-toc'?: boolean;
24
30
  'per-slide'?: boolean;
25
- scale?: number;
31
+ 'scale'?: number;
26
32
  }
27
33
  interface BuildArgs extends ExportArgs {
28
34
  watch: boolean;
@@ -64,9 +70,24 @@ interface SlidevConfig {
64
70
  * Enable Monaco
65
71
  *
66
72
  * @see https://sli.dev/custom/config-monaco.html
67
- * @default 'dev'
73
+ * @default true
68
74
  */
69
75
  monaco: boolean | 'dev' | 'build';
76
+ /**
77
+ * Where to load monaco types from
78
+ *
79
+ * - `cdn` - load from CDN with `@typescript/ata`
80
+ * - `local` - load from local node_modules
81
+ *
82
+ * @default 'local'
83
+ */
84
+ monacoTypesSource: 'cdn' | 'local' | 'none';
85
+ /**
86
+ * Additional node packages to load as monaco types
87
+ *
88
+ * @default []
89
+ */
90
+ monacoTypesAdditionalPackages: string[];
70
91
  /**
71
92
  * Show a download button in the SPA build,
72
93
  * could also be a link to custom pdf
@@ -419,8 +440,13 @@ interface SlidevPreparserExtension {
419
440
  transformRawLines?: (lines: string[]) => Promise<void> | void;
420
441
  transformSlide?: (content: string, frontmatter: any) => Promise<string | undefined>;
421
442
  }
422
- type PreparserExtensionLoader = (headmatter?: Record<string, unknown>, filepath?: string) => Promise<SlidevPreparserExtension[]>;
443
+ type PreparserExtensionLoader = (headmatter?: Record<string, unknown>, filepath?: string, mode?: string) => Promise<SlidevPreparserExtension[]>;
423
444
  type RenderContext = 'none' | 'slide' | 'overview' | 'presenter' | 'previewNext';
445
+ interface SlideRoute {
446
+ no: number;
447
+ meta: RouteMeta;
448
+ component: () => Promise<RouteComponent>;
449
+ }
424
450
  type LoadedSnippets = Record<string, string>;
425
451
  type ClicksElement = Element | string;
426
452
  type ClicksRelativeEls = Map<ClicksElement, number>;
@@ -462,8 +488,8 @@ interface ClicksInfo {
462
488
  type ResolvedClicksInfo = Required<ClicksInfo>;
463
489
  type ClicksMap = Map<ClicksElement, ClicksInfo>;
464
490
  interface ClicksContext {
491
+ current: number;
465
492
  readonly disabled: boolean;
466
- readonly current: number;
467
493
  readonly relativeOffsets: ClicksRelativeEls;
468
494
  readonly map: ClicksMap;
469
495
  resolve: (at: string | number, size?: number) => {
@@ -473,19 +499,70 @@ interface ClicksContext {
473
499
  };
474
500
  register: (el: ClicksElement, info: ClicksInfo) => void;
475
501
  unregister: (el: ClicksElement) => void;
502
+ onMounted: () => void;
476
503
  readonly currentOffset: number;
477
504
  readonly total: number;
478
505
  }
479
506
 
507
+ interface CodeRunnerContext {
508
+ /**
509
+ * Options passed to runner via the `runnerOptions` prop.
510
+ */
511
+ options: Record<string, unknown>;
512
+ /**
513
+ * Highlight code with shiki.
514
+ */
515
+ highlight: (code: string, lang: string, options?: Partial<CodeToHastOptions>) => Promise<string>;
516
+ /**
517
+ * Use (other) code runner to run code.
518
+ */
519
+ run: (code: string, lang: string) => Promise<CodeRunnerOutputs>;
520
+ }
521
+ interface CodeRunnerOutputHtml {
522
+ /**
523
+ * The HTML to be rendered.
524
+ *
525
+ * Slidev does NOT sanitize the HTML for you - make sure it's from trusted sources or sanitize it before passing it in
526
+ */
527
+ html: string;
528
+ }
529
+ interface CodeRunnerOutputDom {
530
+ /**
531
+ * The DOM element to be rendered.
532
+ */
533
+ element: HTMLElement;
534
+ }
535
+ interface CodeRunnerOutputError {
536
+ /**
537
+ * The error message to be displayed.
538
+ */
539
+ error: string;
540
+ }
541
+ interface CodeRunnerOutputText {
542
+ /**
543
+ * The text to be displayed.
544
+ */
545
+ text: string;
546
+ /**
547
+ * The class to be applied to the text.
548
+ */
549
+ class?: string;
550
+ /**
551
+ * The language to be highlighted.
552
+ */
553
+ highlightLang?: string;
554
+ }
555
+ type CodeRunnerOutputTextArray = CodeRunnerOutputText[];
556
+ type CodeRunnerOutput = CodeRunnerOutputHtml | CodeRunnerOutputError | CodeRunnerOutputText | CodeRunnerOutputTextArray | CodeRunnerOutputDom;
557
+ type CodeRunnerOutputs = Arrayable<CodeRunnerOutput>;
558
+ type CodeRunner = (code: string, ctx: CodeRunnerContext) => Awaitable<CodeRunnerOutputs>;
559
+ type CodeRunnerProviders = Record<string, CodeRunner>;
560
+
480
561
  interface AppContext {
481
562
  app: App;
482
563
  router: Router;
483
564
  }
484
565
  interface MonacoSetupReturn {
485
- theme?: {
486
- light?: string;
487
- dark?: string;
488
- };
489
566
  editorOptions?: monaco.editor.IEditorOptions;
490
567
  }
491
568
  type MermaidOptions = (typeof mermaid.initialize) extends (a: infer A) => any ? A : never;
@@ -517,17 +594,20 @@ interface ShikiContext {
517
594
  */
518
595
  loadTheme: (path: string) => Promise<any>;
519
596
  }
520
- type ShikiSetupReturn = Partial<CodeToHastOptions> & {
597
+ type ShikiSetupReturn = Partial<Omit<CodeToHastOptionsCommon<BuiltinLanguage>, 'lang'>> & CodeOptionsThemes<BuiltinTheme> & CodeOptionsMeta & {
521
598
  setup?: (highlighter: Highlighter) => Awaitable<void>;
599
+ langs?: (LanguageInput | BuiltinLanguage)[];
522
600
  };
523
601
  type ShikiSetup = (shiki: ShikiContext) => Awaitable<ShikiSetupReturn | void>;
524
602
  type KatexSetup = () => Awaitable<Partial<KatexOptions> | void>;
525
603
  type UnoSetup = () => Awaitable<Partial<VitePluginConfig> | void>;
526
604
  type PreparserSetup = (filepath: string) => SlidevPreparserExtension;
527
- type MonacoSetup = (m: typeof monaco) => Awaitable<MonacoSetupReturn>;
605
+ type MonacoSetup = (m: typeof monaco) => Awaitable<MonacoSetupReturn | void>;
528
606
  type AppSetup = (context: AppContext) => Awaitable<void>;
607
+ type RootSetup = () => Awaitable<void>;
529
608
  type MermaidSetup = () => Partial<MermaidOptions> | void;
530
609
  type ShortcutsSetup = (nav: NavOperations, defaultShortcuts: ShortcutOptions[]) => Array<ShortcutOptions>;
610
+ type CodeRunnersSetup = (runners: CodeRunnerProviders) => Awaitable<CodeRunnerProviders | void>;
531
611
  declare function defineShikiSetup(fn: ShikiSetup): ShikiSetup;
532
612
  declare function defineUnoSetup(fn: UnoSetup): UnoSetup;
533
613
  declare function defineMonacoSetup(fn: MonacoSetup): MonacoSetup;
@@ -536,8 +616,10 @@ declare function defineMermaidSetup(fn: MermaidSetup): MermaidSetup;
536
616
  declare function defineKatexSetup(fn: KatexSetup): KatexSetup;
537
617
  declare function defineShortcutsSetup(fn: ShortcutsSetup): ShortcutsSetup;
538
618
  declare function definePreparserSetup(fn: PreparserSetup): PreparserSetup;
619
+ declare function defineCodeRunnersSetup(fn: CodeRunnersSetup): CodeRunnersSetup;
539
620
 
540
621
  interface TocItem {
622
+ no: number;
541
623
  active?: boolean;
542
624
  activeParent?: boolean;
543
625
  children: TocItem[];
@@ -548,4 +630,86 @@ interface TocItem {
548
630
  title?: string;
549
631
  }
550
632
 
551
- export { type AppContext, type AppSetup, type BuildArgs, type BuiltinSlideTransition, type ClicksContext, type ClicksElement, type ClicksInfo, type ClicksMap, type ClicksRelativeEls, type CommonArgs, type DrawingsOptions, type ExportArgs, type FontOptions, type FrontmatterStyle, type KatexSetup, type LoadedSnippets, type MermaidOptions, type MermaidSetup, type MonacoSetup, type MonacoSetupReturn, type NavOperations, type PreparserExtensionLoader, type PreparserSetup, type RenderContext, type ResolvedClicksInfo, type ResolvedDrawingsOptions, type ResolvedExportOptions, type ResolvedFontOptions, type ShikiContext, type ShikiSetup, type ShikiSetupReturn, type ShortcutOptions, type ShortcutsSetup, type SlideInfo, type SlideInfoBase, type SlidePatch, type SlidevConfig, type SlidevData, type SlidevFeatureFlags, type SlidevMarkdown, type SlidevPreparserExtension, type SlidevThemeConfig, type SlidevThemeMeta, type SourceSlideInfo, type TocItem, type UnoSetup, defineAppSetup, defineKatexSetup, defineMermaidSetup, defineMonacoSetup, definePreparserSetup, defineShikiSetup, defineShortcutsSetup, defineUnoSetup };
633
+ declare module 'vite' {
634
+ interface CustomEventMap {
635
+ 'slidev:update-slide': {
636
+ no: number;
637
+ data: SlideInfo;
638
+ };
639
+ 'slidev:update-note': {
640
+ no: number;
641
+ note: string;
642
+ noteHTML: string;
643
+ };
644
+ }
645
+ }
646
+
647
+ interface RootsInfo {
648
+ cliRoot: string;
649
+ clientRoot: string;
650
+ userRoot: string;
651
+ userPkgJson: Record<string, any>;
652
+ userWorkspaceRoot: string;
653
+ }
654
+ interface SlidevEntryOptions {
655
+ /**
656
+ * Markdown entry
657
+ */
658
+ entry: string;
659
+ /**
660
+ * Theme id
661
+ */
662
+ theme?: string;
663
+ /**
664
+ * Remote password
665
+ */
666
+ remote?: string;
667
+ /**
668
+ * Enable inspect plugin
669
+ */
670
+ inspect?: boolean;
671
+ }
672
+ interface ResolvedSlidevOptions extends RootsInfo {
673
+ data: SlidevData;
674
+ entry: string;
675
+ themeRaw: string;
676
+ theme: string;
677
+ themeRoots: string[];
678
+ addonRoots: string[];
679
+ /**
680
+ * =`[...themeRoots, ...addonRoots, userRoot]` (`clientRoot` excluded)
681
+ */
682
+ roots: string[];
683
+ mode: 'dev' | 'build' | 'export';
684
+ remote?: string;
685
+ inspect?: boolean;
686
+ }
687
+ interface SlidevServerOptions {
688
+ /**
689
+ * @returns `false` if server should be restarted
690
+ */
691
+ loadData?: () => Promise<SlidevData | false>;
692
+ }
693
+
694
+ interface SlidevPluginOptions {
695
+ vue?: ArgumentsType<typeof Vue>[0];
696
+ vuejsx?: ArgumentsType<typeof VueJsx>[0];
697
+ markdown?: ArgumentsType<typeof Markdown>[0];
698
+ components?: ArgumentsType<typeof Components>[0];
699
+ icons?: ArgumentsType<typeof Icons>[0];
700
+ remoteAssets?: ArgumentsType<typeof RemoteAssets>[0];
701
+ serverRef?: ArgumentsType<typeof ServerRef>[0];
702
+ unocss?: VitePluginConfig;
703
+ }
704
+ declare module 'vite' {
705
+ interface UserConfig {
706
+ /**
707
+ * Custom internal plugin options for Slidev (advanced)
708
+ *
709
+ * @see https://github.com/slidevjs/slidev/blob/main/packages/slidev/node/options.ts#L50
710
+ */
711
+ slidev?: SlidevPluginOptions;
712
+ }
713
+ }
714
+
715
+ export { type AppContext, type AppSetup, type BuildArgs, type BuiltinSlideTransition, type ClicksContext, type ClicksElement, type ClicksInfo, type ClicksMap, type ClicksRelativeEls, type CodeRunner, type CodeRunnerContext, type CodeRunnerOutput, type CodeRunnerOutputDom, type CodeRunnerOutputError, type CodeRunnerOutputHtml, type CodeRunnerOutputText, type CodeRunnerOutputTextArray, type CodeRunnerOutputs, type CodeRunnerProviders, type CodeRunnersSetup, type CommonArgs, type DrawingsOptions, type ExportArgs, type FontOptions, type FrontmatterStyle, type KatexSetup, type LoadedSnippets, type MermaidOptions, type MermaidSetup, type MonacoSetup, type MonacoSetupReturn, type NavOperations, type PreparserExtensionLoader, type PreparserSetup, type RenderContext, type ResolvedClicksInfo, type ResolvedDrawingsOptions, type ResolvedExportOptions, type ResolvedFontOptions, type ResolvedSlidevOptions, type RootSetup, type RootsInfo, type ShikiContext, type ShikiSetup, type ShikiSetupReturn, type ShortcutOptions, type ShortcutsSetup, type SlideInfo, type SlideInfoBase, type SlidePatch, type SlideRoute, type SlidevConfig, type SlidevData, type SlidevEntryOptions, type SlidevFeatureFlags, type SlidevMarkdown, type SlidevPluginOptions, type SlidevPreparserExtension, type SlidevServerOptions, type SlidevThemeConfig, type SlidevThemeMeta, type SourceSlideInfo, type TocItem, type UnoSetup, defineAppSetup, defineCodeRunnersSetup, defineKatexSetup, defineMermaidSetup, defineMonacoSetup, definePreparserSetup, defineShikiSetup, defineShortcutsSetup, defineUnoSetup };
package/dist/index.mjs CHANGED
@@ -23,8 +23,12 @@ function defineShortcutsSetup(fn) {
23
23
  function definePreparserSetup(fn) {
24
24
  return fn;
25
25
  }
26
+ function defineCodeRunnersSetup(fn) {
27
+ return fn;
28
+ }
26
29
  export {
27
30
  defineAppSetup,
31
+ defineCodeRunnersSetup,
28
32
  defineKatexSetup,
29
33
  defineMermaidSetup,
30
34
  defineMonacoSetup,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/types",
3
- "version": "0.48.0-beta.9",
3
+ "version": "0.48.0",
4
4
  "description": "Shared types declarations for Slidev",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -22,6 +22,22 @@
22
22
  "engines": {
23
23
  "node": ">=18.0.0"
24
24
  },
25
+ "dependencies": {
26
+ "@antfu/utils": "^0.7.7",
27
+ "@vitejs/plugin-vue": "^5.0.4",
28
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
29
+ "katex": "^0.16.9",
30
+ "mermaid": "^10.9.0",
31
+ "monaco-editor": "^0.46.0",
32
+ "shiki": "^1.1.7",
33
+ "unocss": "^0.58.5",
34
+ "unplugin-icons": "^0.18.5",
35
+ "unplugin-vue-markdown": "^0.26.0",
36
+ "vite-plugin-remote-assets": "^0.4.1",
37
+ "vite-plugin-vue-server-ref": "^0.4.2",
38
+ "vue": "^3.4.21",
39
+ "vue-router": "^4.3.0"
40
+ },
25
41
  "scripts": {
26
42
  "build": "tsup src/index.ts",
27
43
  "dev": "nr build --watch"