@incremark/core 0.3.1 → 0.3.3
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 +68 -3
- package/README.md +68 -8
- package/dist/{MarkedAstBuildter-DDP1An5M.d.ts → MarkedAstBuildter-B2QhLKKy.d.ts} +2 -2
- package/dist/engines/marked/index.d.ts +4 -4
- package/dist/engines/marked/index.js +1 -1
- package/dist/engines/marked/index.js.map +1 -1
- package/dist/engines/micromark/index.d.ts +4 -4
- package/dist/engines/micromark/index.js +2 -2
- package/dist/engines/micromark/index.js.map +1 -1
- package/dist/index.d.ts +33 -6
- package/dist/index.js +151 -16
- package/dist/index.js.map +1 -1
- package/dist/{types-N1b99kYB.d.ts → types-B7GTGJc2.d.ts} +2 -1
- package/dist/utils/index.d.ts +8 -1
- package/dist/utils/index.js +15 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -129,11 +129,76 @@ Get completed blocks.
|
|
|
129
129
|
|
|
130
130
|
Get current buffer content.
|
|
131
131
|
|
|
132
|
-
##
|
|
132
|
+
## Framework Integration
|
|
133
|
+
|
|
134
|
+
For daily use, it's recommended to use the framework packages which have built-in incremental parsing and typewriter effect support:
|
|
135
|
+
|
|
136
|
+
```vue
|
|
137
|
+
<!-- Vue -->
|
|
138
|
+
<script setup>
|
|
139
|
+
import { ref } from 'vue'
|
|
140
|
+
import { IncremarkContent } from '@incremark/vue'
|
|
141
|
+
|
|
142
|
+
const content = ref('')
|
|
143
|
+
const isFinished = ref(false)
|
|
144
|
+
|
|
145
|
+
async function simulateStream() {
|
|
146
|
+
content.value = ''
|
|
147
|
+
isFinished.value = false
|
|
148
|
+
|
|
149
|
+
const text = '# Hello\n\nThis is **Incremark**!'
|
|
150
|
+
for (const chunk of text.match(/[\s\S]{1,5}/g) || []) {
|
|
151
|
+
content.value += chunk // Incremental append
|
|
152
|
+
await new Promise(r => setTimeout(r, 50))
|
|
153
|
+
}
|
|
154
|
+
isFinished.value = true
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<template>
|
|
159
|
+
<IncremarkContent
|
|
160
|
+
:content="content"
|
|
161
|
+
:is-finished="isFinished"
|
|
162
|
+
:incremark-options="{ typewriter: { enabled: true } }"
|
|
163
|
+
/>
|
|
164
|
+
</template>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
// React
|
|
169
|
+
import { useState } from 'react'
|
|
170
|
+
import { IncremarkContent } from '@incremark/react'
|
|
171
|
+
|
|
172
|
+
function App() {
|
|
173
|
+
const [content, setContent] = useState('')
|
|
174
|
+
const [isFinished, setIsFinished] = useState(false)
|
|
175
|
+
|
|
176
|
+
async function simulateStream() {
|
|
177
|
+
setContent('')
|
|
178
|
+
setIsFinished(false)
|
|
179
|
+
|
|
180
|
+
const text = '# Hello\n\nThis is **Incremark**!'
|
|
181
|
+
const chunks = text.match(/[\s\S]{1,5}/g) || []
|
|
182
|
+
for (const chunk of chunks) {
|
|
183
|
+
setContent(prev => prev + chunk) // Incremental append
|
|
184
|
+
await new Promise(r => setTimeout(r, 50))
|
|
185
|
+
}
|
|
186
|
+
setIsFinished(true)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<IncremarkContent
|
|
191
|
+
content={content}
|
|
192
|
+
isFinished={isFinished}
|
|
193
|
+
incremarkOptions={{ typewriter: { enabled: true } } }
|
|
194
|
+
/>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
```
|
|
133
198
|
|
|
134
|
-
|
|
199
|
+
## Advanced: BlockTransformer
|
|
135
200
|
|
|
136
|
-
|
|
201
|
+
`BlockTransformer` is the typewriter effect controller, serving as middleware between parser and renderer. Only use this when you need custom rendering logic.
|
|
137
202
|
|
|
138
203
|
```ts
|
|
139
204
|
import { createBlockTransformer, defaultPlugins } from '@incremark/core'
|
package/README.md
CHANGED
|
@@ -87,11 +87,76 @@ console.log(update.completed) // 已完成的块
|
|
|
87
87
|
|
|
88
88
|
获取完整 AST。
|
|
89
89
|
|
|
90
|
-
##
|
|
90
|
+
## 与框架集成
|
|
91
|
+
|
|
92
|
+
对于日常使用,建议直接使用框架集成包,它们已内置增量解析和打字机效果支持:
|
|
93
|
+
|
|
94
|
+
```vue
|
|
95
|
+
<!-- Vue -->
|
|
96
|
+
<script setup>
|
|
97
|
+
import { ref } from 'vue'
|
|
98
|
+
import { IncremarkContent } from '@incremark/vue'
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
const content = ref('')
|
|
101
|
+
const isFinished = ref(false)
|
|
93
102
|
|
|
94
|
-
|
|
103
|
+
async function simulateStream() {
|
|
104
|
+
content.value = ''
|
|
105
|
+
isFinished.value = false
|
|
106
|
+
|
|
107
|
+
const text = '# Hello\n\nThis is **Incremark**!'
|
|
108
|
+
for (const chunk of text.match(/[\s\S]{1,5}/g) || []) {
|
|
109
|
+
content.value += chunk // 增量追加
|
|
110
|
+
await new Promise(r => setTimeout(r, 50))
|
|
111
|
+
}
|
|
112
|
+
isFinished.value = true
|
|
113
|
+
}
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<template>
|
|
117
|
+
<IncremarkContent
|
|
118
|
+
:content="content"
|
|
119
|
+
:is-finished="isFinished"
|
|
120
|
+
:incremark-options="{ typewriter: { enabled: true } }"
|
|
121
|
+
/>
|
|
122
|
+
</template>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
// React
|
|
127
|
+
import { useState } from 'react'
|
|
128
|
+
import { IncremarkContent } from '@incremark/react'
|
|
129
|
+
|
|
130
|
+
function App() {
|
|
131
|
+
const [content, setContent] = useState('')
|
|
132
|
+
const [isFinished, setIsFinished] = useState(false)
|
|
133
|
+
|
|
134
|
+
async function simulateStream() {
|
|
135
|
+
setContent('')
|
|
136
|
+
setIsFinished(false)
|
|
137
|
+
|
|
138
|
+
const text = '# Hello\n\nThis is **Incremark**!'
|
|
139
|
+
const chunks = text.match(/[\s\S]{1,5}/g) || []
|
|
140
|
+
for (const chunk of chunks) {
|
|
141
|
+
setContent(prev => prev + chunk) // 增量追加
|
|
142
|
+
await new Promise(r => setTimeout(r, 50))
|
|
143
|
+
}
|
|
144
|
+
setIsFinished(true)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<IncremarkContent
|
|
149
|
+
content={content}
|
|
150
|
+
isFinished={isFinished}
|
|
151
|
+
incremarkOptions={{ typewriter: { enabled: true } } }
|
|
152
|
+
/>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 高级用法:BlockTransformer
|
|
158
|
+
|
|
159
|
+
`BlockTransformer` 是打字机效果控制器,作为解析器和渲染器之间的中间层。仅在需要自定义渲染逻辑时使用。
|
|
95
160
|
|
|
96
161
|
```ts
|
|
97
162
|
import { createBlockTransformer, defaultPlugins } from '@incremark/core'
|
|
@@ -181,11 +246,6 @@ interface DisplayBlock {
|
|
|
181
246
|
}
|
|
182
247
|
```
|
|
183
248
|
|
|
184
|
-
## 与框架集成
|
|
185
|
-
|
|
186
|
-
- Vue: [@incremark/vue](../vue)
|
|
187
|
-
- React: [@incremark/react](../react)
|
|
188
|
-
|
|
189
249
|
## License
|
|
190
250
|
|
|
191
251
|
MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Root, RootContent } from 'mdast';
|
|
2
2
|
import { C as ContainerConfig, H as HtmlTreeExtensionOptions, B as BlockStatus, P as ParsedBlock } from './index-CWuosVAK.js';
|
|
3
|
-
import { I as IAstBuilder, E as EngineParserOptions } from './types-
|
|
3
|
+
import { I as IAstBuilder, E as EngineParserOptions } from './types-B7GTGJc2.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Marked AST 构建器(极速模式)
|
|
@@ -62,7 +62,7 @@ declare class MarkedAstBuilder implements IAstBuilder {
|
|
|
62
62
|
/**
|
|
63
63
|
* 将 AST 节点转换为 ParsedBlock
|
|
64
64
|
*/
|
|
65
|
-
nodesToBlocks(nodes: RootContent[], startOffset: number, rawText: string, status: BlockStatus, generateBlockId: () => string): ParsedBlock[];
|
|
65
|
+
nodesToBlocks(nodes: RootContent[], startOffset: number, rawText: string, status: BlockStatus, generateBlockId: (startOffset: number) => string): ParsedBlock[];
|
|
66
66
|
/**
|
|
67
67
|
* 更新配置选项
|
|
68
68
|
* @param options 部分配置选项
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { M as MarkedAstBuilder } from '../../MarkedAstBuildter-
|
|
2
|
-
export { A as AstBuilder } from '../../MarkedAstBuildter-
|
|
3
|
-
import { E as EngineParserOptions } from '../../types-
|
|
4
|
-
export { I as IAstBuilder, b as IncremarkPlugin, M as MarkedEngineExtension } from '../../types-
|
|
1
|
+
import { M as MarkedAstBuilder } from '../../MarkedAstBuildter-B2QhLKKy.js';
|
|
2
|
+
export { A as AstBuilder } from '../../MarkedAstBuildter-B2QhLKKy.js';
|
|
3
|
+
import { E as EngineParserOptions } from '../../types-B7GTGJc2.js';
|
|
4
|
+
export { I as IAstBuilder, b as IncremarkPlugin, M as MarkedEngineExtension } from '../../types-B7GTGJc2.js';
|
|
5
5
|
import 'mdast';
|
|
6
6
|
import '../../index-CWuosVAK.js';
|
|
7
7
|
import 'micromark-util-types';
|
|
@@ -1563,7 +1563,7 @@ var MarkedAstBuilder = class {
|
|
|
1563
1563
|
const absoluteStart = startOffset + relativeStart;
|
|
1564
1564
|
const absoluteEnd = startOffset + relativeEnd;
|
|
1565
1565
|
blocks.push({
|
|
1566
|
-
id: generateBlockId(),
|
|
1566
|
+
id: generateBlockId(absoluteStart),
|
|
1567
1567
|
status,
|
|
1568
1568
|
node,
|
|
1569
1569
|
startOffset: absoluteStart,
|