@incremark/vue 0.2.5 → 0.2.7
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/components/Incremark.vue.d.ts +24 -4
- package/dist/components/IncremarkCode.vue.d.ts +7 -0
- package/dist/components/IncremarkContent.vue.d.ts +3 -0
- package/dist/components/IncremarkRenderer.vue.d.ts +3 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/composables/useIncremark.d.ts +3 -3
- package/dist/composables/useShiki.d.ts +62 -0
- package/dist/composables/useStreamRenderer.d.ts +7 -11
- package/dist/composables/useTypewriter.d.ts +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +463 -304
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/package.json +5 -5
|
@@ -2,19 +2,37 @@ import { type Component } from 'vue';
|
|
|
2
2
|
import type { ParsedBlock } from '@incremark/core';
|
|
3
3
|
import type { UseIncremarkReturn } from '../composables/useIncremark';
|
|
4
4
|
export type ComponentMap = Partial<Record<string, Component>>;
|
|
5
|
-
export
|
|
6
|
-
stableId: string;
|
|
5
|
+
export type RenderableBlock = ParsedBlock & {
|
|
7
6
|
isLastPending?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 代码块配置
|
|
10
|
+
*/
|
|
11
|
+
export interface CodeBlockConfig {
|
|
12
|
+
/** 是否从一开始就接管渲染,而不是等到 completed 状态 */
|
|
13
|
+
takeOver?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 代码块配置
|
|
17
|
+
*/
|
|
18
|
+
export interface CodeBlockConfig {
|
|
19
|
+
/** 是否从一开始就接管渲染,而不是等到 completed 状态 */
|
|
20
|
+
takeOver?: boolean;
|
|
8
21
|
}
|
|
9
22
|
type __VLS_Props = {
|
|
10
23
|
/** 要渲染的块列表(来自 useIncremark 的 blocks) */
|
|
11
|
-
blocks?:
|
|
24
|
+
blocks?: RenderableBlock[];
|
|
25
|
+
/** 内容是否完全显示完成(用于控制脚注等需要在内容完全显示后才出现的元素)
|
|
26
|
+
* 如果传入了 incremark,则会自动使用 incremark.isDisplayComplete,此 prop 被忽略 */
|
|
27
|
+
isDisplayComplete?: boolean;
|
|
12
28
|
/** 自定义组件映射,key 为节点类型 */
|
|
13
29
|
components?: ComponentMap;
|
|
14
30
|
/** 自定义容器组件映射,key 为容器名称(如 'warning', 'info') */
|
|
15
31
|
customContainers?: Record<string, Component>;
|
|
16
32
|
/** 自定义代码块组件映射,key 为代码语言名称(如 'echart', 'mermaid') */
|
|
17
33
|
customCodeBlocks?: Record<string, Component>;
|
|
34
|
+
/** 代码块配置映射,key 为代码语言名称 */
|
|
35
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig>;
|
|
18
36
|
/** 待处理块的样式类名 */
|
|
19
37
|
pendingClass?: string;
|
|
20
38
|
/** 已完成块的样式类名 */
|
|
@@ -25,8 +43,10 @@ type __VLS_Props = {
|
|
|
25
43
|
incremark?: UseIncremarkReturn;
|
|
26
44
|
};
|
|
27
45
|
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
28
|
-
blocks:
|
|
46
|
+
blocks: RenderableBlock[];
|
|
47
|
+
isDisplayComplete: boolean;
|
|
29
48
|
customCodeBlocks: Record<string, Component>;
|
|
49
|
+
codeBlockConfigs: Record<string, CodeBlockConfig>;
|
|
30
50
|
customContainers: Record<string, Component>;
|
|
31
51
|
components: Partial<Record<string, Component>>;
|
|
32
52
|
pendingClass: string;
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import type { Code } from 'mdast';
|
|
2
2
|
import type { Component } from 'vue';
|
|
3
|
+
import type { CodeBlockConfig } from './Incremark.vue';
|
|
3
4
|
type __VLS_Props = {
|
|
4
5
|
node: Code;
|
|
5
6
|
/** Shiki 主题,默认 github-dark */
|
|
6
7
|
theme?: string;
|
|
8
|
+
/** 默认回退主题(当指定主题加载失败时使用),默认 github-dark */
|
|
9
|
+
fallbackTheme?: string;
|
|
7
10
|
/** 是否禁用代码高亮 */
|
|
8
11
|
disableHighlight?: boolean;
|
|
9
12
|
/** Mermaid 渲染延迟(毫秒),用于流式输入时防抖 */
|
|
10
13
|
mermaidDelay?: number;
|
|
11
14
|
/** 自定义代码块组件映射,key 为代码语言名称 */
|
|
12
15
|
customCodeBlocks?: Record<string, Component>;
|
|
16
|
+
/** 代码块配置映射,key 为代码语言名称 */
|
|
17
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig>;
|
|
13
18
|
/** 块状态,用于判断是否使用自定义组件 */
|
|
14
19
|
blockStatus?: 'pending' | 'stable' | 'completed';
|
|
15
20
|
};
|
|
16
21
|
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
17
22
|
theme: string;
|
|
23
|
+
fallbackTheme: string;
|
|
18
24
|
disableHighlight: boolean;
|
|
19
25
|
mermaidDelay: number;
|
|
20
26
|
customCodeBlocks: Record<string, Component>;
|
|
27
|
+
codeBlockConfigs: Record<string, CodeBlockConfig>;
|
|
21
28
|
blockStatus: "pending" | "stable" | "completed";
|
|
22
29
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
23
30
|
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IncremarkContentProps } from '../types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<IncremarkContentProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<IncremarkContentProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
3
|
+
export default _default;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { RootContent } from 'mdast';
|
|
2
2
|
import type { Component } from 'vue';
|
|
3
3
|
import type { ContainerNode } from './IncremarkContainer.vue';
|
|
4
|
+
import type { CodeBlockConfig } from './Incremark.vue';
|
|
4
5
|
type ExtendedRootContent = RootContent | ContainerNode;
|
|
5
6
|
type __VLS_Props = {
|
|
6
7
|
node: ExtendedRootContent;
|
|
7
8
|
customContainers?: Record<string, Component>;
|
|
8
9
|
customCodeBlocks?: Record<string, Component>;
|
|
10
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig>;
|
|
9
11
|
blockStatus?: 'pending' | 'stable' | 'completed';
|
|
12
|
+
components?: Partial<Record<string, Component>>;
|
|
10
13
|
};
|
|
11
14
|
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
15
|
export default _default;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export type { IncremarkContentProps } from '../types';
|
|
1
2
|
export { default as Incremark } from './Incremark.vue';
|
|
2
|
-
export
|
|
3
|
+
export { default as IncremarkContent } from '../components/IncremarkContent.vue';
|
|
4
|
+
export type { ComponentMap, RenderableBlock } from './Incremark.vue';
|
|
3
5
|
export { default as IncremarkRenderer } from './IncremarkRenderer.vue';
|
|
4
6
|
export { default as IncremarkHeading } from './IncremarkHeading.vue';
|
|
5
7
|
export { default as IncremarkParagraph } from './IncremarkParagraph.vue';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ComputedRef } from 'vue';
|
|
1
|
+
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import { type ParserOptions, type ParsedBlock, type IncrementalUpdate, type Root, type TransformerPlugin, type AnimationEffect } from '@incremark/core';
|
|
3
3
|
/** 打字机效果配置 */
|
|
4
4
|
export interface TypewriterOptions {
|
|
@@ -76,7 +76,7 @@ export type UseIncremarkReturn = ReturnType<typeof useIncremark>;
|
|
|
76
76
|
* </template>
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
|
-
export declare function useIncremark(
|
|
79
|
+
export declare function useIncremark(optionsInput?: MaybeRefOrGetter<UseIncremarkOptions>): {
|
|
80
80
|
/** 已收集的完整 Markdown 字符串 */
|
|
81
81
|
markdown: import("vue").Ref<string, string>;
|
|
82
82
|
/** 已完成的块列表 */
|
|
@@ -87,7 +87,7 @@ export declare function useIncremark(options?: UseIncremarkOptions): {
|
|
|
87
87
|
ast: ComputedRef<Root>;
|
|
88
88
|
/** 用于渲染的 blocks(根据打字机设置自动处理) */
|
|
89
89
|
blocks: ComputedRef<(ParsedBlock & {
|
|
90
|
-
|
|
90
|
+
isLastPending?: boolean;
|
|
91
91
|
})[]>;
|
|
92
92
|
/** 是否正在加载 */
|
|
93
93
|
isLoading: import("vue").Ref<boolean, boolean>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shiki Highlighter 单例管理器
|
|
3
|
+
*
|
|
4
|
+
* 避免重复创建 Shiki 实例,所有组件共享同一个 highlighter
|
|
5
|
+
*/
|
|
6
|
+
import type { HighlighterGeneric, BundledLanguage, BundledTheme } from 'shiki';
|
|
7
|
+
interface HighlighterInfo {
|
|
8
|
+
highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
9
|
+
loadedLanguages: Set<BundledLanguage>;
|
|
10
|
+
loadedThemes: Set<BundledTheme>;
|
|
11
|
+
}
|
|
12
|
+
/** Shiki highlighter 单例管理器 */
|
|
13
|
+
declare class ShikiManager {
|
|
14
|
+
private static instance;
|
|
15
|
+
/** 存储 highlighter 实例,key 为主题名称 */
|
|
16
|
+
private highlighters;
|
|
17
|
+
private constructor();
|
|
18
|
+
static getInstance(): ShikiManager;
|
|
19
|
+
/**
|
|
20
|
+
* 获取或创建 highlighter
|
|
21
|
+
* @param theme 主题名称
|
|
22
|
+
* @returns highlighter 实例
|
|
23
|
+
*/
|
|
24
|
+
getHighlighter(theme: BundledTheme): Promise<HighlighterInfo>;
|
|
25
|
+
/**
|
|
26
|
+
* 加载语言(按需)
|
|
27
|
+
* @param theme 主题名称
|
|
28
|
+
* @param lang 语言名称
|
|
29
|
+
*/
|
|
30
|
+
loadLanguage(theme: BundledTheme, lang: BundledLanguage): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 加载主题(按需)
|
|
33
|
+
* @param theme 主题名称
|
|
34
|
+
*/
|
|
35
|
+
loadTheme(theme: BundledTheme): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 高亮代码
|
|
38
|
+
* @param theme 主题名称
|
|
39
|
+
* @param code 代码内容
|
|
40
|
+
* @param lang 语言名称
|
|
41
|
+
* @param fallbackTheme 回退主题
|
|
42
|
+
* @returns 高亮后的 HTML
|
|
43
|
+
*/
|
|
44
|
+
codeToHtml(theme: BundledTheme, code: string, lang: BundledLanguage, fallbackTheme: BundledTheme): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* 清理所有 highlighter(应用退出或需要重置时调用)
|
|
47
|
+
*/
|
|
48
|
+
disposeAll(): void;
|
|
49
|
+
}
|
|
50
|
+
declare const shikiManager: ShikiManager;
|
|
51
|
+
export { shikiManager, ShikiManager };
|
|
52
|
+
/**
|
|
53
|
+
* 使用 Shiki Highlighter(组合式函数)
|
|
54
|
+
*
|
|
55
|
+
* @param theme 主题名称
|
|
56
|
+
* @returns Shiki 相关的响应式状态和方法
|
|
57
|
+
*/
|
|
58
|
+
export declare function useShiki(theme: string): {
|
|
59
|
+
highlighterInfo: import("vue").ShallowRef<HighlighterInfo | null, HighlighterInfo | null>;
|
|
60
|
+
isHighlighting: import("vue").ShallowRef<boolean, boolean>;
|
|
61
|
+
highlight: (code: string, lang: string, fallbackTheme: string) => Promise<string>;
|
|
62
|
+
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Ref, type ComputedRef } from 'vue';
|
|
2
2
|
import type { ParsedBlock } from '@incremark/core';
|
|
3
|
-
export interface BlockWithStableId extends ParsedBlock {
|
|
4
|
-
/** 稳定的渲染 ID(用于 Vue key) */
|
|
5
|
-
stableId: string;
|
|
6
|
-
}
|
|
7
3
|
export interface UseStreamRendererOptions {
|
|
8
4
|
/** 已完成的块 */
|
|
9
5
|
completedBlocks: Ref<ParsedBlock[]>;
|
|
@@ -11,16 +7,16 @@ export interface UseStreamRendererOptions {
|
|
|
11
7
|
pendingBlocks: Ref<ParsedBlock[]>;
|
|
12
8
|
}
|
|
13
9
|
export interface UseStreamRendererReturn {
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
10
|
+
/** 已完成的块 */
|
|
11
|
+
completedBlocks: ComputedRef<ParsedBlock[]>;
|
|
12
|
+
/** 待处理的块 */
|
|
13
|
+
pendingBlocks: ComputedRef<ParsedBlock[]>;
|
|
14
|
+
/** 所有块 */
|
|
15
|
+
allBlocks: ComputedRef<ParsedBlock[]>;
|
|
20
16
|
}
|
|
21
17
|
/**
|
|
22
18
|
* Vue 3 Composable: 流式渲染辅助
|
|
23
19
|
*
|
|
24
|
-
*
|
|
20
|
+
* 直接使用 block.id 作为稳定的渲染 key
|
|
25
21
|
*/
|
|
26
22
|
export declare function useStreamRenderer(options: UseStreamRendererOptions): UseStreamRendererReturn;
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
* @author Incremark Team
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
|
-
import { type Ref, type ComputedRef } from 'vue';
|
|
10
|
+
import { type Ref, type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
11
11
|
import { type RootContent, type ParsedBlock, type BlockTransformer } from '@incremark/core';
|
|
12
12
|
import type { TypewriterOptions, TypewriterControls } from './useIncremark';
|
|
13
13
|
export interface UseTypewriterOptions {
|
|
14
|
-
typewriter
|
|
14
|
+
typewriter: MaybeRefOrGetter<TypewriterOptions | undefined>;
|
|
15
15
|
completedBlocks: Ref<ParsedBlock[]>;
|
|
16
16
|
pendingBlocks: Ref<ParsedBlock[]>;
|
|
17
17
|
}
|
|
18
18
|
export interface UseTypewriterReturn {
|
|
19
19
|
/** 用于渲染的 blocks(经过打字机处理或原始blocks) */
|
|
20
20
|
blocks: ComputedRef<Array<ParsedBlock & {
|
|
21
|
-
|
|
21
|
+
isLastPending?: boolean;
|
|
22
22
|
}>>;
|
|
23
23
|
/** 打字机控制对象 */
|
|
24
24
|
typewriter: TypewriterControls;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ export { useIncremark, useStreamRenderer, useDevTools, useBlockTransformer } fro
|
|
|
2
2
|
export { useProvideDefinations } from './composables/useProvideDefinations';
|
|
3
3
|
export { useDefinationsContext } from './composables/useDefinationsContext';
|
|
4
4
|
export type { UseIncremarkOptions, TypewriterOptions, TypewriterControls, UseStreamRendererOptions, UseDevToolsOptions, UseBlockTransformerOptions, UseBlockTransformerReturn } from './composables';
|
|
5
|
-
export
|
|
6
|
-
export type { ComponentMap, BlockWithStableId } from './components';
|
|
5
|
+
export * from './components';
|
|
7
6
|
export { default as ThemeProvider } from './ThemeProvider.vue';
|
|
8
7
|
export type { ParsedBlock, IncrementalUpdate, ParserOptions, BlockStatus, Root, RootContent, SourceBlock, DisplayBlock, TransformerPlugin, TransformerOptions, TransformerState, AnimationEffect } from '@incremark/core';
|
|
9
8
|
export { BlockTransformer, createBlockTransformer, countChars, sliceAst, cloneNode, codeBlockPlugin, mermaidPlugin, imagePlugin, mathPlugin, thematicBreakPlugin, defaultPlugins, allPlugins, createPlugin } from '@incremark/core';
|