@incremark/react 0.2.4 → 0.2.5

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
@@ -180,6 +180,13 @@ declare function useIncremark(options?: UseIncremarkOptions): {
180
180
  isLoading: boolean;
181
181
  /** 是否已完成(finalize) */
182
182
  isFinalized: boolean;
183
+ /**
184
+ * 内容是否完全显示完成
185
+ * - 无打字机:等于 isFinalized
186
+ * - 有打字机:isFinalized + 动画播放完成
187
+ * 适用于控制 footnote 等需要在内容完全显示后才出现的元素
188
+ */
189
+ isDisplayComplete: boolean;
183
190
  /** 追加内容 */
184
191
  append: (chunk: string) => IncrementalUpdate;
185
192
  /** 完成解析 */
package/dist/index.js CHANGED
@@ -146,6 +146,7 @@ function useTypewriter(options) {
146
146
  typewriterConfig?.effect ?? "none"
147
147
  );
148
148
  const [displayBlocks, setDisplayBlocks] = useState2([]);
149
+ const [isAnimationComplete, setIsAnimationComplete] = useState2(true);
149
150
  if (hasTypewriterConfig && !transformerRef.current) {
150
151
  const twOptions = typewriterConfig;
151
152
  transformerRef.current = createBlockTransformer({
@@ -158,6 +159,12 @@ function useTypewriter(options) {
158
159
  setDisplayBlocks(blocks2);
159
160
  setIsTypewriterProcessing(transformerRef.current?.isProcessing() ?? false);
160
161
  setIsTypewriterPaused(transformerRef.current?.isPausedState() ?? false);
162
+ if (transformerRef.current?.isProcessing()) {
163
+ setIsAnimationComplete(false);
164
+ }
165
+ },
166
+ onAllComplete: () => {
167
+ setIsAnimationComplete(true);
161
168
  }
162
169
  });
163
170
  }
@@ -283,7 +290,8 @@ function useTypewriter(options) {
283
290
  return {
284
291
  blocks,
285
292
  typewriter: typewriterControls,
286
- transformer
293
+ transformer,
294
+ isAnimationComplete
287
295
  };
288
296
  }
289
297
 
@@ -318,11 +326,12 @@ function useIncremark(options = {}) {
318
326
  const [pendingBlocks, setPendingBlocks] = useState3([]);
319
327
  const [isLoading, setIsLoading] = useState3(false);
320
328
  const [isFinalized, setIsFinalized] = useState3(false);
321
- const { blocks, typewriter, transformer } = useTypewriter({
329
+ const { blocks, typewriter, transformer, isAnimationComplete } = useTypewriter({
322
330
  typewriter: options.typewriter,
323
331
  completedBlocks,
324
332
  pendingBlocks
325
333
  });
334
+ const isDisplayComplete = isFinalized && isAnimationComplete;
326
335
  const ast = useMemo2(
327
336
  () => ({
328
337
  type: "root",
@@ -397,6 +406,13 @@ function useIncremark(options = {}) {
397
406
  isLoading,
398
407
  /** 是否已完成(finalize) */
399
408
  isFinalized,
409
+ /**
410
+ * 内容是否完全显示完成
411
+ * - 无打字机:等于 isFinalized
412
+ * - 有打字机:isFinalized + 动画播放完成
413
+ * 适用于控制 footnote 等需要在内容完全显示后才出现的元素
414
+ */
415
+ isDisplayComplete,
400
416
  /** 追加内容 */
401
417
  append,
402
418
  /** 完成解析 */
@@ -1304,7 +1320,7 @@ var Incremark = (props) => {
1304
1320
  incremark
1305
1321
  } = props;
1306
1322
  if (incremark) {
1307
- const { blocks: blocks2, isFinalized: isFinalized2, _definitionsContextValue } = incremark;
1323
+ const { blocks: blocks2, isDisplayComplete: isDisplayComplete2, _definitionsContextValue } = incremark;
1308
1324
  return /* @__PURE__ */ jsx17(IncremarkContainerProvider, { definitions: _definitionsContextValue, children: /* @__PURE__ */ jsx17(
1309
1325
  IncremarkInternal,
1310
1326
  {
@@ -1314,12 +1330,12 @@ var Incremark = (props) => {
1314
1330
  customCodeBlocks,
1315
1331
  showBlockStatus,
1316
1332
  className,
1317
- isFinalized: isFinalized2
1333
+ isDisplayComplete: isDisplayComplete2
1318
1334
  }
1319
1335
  ) });
1320
1336
  }
1321
1337
  const blocks = propsBlocks || [];
1322
- const isFinalized = blocks.length > 0 && blocks.every((b) => b.status === "completed");
1338
+ const isDisplayComplete = blocks.length > 0 && blocks.every((b) => b.status === "completed");
1323
1339
  return /* @__PURE__ */ jsx17(
1324
1340
  IncremarkInternal,
1325
1341
  {
@@ -1329,7 +1345,7 @@ var Incremark = (props) => {
1329
1345
  customCodeBlocks,
1330
1346
  showBlockStatus,
1331
1347
  className,
1332
- isFinalized
1348
+ isDisplayComplete
1333
1349
  }
1334
1350
  );
1335
1351
  };
@@ -1340,7 +1356,7 @@ var IncremarkInternal = ({
1340
1356
  customCodeBlocks,
1341
1357
  showBlockStatus,
1342
1358
  className,
1343
- isFinalized
1359
+ isDisplayComplete
1344
1360
  }) => {
1345
1361
  return /* @__PURE__ */ jsxs8("div", { className: `incremark ${className}`, children: [
1346
1362
  blocks.map((block) => {
@@ -1365,7 +1381,7 @@ var IncremarkInternal = ({
1365
1381
  }
1366
1382
  ) }, block.stableId);
1367
1383
  }),
1368
- isFinalized && /* @__PURE__ */ jsx17(IncremarkFootnotes, {})
1384
+ isDisplayComplete && /* @__PURE__ */ jsx17(IncremarkFootnotes, {})
1369
1385
  ] });
1370
1386
  };
1371
1387
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incremark/react",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "license": "MIT",
5
5
  "description": "Incremark React integration - Incremental Markdown parser for AI streaming",
6
6
  "type": "module",
@@ -21,13 +21,13 @@
21
21
  "mermaid": "^10.0.0 || ^11.0.0",
22
22
  "katex": "^0.16.0",
23
23
  "react": ">=18.0.0",
24
- "@incremark/core": "0.2.4"
24
+ "@incremark/core": "0.2.5"
25
25
  },
26
26
  "dependencies": {
27
27
  "shiki": "^3.20.0",
28
- "@incremark/theme": "0.2.4",
29
- "@incremark/shared": "0.2.4",
30
- "@incremark/devtools": "0.2.4"
28
+ "@incremark/theme": "0.2.5",
29
+ "@incremark/shared": "0.2.5",
30
+ "@incremark/devtools": "0.2.5"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/mdast": "^4.0.0",