@incremark/core 0.3.2 → 0.3.4

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.
Files changed (3) hide show
  1. package/README.en.md +68 -3
  2. package/README.md +68 -8
  3. 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
- ## BlockTransformer
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
- Typewriter effect controller, serves as middleware between parser and renderer.
199
+ ## Advanced: BlockTransformer
135
200
 
136
- ### Basic Usage
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
- ## BlockTransformer
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incremark/core",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "High-performance incremental markdown parser specifically designed for AI streaming output scenarios.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",