@incremark/vue 0.2.6 → 0.3.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/README.en.md +206 -56
- package/dist/components/ConfigProvider.vue.d.ts +19 -0
- package/dist/components/Incremark.vue.d.ts +4 -12
- package/dist/components/IncremarkCode.vue.d.ts +7 -4
- package/dist/components/IncremarkCodeDefault.vue.d.ts +16 -0
- package/dist/components/IncremarkCodeMermaid.vue.d.ts +10 -0
- package/dist/components/IncremarkContent.vue.d.ts +3 -0
- package/dist/components/SvgIcon.vue.d.ts +13 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/useIncremark.d.ts +3 -3
- package/dist/composables/useLocale.d.ts +21 -0
- package/dist/composables/useShiki.d.ts +66 -0
- package/dist/composables/useStreamRenderer.d.ts +7 -11
- package/dist/composables/useTypewriter.d.ts +3 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1014 -553
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/package.json +13 -7
package/README.en.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
# @incremark/vue
|
|
2
2
|
|
|
3
|
-
Vue 3 integration for Incremark.
|
|
3
|
+
Vue 3 integration library for Incremark, providing high-performance streaming Markdown rendering components.
|
|
4
4
|
|
|
5
5
|
**[🇨🇳 中文](./README.md)** | 🇺🇸 English
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Core Advantages
|
|
8
8
|
|
|
9
|
-
- 📦 **Out of the Box** - Provides `
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
9
|
+
- 📦 **Out of the Box** - Provides `IncremarkContent` component and `useIncremark` composable
|
|
10
|
+
- ⚡ **Extreme Performance** - Incremental parsing with O(n) complexity, dual-engine support
|
|
11
|
+
- ⌨️ **Typewriter Effect** - Built-in animation effects (fade-in, typing)
|
|
12
|
+
- 🎨 **Highly Customizable** - Custom components, code blocks, containers
|
|
13
|
+
- 🎯 **Theme System** - Built-in ThemeProvider with light/dark themes
|
|
14
|
+
- 📜 **Auto Scroll** - Built-in AutoScrollContainer component
|
|
15
|
+
- 🔧 **DevTools** - Built-in developer debugging tools
|
|
13
16
|
|
|
14
17
|
## Installation
|
|
15
18
|
|
|
@@ -19,20 +22,56 @@ pnpm add @incremark/core @incremark/vue
|
|
|
19
22
|
|
|
20
23
|
## Quick Start
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
### Recommended: IncremarkContent Component
|
|
23
26
|
|
|
24
|
-
```
|
|
27
|
+
```vue
|
|
28
|
+
<script setup>
|
|
29
|
+
import { ref } from 'vue'
|
|
30
|
+
import { IncremarkContent } from '@incremark/vue'
|
|
25
31
|
import '@incremark/vue/style.css'
|
|
32
|
+
|
|
33
|
+
const content = ref('')
|
|
34
|
+
const isFinished = ref(false)
|
|
35
|
+
|
|
36
|
+
// Handle AI streaming output
|
|
37
|
+
async function handleStream(stream) {
|
|
38
|
+
content.value = ''
|
|
39
|
+
isFinished.value = false
|
|
40
|
+
|
|
41
|
+
for await (const chunk of stream) {
|
|
42
|
+
content.value += chunk
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isFinished.value = true
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<button @click="handleStream(stream)">Start</button>
|
|
51
|
+
<IncremarkContent
|
|
52
|
+
:content="content"
|
|
53
|
+
:is-finished="isFinished"
|
|
54
|
+
:incremark-options="{
|
|
55
|
+
gfm: true,
|
|
56
|
+
math: true,
|
|
57
|
+
containers: true,
|
|
58
|
+
htmlTree: true
|
|
59
|
+
}"
|
|
60
|
+
/>
|
|
61
|
+
</template>
|
|
26
62
|
```
|
|
27
63
|
|
|
28
|
-
|
|
64
|
+
### Advanced: useIncremark Composable
|
|
29
65
|
|
|
30
66
|
```vue
|
|
31
67
|
<script setup>
|
|
32
68
|
import { useIncremark, Incremark } from '@incremark/vue'
|
|
33
69
|
import '@incremark/vue/style.css'
|
|
34
70
|
|
|
35
|
-
const { blocks, append, finalize, reset } = useIncremark({
|
|
71
|
+
const { blocks, append, finalize, reset } = useIncremark({
|
|
72
|
+
gfm: true,
|
|
73
|
+
math: true
|
|
74
|
+
})
|
|
36
75
|
|
|
37
76
|
async function handleStream(stream) {
|
|
38
77
|
reset()
|
|
@@ -44,89 +83,200 @@ async function handleStream(stream) {
|
|
|
44
83
|
</script>
|
|
45
84
|
|
|
46
85
|
<template>
|
|
47
|
-
<button @click="handleStream">Start</button>
|
|
86
|
+
<button @click="handleStream(stream)">Start</button>
|
|
48
87
|
<Incremark :blocks="blocks" />
|
|
49
88
|
</template>
|
|
50
89
|
```
|
|
51
90
|
|
|
52
|
-
##
|
|
91
|
+
## IncremarkContent Component
|
|
53
92
|
|
|
54
|
-
|
|
93
|
+
Declarative all-in-one component, recommended for most scenarios.
|
|
55
94
|
|
|
56
|
-
|
|
95
|
+
### Props
|
|
57
96
|
|
|
58
|
-
|
|
97
|
+
```ts
|
|
98
|
+
interface IncremarkContentProps {
|
|
99
|
+
// Input (choose one)
|
|
100
|
+
content?: string // Accumulated Markdown string
|
|
101
|
+
stream?: () => AsyncGenerator<string> // Async generator function
|
|
102
|
+
|
|
103
|
+
// Status
|
|
104
|
+
isFinished?: boolean // Stream finished flag (required for content mode)
|
|
105
|
+
|
|
106
|
+
// Configuration
|
|
107
|
+
incremarkOptions?: {
|
|
108
|
+
gfm?: boolean // GFM support
|
|
109
|
+
math?: boolean // Math formulas
|
|
110
|
+
htmlTree?: boolean // HTML structured parsing
|
|
111
|
+
containers?: boolean // ::: container syntax
|
|
112
|
+
typewriter?: { // Typewriter effect
|
|
113
|
+
enabled?: boolean
|
|
114
|
+
charsPerTick?: number | [number, number]
|
|
115
|
+
tickInterval?: number
|
|
116
|
+
effect?: 'none' | 'fade-in' | 'typing'
|
|
117
|
+
cursor?: string
|
|
118
|
+
}
|
|
119
|
+
}
|
|
59
120
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
| `pendingBlocks` | `ShallowRef<Block[]>` | Pending blocks |
|
|
66
|
-
| `append` | `Function` | Append content |
|
|
67
|
-
| `finalize` | `Function` | Complete parsing |
|
|
68
|
-
| `reset` | `Function` | Reset state |
|
|
69
|
-
| `render` | `Function` | Render once (reset + append + finalize) |
|
|
121
|
+
// Custom rendering
|
|
122
|
+
components?: ComponentMap // Custom components
|
|
123
|
+
customContainers?: Record<string, Component> // Custom containers
|
|
124
|
+
customCodeBlocks?: Record<string, Component> // Custom code blocks
|
|
125
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig>
|
|
70
126
|
|
|
71
|
-
|
|
127
|
+
// Styling
|
|
128
|
+
showBlockStatus?: boolean // Show block status border
|
|
129
|
+
pendingClass?: string // CSS class for pending blocks
|
|
130
|
+
}
|
|
131
|
+
```
|
|
72
132
|
|
|
73
|
-
Enable
|
|
133
|
+
### Example: Enable Typewriter Effect
|
|
74
134
|
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
|
|
135
|
+
```vue
|
|
136
|
+
<IncremarkContent
|
|
137
|
+
:content="content"
|
|
138
|
+
:is-finished="isFinished"
|
|
139
|
+
:incremark-options="{
|
|
140
|
+
gfm: true,
|
|
141
|
+
typewriter: {
|
|
142
|
+
enabled: true,
|
|
143
|
+
charsPerTick: [1, 3],
|
|
144
|
+
tickInterval: 30,
|
|
145
|
+
effect: 'fade-in'
|
|
146
|
+
}
|
|
147
|
+
}"
|
|
148
|
+
/>
|
|
78
149
|
```
|
|
79
150
|
|
|
80
|
-
###
|
|
151
|
+
### Example: Custom Components
|
|
152
|
+
|
|
153
|
+
```vue
|
|
154
|
+
<script setup>
|
|
155
|
+
import CustomHeading from './CustomHeading.vue'
|
|
156
|
+
import WarningContainer from './WarningContainer.vue'
|
|
157
|
+
import EchartsCodeBlock from './EchartsCodeBlock.vue'
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
<template>
|
|
161
|
+
<IncremarkContent
|
|
162
|
+
:content="content"
|
|
163
|
+
:is-finished="isFinished"
|
|
164
|
+
:components="{ heading: CustomHeading }"
|
|
165
|
+
:custom-containers="{ warning: WarningContainer }"
|
|
166
|
+
:custom-code-blocks="{ echarts: EchartsCodeBlock }"
|
|
167
|
+
:code-block-configs="{ echarts: { takeOver: true } }"
|
|
168
|
+
/>
|
|
169
|
+
</template>
|
|
170
|
+
```
|
|
81
171
|
|
|
82
|
-
|
|
172
|
+
## Theme System
|
|
83
173
|
|
|
84
174
|
```vue
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
175
|
+
<script setup>
|
|
176
|
+
import { ThemeProvider, IncremarkContent } from '@incremark/vue'
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<template>
|
|
180
|
+
<!-- Built-in theme -->
|
|
181
|
+
<ThemeProvider theme="dark">
|
|
182
|
+
<IncremarkContent :content="content" :is-finished="isFinished" />
|
|
183
|
+
</ThemeProvider>
|
|
184
|
+
|
|
185
|
+
<!-- Custom theme -->
|
|
186
|
+
<ThemeProvider :theme="{ color: { brand: { primary: '#8b5cf6' } } }">
|
|
187
|
+
<IncremarkContent :content="content" :is-finished="isFinished" />
|
|
188
|
+
</ThemeProvider>
|
|
189
|
+
</template>
|
|
89
190
|
```
|
|
90
191
|
|
|
91
|
-
##
|
|
192
|
+
## Auto Scroll
|
|
92
193
|
|
|
93
194
|
```vue
|
|
94
195
|
<script setup>
|
|
95
|
-
import {
|
|
96
|
-
import
|
|
196
|
+
import { ref } from 'vue'
|
|
197
|
+
import { AutoScrollContainer, IncremarkContent } from '@incremark/vue'
|
|
97
198
|
|
|
98
|
-
const
|
|
199
|
+
const scrollRef = ref()
|
|
200
|
+
const autoScrollEnabled = ref(true)
|
|
99
201
|
</script>
|
|
100
202
|
|
|
101
203
|
<template>
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
:
|
|
105
|
-
|
|
204
|
+
<AutoScrollContainer
|
|
205
|
+
ref="scrollRef"
|
|
206
|
+
:enabled="autoScrollEnabled"
|
|
207
|
+
:threshold="50"
|
|
208
|
+
behavior="smooth"
|
|
209
|
+
>
|
|
210
|
+
<IncremarkContent :content="content" :is-finished="isFinished" />
|
|
211
|
+
</AutoScrollContainer>
|
|
212
|
+
|
|
213
|
+
<button @click="scrollRef?.scrollToBottom()">
|
|
214
|
+
Scroll to Bottom
|
|
215
|
+
</button>
|
|
106
216
|
</template>
|
|
107
217
|
```
|
|
108
218
|
|
|
109
|
-
##
|
|
219
|
+
## useIncremark API
|
|
110
220
|
|
|
111
|
-
```
|
|
112
|
-
|
|
221
|
+
```ts
|
|
222
|
+
const {
|
|
223
|
+
// State
|
|
224
|
+
markdown, // Ref<string> - Complete Markdown
|
|
225
|
+
blocks, // ComputedRef<Block[]> - All blocks
|
|
226
|
+
completedBlocks, // ShallowRef<Block[]> - Completed blocks
|
|
227
|
+
pendingBlocks, // ShallowRef<Block[]> - Pending blocks
|
|
228
|
+
isLoading, // Ref<boolean> - Is loading
|
|
229
|
+
isDisplayComplete, // ComputedRef<boolean> - Is display complete
|
|
230
|
+
|
|
231
|
+
// Methods
|
|
232
|
+
append, // (chunk: string) => IncrementalUpdate
|
|
233
|
+
finalize, // () => IncrementalUpdate
|
|
234
|
+
reset, // () => void
|
|
235
|
+
render, // (content: string) => IncrementalUpdate
|
|
236
|
+
|
|
237
|
+
// Typewriter controls
|
|
238
|
+
typewriter: {
|
|
239
|
+
enabled, // Ref<boolean> - Is enabled
|
|
240
|
+
isProcessing, // Ref<boolean> - Is processing
|
|
241
|
+
skip, // () => void - Skip animation
|
|
242
|
+
setOptions // (options) => void - Update config
|
|
243
|
+
}
|
|
244
|
+
} = useIncremark(options)
|
|
113
245
|
```
|
|
114
246
|
|
|
247
|
+
## DevTools
|
|
248
|
+
|
|
115
249
|
```vue
|
|
116
250
|
<script setup>
|
|
117
|
-
import { useIncremark } from '@incremark/vue'
|
|
118
|
-
import { math } from 'micromark-extension-math'
|
|
119
|
-
import { mathFromMarkdown } from 'mdast-util-math'
|
|
120
|
-
import 'katex/dist/katex.min.css'
|
|
251
|
+
import { useIncremark, useDevTools, Incremark } from '@incremark/vue'
|
|
121
252
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
mdastExtensions: [mathFromMarkdown()]
|
|
125
|
-
})
|
|
253
|
+
const incremark = useIncremark()
|
|
254
|
+
useDevTools(incremark)
|
|
126
255
|
</script>
|
|
256
|
+
|
|
257
|
+
<template>
|
|
258
|
+
<Incremark :blocks="incremark.blocks" />
|
|
259
|
+
</template>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Math Formula Support
|
|
263
|
+
|
|
264
|
+
Built-in support, just enable `math: true`:
|
|
265
|
+
|
|
266
|
+
```vue
|
|
267
|
+
<IncremarkContent
|
|
268
|
+
:content="content"
|
|
269
|
+
:is-finished="isFinished"
|
|
270
|
+
:incremark-options="{ math: true }"
|
|
271
|
+
/>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Import KaTeX styles:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import 'katex/dist/katex.min.css'
|
|
127
278
|
```
|
|
128
279
|
|
|
129
280
|
## License
|
|
130
281
|
|
|
131
282
|
MIT
|
|
132
|
-
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IncremarkLocale } from '@incremark/shared';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** locale 对象 */
|
|
4
|
+
locale?: IncremarkLocale;
|
|
5
|
+
}
|
|
6
|
+
declare var __VLS_1: {};
|
|
7
|
+
type __VLS_Slots = {} & {
|
|
8
|
+
default?: (props: typeof __VLS_1) => any;
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_component: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
11
|
+
locale: IncremarkLocale;
|
|
12
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
14
|
+
export default _default;
|
|
15
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
16
|
+
new (): {
|
|
17
|
+
$slots: S;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -2,17 +2,9 @@ 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;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 代码块配置
|
|
11
|
-
*/
|
|
12
|
-
export interface CodeBlockConfig {
|
|
13
|
-
/** 是否从一开始就接管渲染,而不是等到 completed 状态 */
|
|
14
|
-
takeOver?: boolean;
|
|
15
|
-
}
|
|
7
|
+
};
|
|
16
8
|
/**
|
|
17
9
|
* 代码块配置
|
|
18
10
|
*/
|
|
@@ -22,7 +14,7 @@ export interface CodeBlockConfig {
|
|
|
22
14
|
}
|
|
23
15
|
type __VLS_Props = {
|
|
24
16
|
/** 要渲染的块列表(来自 useIncremark 的 blocks) */
|
|
25
|
-
blocks?:
|
|
17
|
+
blocks?: RenderableBlock[];
|
|
26
18
|
/** 内容是否完全显示完成(用于控制脚注等需要在内容完全显示后才出现的元素)
|
|
27
19
|
* 如果传入了 incremark,则会自动使用 incremark.isDisplayComplete,此 prop 被忽略 */
|
|
28
20
|
isDisplayComplete?: boolean;
|
|
@@ -44,7 +36,7 @@ type __VLS_Props = {
|
|
|
44
36
|
incremark?: UseIncremarkReturn;
|
|
45
37
|
};
|
|
46
38
|
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
47
|
-
blocks:
|
|
39
|
+
blocks: RenderableBlock[];
|
|
48
40
|
isDisplayComplete: boolean;
|
|
49
41
|
customCodeBlocks: Record<string, Component>;
|
|
50
42
|
codeBlockConfigs: Record<string, CodeBlockConfig>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Code } from 'mdast';
|
|
2
2
|
import type { Component } from 'vue';
|
|
3
3
|
import type { CodeBlockConfig } from './Incremark.vue';
|
|
4
|
-
|
|
4
|
+
interface Props {
|
|
5
5
|
node: Code;
|
|
6
6
|
/** Shiki 主题,默认 github-dark */
|
|
7
7
|
theme?: string;
|
|
@@ -17,14 +17,17 @@ type __VLS_Props = {
|
|
|
17
17
|
codeBlockConfigs?: Record<string, CodeBlockConfig>;
|
|
18
18
|
/** 块状态,用于判断是否使用自定义组件 */
|
|
19
19
|
blockStatus?: 'pending' | 'stable' | 'completed';
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** 默认代码块渲染组件(当不是 mermaid 且没有自定义组件时使用) */
|
|
21
|
+
defaultCodeComponent?: Component;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
22
24
|
theme: string;
|
|
25
|
+
mermaidDelay: number;
|
|
23
26
|
fallbackTheme: string;
|
|
24
27
|
disableHighlight: boolean;
|
|
25
|
-
mermaidDelay: number;
|
|
26
28
|
customCodeBlocks: Record<string, Component>;
|
|
27
29
|
codeBlockConfigs: Record<string, CodeBlockConfig>;
|
|
28
30
|
blockStatus: "pending" | "stable" | "completed";
|
|
31
|
+
defaultCodeComponent: Component;
|
|
29
32
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
30
33
|
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Code } from 'mdast';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: Code;
|
|
4
|
+
/** Shiki 主题,默认 github-dark */
|
|
5
|
+
theme?: string;
|
|
6
|
+
/** 默认回退主题(当指定主题加载失败时使用),默认 github-dark */
|
|
7
|
+
fallbackTheme?: string;
|
|
8
|
+
/** 是否禁用代码高亮 */
|
|
9
|
+
disableHighlight?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
12
|
+
theme: string;
|
|
13
|
+
fallbackTheme: string;
|
|
14
|
+
disableHighlight: boolean;
|
|
15
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Code } from 'mdast';
|
|
2
|
+
interface Props {
|
|
3
|
+
node: Code;
|
|
4
|
+
/** Mermaid 渲染延迟(毫秒),用于流式输入时防抖 */
|
|
5
|
+
mermaidDelay?: number;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
8
|
+
mermaidDelay: number;
|
|
9
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SvgIcon 组件
|
|
3
|
+
*
|
|
4
|
+
* 直接渲染 SVG 字符串
|
|
5
|
+
*/
|
|
6
|
+
interface Props {
|
|
7
|
+
/** SVG 字符串内容 */
|
|
8
|
+
svg: string;
|
|
9
|
+
/** 图标大小 class,如 incremark-icon--sm, incremark-icon--md 等 */
|
|
10
|
+
sizeClass?: string;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
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';
|
|
@@ -6,3 +6,4 @@ export { useDevTools } from './useDevTools';
|
|
|
6
6
|
export type { UseDevToolsOptions } from './useDevTools';
|
|
7
7
|
export { useBlockTransformer } from './useBlockTransformer';
|
|
8
8
|
export type { UseBlockTransformerOptions, UseBlockTransformerReturn } from './useBlockTransformer';
|
|
9
|
+
export { useLocale, type UseLocaleReturn } from './useLocale';
|
|
@@ -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,21 @@
|
|
|
1
|
+
import { type Ref, type ComputedRef, type InjectionKey } from 'vue';
|
|
2
|
+
import type { IncremarkLocale } from '@incremark/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Locale 注入 key,用于 provide/inject
|
|
5
|
+
*/
|
|
6
|
+
declare const LOCALE_KEY: InjectionKey<Ref<IncremarkLocale>>;
|
|
7
|
+
/**
|
|
8
|
+
* Vue 国际化 Hook
|
|
9
|
+
*/
|
|
10
|
+
export interface UseLocaleReturn {
|
|
11
|
+
/** 翻译函数 */
|
|
12
|
+
t: ComputedRef<(key: string) => string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 使用 locale
|
|
16
|
+
*/
|
|
17
|
+
export declare function useLocale(): UseLocaleReturn;
|
|
18
|
+
/**
|
|
19
|
+
* 提供 locale 的 key(用于 ConfigProvider)
|
|
20
|
+
*/
|
|
21
|
+
export { LOCALE_KEY };
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
/**
|
|
51
|
+
* 获取 ShikiManager 单例(延迟初始化)
|
|
52
|
+
* 避免模块加载时立即创建实例,支持 SSR
|
|
53
|
+
*/
|
|
54
|
+
declare function getShikiManager(): ShikiManager;
|
|
55
|
+
export { getShikiManager, ShikiManager };
|
|
56
|
+
/**
|
|
57
|
+
* 使用 Shiki Highlighter(组合式函数)
|
|
58
|
+
*
|
|
59
|
+
* @param theme 主题名称
|
|
60
|
+
* @returns Shiki 相关的响应式状态和方法
|
|
61
|
+
*/
|
|
62
|
+
export declare function useShiki(theme: string): {
|
|
63
|
+
highlighterInfo: import("vue").ShallowRef<HighlighterInfo | null, HighlighterInfo | null>;
|
|
64
|
+
isHighlighting: import("vue").ShallowRef<boolean, boolean>;
|
|
65
|
+
highlight: (code: string, lang: string, fallbackTheme: string) => Promise<string>;
|
|
66
|
+
};
|
|
@@ -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;
|