markview-vue 0.1.9 → 0.1.11

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/dist/index.d.ts CHANGED
@@ -5,7 +5,6 @@ import { FunctionalComponent } from 'vue';
5
5
  import { HighlighterCore } from 'shiki/core';
6
6
  import { InjectionKey } from 'vue';
7
7
  import { LucideProps } from 'lucide-vue-next';
8
- import { MDXComponents } from 'mdx/types';
9
8
  import { MDXProps } from 'mdx/types';
10
9
  import { PluggableList } from '@mdx-js/mdx/lib/core';
11
10
  import { Plugin as Plugin_2 } from 'vue';
@@ -673,6 +672,32 @@ declare type ContainerType_2 = 'tip' | 'warning' | 'danger' | 'info';
673
672
  */
674
673
  export declare function copyToClipboard(text: string): Promise<boolean>;
675
674
 
675
+ /**
676
+ * 创建 Highlighter Vue Plugin
677
+ *
678
+ * 在应用初始化时预加载语言,后续所有 MarkdownRender 实例自动可用。
679
+ *
680
+ * @example
681
+ * ```ts
682
+ * import { createHighlighterPlugin } from 'markview-vue'
683
+ *
684
+ * // 方式 1:传入多个语言
685
+ * app.use(createHighlighterPlugin({
686
+ * langs: [
687
+ * import('@shikijs/langs/python'),
688
+ * import('@shikijs/langs/rust'),
689
+ * import('@shikijs/langs/go'),
690
+ * ]
691
+ * }))
692
+ *
693
+ * // 方式 2:传入整个语言包
694
+ * app.use(createHighlighterPlugin({
695
+ * langs: import('@shikijs/langs')
696
+ * }))
697
+ * ```
698
+ */
699
+ export declare function createHighlighterPlugin(options?: HighlighterPluginOptions): Plugin_2;
700
+
676
701
  declare const _default: __VLS_WithTemplateSlots_4<typeof __VLS_component_4, __VLS_TemplateResult_4["slots"]>;
677
702
  export { _default as ListItem }
678
703
  export { _default as li }
@@ -701,6 +726,11 @@ export { _default_6 as mark }
701
726
 
702
727
  export declare const Divider: __VLS_WithTemplateSlots_20<typeof __VLS_component_20, __VLS_TemplateResult_20["slots"]>;
703
728
 
729
+ /**
730
+ * 确保 highlighter 已初始化
731
+ */
732
+ declare function ensureReady(): Promise<void>;
733
+
704
734
  /**
705
735
  * 从 VNode 中提取语言标识(用于代码块)
706
736
  */
@@ -764,8 +794,17 @@ declare function hide(): void;
764
794
 
765
795
  /**
766
796
  * 高亮代码
797
+ *
798
+ * @param code - 源代码
799
+ * @param lang - 语言标识
800
+ * @param theme - 主题名称,'light' | 'dark',默认 'light'
767
801
  */
768
- export declare function highlightCode(code: string, lang: string): Promise<string>;
802
+ export declare function highlightCode(code: string, lang: string, theme?: 'light' | 'dark'): Promise<string>;
803
+
804
+ export declare interface HighlighterPluginOptions {
805
+ /** 需要预加载的语言包 */
806
+ langs?: LangInput;
807
+ }
769
808
 
770
809
  export declare const Icon: DefineComponent<__VLS_Props_14, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_14> & Readonly<{}>, {
771
810
  size: number;
@@ -821,6 +860,13 @@ export declare const ImagePreview: DefineComponent<__VLS_Props_11, {}, {}, {}, {
821
860
 
822
861
  export declare const img: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLElement>;
823
862
 
863
+ declare const isLoading: Ref<boolean, boolean>;
864
+
865
+ declare const isReady: Ref<boolean, boolean>;
866
+
867
+ /** 支持的语言包输入类型 */
868
+ export declare type LangInput = Promise<any>[] | Promise<any>;
869
+
824
870
  /**
825
871
  * 语言别名映射表
826
872
  */
@@ -828,6 +874,40 @@ export declare const LANGUAGE_ALIASES: Record<string, string>;
828
874
 
829
875
  export declare const List: __VLS_WithTemplateSlots_13<typeof __VLS_component_13, __VLS_TemplateResult_13["slots"]>;
830
876
 
877
+ declare const loadedLangs: Ref<string[], string[]>;
878
+
879
+ /**
880
+ * 加载额外语言
881
+ *
882
+ * @param langs - 支持单个 Promise、Promise 数组、或整个语言包
883
+ */
884
+ declare function loadLangs(langs: LangInput): Promise<void>;
885
+
886
+ /**
887
+ * 动态加载额外语言
888
+ *
889
+ * @param langs - 语言包输入,支持以下格式:
890
+ * - 单个语言 Promise:`import('@shikijs/langs/python')`
891
+ * - 语言 Promise 数组:`[import('@shikijs/langs/python'), import('@shikijs/langs/rust')]`
892
+ * - 语言包 Promise:`import('@shikijs/langs')` — 自动解析包内所有语言
893
+ *
894
+ * @example
895
+ * ```ts
896
+ * // 方式1:传入单个语言
897
+ * await loadLanguages(import('@shikijs/langs/python'))
898
+ *
899
+ * // 方式2:传入多个语言
900
+ * await loadLanguages([
901
+ * import('@shikijs/langs/python'),
902
+ * import('@shikijs/langs/rust'),
903
+ * ])
904
+ *
905
+ * // 方式3:传入整个语言包(会自动解析所有语言)
906
+ * await loadLanguages(import('@shikijs/langs'))
907
+ * ```
908
+ */
909
+ export declare function loadLanguages(langs: LangInput): Promise<void>;
910
+
831
911
  export declare const MarkdownRender: DefineComponent<MarkdownRenderProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
832
912
  error: (error: Error) => any;
833
913
  rendered: () => any;
@@ -843,7 +923,7 @@ export declare const MarkdownRender: DefineComponent<MarkdownRenderProps, {}, {}
843
923
  }>, {
844
924
  format: "md" | "mdx";
845
925
  theme: "light" | "dark";
846
- components: MDXComponents;
926
+ components: MDXProps["components"];
847
927
  raw: string;
848
928
  remarkGfm: boolean;
849
929
  prefix: string;
@@ -853,6 +933,7 @@ export declare const MarkdownRender: DefineComponent<MarkdownRenderProps, {}, {}
853
933
  tocMode: "sidebar" | "embedded";
854
934
  showBackTop: boolean;
855
935
  backTopThreshold: number;
936
+ extraLangs: LangInput;
856
937
  }, {}, {}, {}, string, ComponentProvideOptions, false, {
857
938
  wrapperRef: HTMLDivElement;
858
939
  contentRef: HTMLDivElement;
@@ -899,6 +980,13 @@ export declare interface MarkdownRenderProps {
899
980
  showBackTop?: boolean;
900
981
  /** 回到顶部按钮显示阈值(滚动距离) */
901
982
  backTopThreshold?: number;
983
+ /**
984
+ * 额外语言包,支持以下格式:
985
+ * - 单个语言:import('@shikijs/langs/python')
986
+ * - 语言数组:[import('@shikijs/langs/python'), import('@shikijs/langs/rust')]
987
+ * - 语言包(bundled):import('@shikijs/langs') — 自动解析包内所有语言
988
+ */
989
+ extraLangs?: LangInput;
902
990
  }
903
991
 
904
992
  /**
@@ -937,6 +1025,9 @@ declare interface Props {
937
1025
  */
938
1026
  export declare function provideHeadingCollapse(): HeadingCollapseState;
939
1027
 
1028
+ /** 刷新已加载语言列表 */
1029
+ declare function refreshLoadedLangs(): Promise<void>;
1030
+
940
1031
  declare function show(msg: string, toastType?: ToastType_2, duration?: number): void;
941
1032
 
942
1033
  export declare const Skeleton: DefineComponent<__VLS_Props_9, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_9> & Readonly<{}>, {
@@ -1036,6 +1127,36 @@ export declare const ul: DefineComponent<{}, () => VNode<RendererNode, RendererE
1036
1127
  */
1037
1128
  export declare function useHeadingCollapse(): HeadingCollapseState | null;
1038
1129
 
1130
+ /**
1131
+ * Composable:在组件内使用 highlighter
1132
+ *
1133
+ * @example
1134
+ * ```ts
1135
+ * const { loadLangs, loadedLangs, isReady } = useHighlighter()
1136
+ *
1137
+ * onMounted(async () => {
1138
+ * await loadLangs(import('@shikijs/langs/go'))
1139
+ * console.log('已加载:', loadedLangs.value)
1140
+ * })
1141
+ * ```
1142
+ */
1143
+ export declare function useHighlighter(): UseHighlighterReturn;
1144
+
1145
+ export declare interface UseHighlighterReturn {
1146
+ /** highlighter 是否已初始化 */
1147
+ isReady: typeof isReady;
1148
+ /** 当前已加载的语言列表 */
1149
+ loadedLangs: typeof loadedLangs;
1150
+ /** 是否正在加载语言 */
1151
+ isLoading: typeof isLoading;
1152
+ /** 加载额外语言 */
1153
+ loadLangs: typeof loadLangs;
1154
+ /** 确保 highlighter 已初始化 */
1155
+ ensureReady: typeof ensureReady;
1156
+ /** 刷新已加载语言列表 */
1157
+ refreshLoadedLangs: typeof refreshLoadedLangs;
1158
+ }
1159
+
1039
1160
  /**
1040
1161
  * Vue 插件安装方法,支持 app.use() 方式全局注册
1041
1162
  */