@incremark/react 0.3.1 → 0.3.2
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 +3 -0
- package/dist/index.js +995 -177
- package/package.json +9 -6
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/hooks/useIncremark.ts
|
|
2
|
-
import { useState as useState3, useCallback as useCallback3, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
2
|
+
import { useState as useState3, useCallback as useCallback3, useMemo as useMemo2, useRef as useRef2, useEffect as useEffect2 } from "react";
|
|
3
3
|
import {
|
|
4
4
|
createIncremarkParser
|
|
5
5
|
} from "@incremark/core";
|
|
@@ -102,13 +102,21 @@ function useProvideDefinitions() {
|
|
|
102
102
|
import { useState as useState2, useCallback as useCallback2, useMemo, useRef, useEffect } from "react";
|
|
103
103
|
import {
|
|
104
104
|
createBlockTransformer,
|
|
105
|
-
defaultPlugins
|
|
105
|
+
defaultPlugins,
|
|
106
|
+
mathPlugin,
|
|
107
|
+
collectFootnoteReferences
|
|
106
108
|
} from "@incremark/core";
|
|
107
109
|
|
|
108
110
|
// src/utils/cursor.ts
|
|
109
111
|
function addCursorToNode(node, cursor) {
|
|
112
|
+
if (node.type === "code") {
|
|
113
|
+
return node;
|
|
114
|
+
}
|
|
110
115
|
const cloned = JSON.parse(JSON.stringify(node));
|
|
111
116
|
function addToLast(n) {
|
|
117
|
+
if (n.type === "code") {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
112
120
|
if (n.children && n.children.length > 0) {
|
|
113
121
|
for (let i = n.children.length - 1; i >= 0; i--) {
|
|
114
122
|
if (addToLast(n.children[i])) {
|
|
@@ -154,14 +162,12 @@ function useTypewriter(options) {
|
|
|
154
162
|
tickInterval: twOptions.tickInterval ?? 30,
|
|
155
163
|
effect: twOptions.effect ?? "none",
|
|
156
164
|
pauseOnHidden: twOptions.pauseOnHidden ?? true,
|
|
157
|
-
|
|
165
|
+
// 默认插件 + 数学公式插件(数学公式应该整体显示,不参与打字机逐字符效果)
|
|
166
|
+
plugins: twOptions.plugins ?? [...defaultPlugins, mathPlugin],
|
|
158
167
|
onChange: (blocks2) => {
|
|
159
168
|
setDisplayBlocks(blocks2);
|
|
160
169
|
setIsTypewriterProcessing(transformerRef.current?.isProcessing() ?? false);
|
|
161
170
|
setIsTypewriterPaused(transformerRef.current?.isPausedState() ?? false);
|
|
162
|
-
if (transformerRef.current?.isProcessing()) {
|
|
163
|
-
setIsAnimationComplete(false);
|
|
164
|
-
}
|
|
165
171
|
},
|
|
166
172
|
onAllComplete: () => {
|
|
167
173
|
setIsAnimationComplete(true);
|
|
@@ -170,24 +176,23 @@ function useTypewriter(options) {
|
|
|
170
176
|
}
|
|
171
177
|
const transformer = transformerRef.current;
|
|
172
178
|
const sourceBlocks = useMemo(
|
|
173
|
-
() =>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
() => [
|
|
180
|
+
...completedBlocks.map((block) => ({
|
|
181
|
+
id: block.id,
|
|
182
|
+
node: block.node,
|
|
183
|
+
status: block.status
|
|
184
|
+
})),
|
|
185
|
+
...pendingBlocks.map((block) => ({
|
|
186
|
+
id: block.id,
|
|
187
|
+
node: block.node,
|
|
188
|
+
status: block.status
|
|
189
|
+
}))
|
|
190
|
+
],
|
|
191
|
+
[completedBlocks, pendingBlocks]
|
|
179
192
|
);
|
|
180
193
|
useEffect(() => {
|
|
181
194
|
if (!transformer) return;
|
|
182
195
|
transformer.push(sourceBlocks);
|
|
183
|
-
const displayBlocks2 = transformer.getDisplayBlocks();
|
|
184
|
-
const currentDisplaying = displayBlocks2.find((b) => !b.isDisplayComplete);
|
|
185
|
-
if (currentDisplaying) {
|
|
186
|
-
const updated = sourceBlocks.find((b) => b.id === currentDisplaying.id);
|
|
187
|
-
if (updated) {
|
|
188
|
-
transformer.update(updated);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
196
|
setIsTypewriterProcessing(transformer.isProcessing());
|
|
192
197
|
setIsTypewriterPaused(transformer.isPausedState());
|
|
193
198
|
}, [sourceBlocks, transformer]);
|
|
@@ -223,6 +228,37 @@ function useTypewriter(options) {
|
|
|
223
228
|
return block;
|
|
224
229
|
});
|
|
225
230
|
}, [completedBlocks, pendingBlocks, typewriterEnabled, typewriterEffect, displayBlocks]);
|
|
231
|
+
const displayedFootnoteReferenceOrder = useMemo(() => {
|
|
232
|
+
if (!typewriterEnabled || !transformer) {
|
|
233
|
+
const references2 = [];
|
|
234
|
+
const seen2 = /* @__PURE__ */ new Set();
|
|
235
|
+
for (const block of [...completedBlocks, ...pendingBlocks]) {
|
|
236
|
+
const blockRefs = collectFootnoteReferences(block.node);
|
|
237
|
+
for (const ref of blockRefs) {
|
|
238
|
+
if (!seen2.has(ref)) {
|
|
239
|
+
seen2.add(ref);
|
|
240
|
+
references2.push(ref);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return references2;
|
|
245
|
+
}
|
|
246
|
+
if (!isAnimationComplete) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
const references = [];
|
|
250
|
+
const seen = /* @__PURE__ */ new Set();
|
|
251
|
+
for (const db of displayBlocks) {
|
|
252
|
+
const blockRefs = collectFootnoteReferences(db.displayNode);
|
|
253
|
+
for (const ref of blockRefs) {
|
|
254
|
+
if (!seen.has(ref)) {
|
|
255
|
+
seen.add(ref);
|
|
256
|
+
references.push(ref);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return references;
|
|
261
|
+
}, [typewriterEnabled, transformer, isAnimationComplete, completedBlocks, pendingBlocks, displayBlocks]);
|
|
226
262
|
const skip = useCallback2(() => {
|
|
227
263
|
transformer?.skip();
|
|
228
264
|
setIsTypewriterProcessing(false);
|
|
@@ -280,7 +316,8 @@ function useTypewriter(options) {
|
|
|
280
316
|
blocks,
|
|
281
317
|
typewriter: typewriterControls,
|
|
282
318
|
transformer,
|
|
283
|
-
isAnimationComplete
|
|
319
|
+
isAnimationComplete,
|
|
320
|
+
displayedFootnoteReferenceOrder
|
|
284
321
|
};
|
|
285
322
|
}
|
|
286
323
|
|
|
@@ -315,14 +352,26 @@ function useIncremark(options = {}) {
|
|
|
315
352
|
const [pendingBlocks, setPendingBlocks] = useState3([]);
|
|
316
353
|
const [isLoading, setIsLoading] = useState3(false);
|
|
317
354
|
const [isFinalized, setIsFinalized] = useState3(false);
|
|
355
|
+
const [ast, setAst] = useState3({
|
|
356
|
+
type: "root",
|
|
357
|
+
children: []
|
|
358
|
+
});
|
|
318
359
|
const handleUpdate = useCallback3(
|
|
319
360
|
(update, isFinalize) => {
|
|
320
361
|
setMarkdown(parser.getBuffer());
|
|
362
|
+
if (update.updated.length > 0) {
|
|
363
|
+
const idsToRemove = new Set(update.updated.map((b) => b.id));
|
|
364
|
+
setCompletedBlocks((prev) => prev.filter((b) => !idsToRemove.has(b.id)));
|
|
365
|
+
}
|
|
321
366
|
if (update.completed.length > 0) {
|
|
322
367
|
setCompletedBlocks((prev) => [...prev, ...update.completed]);
|
|
323
368
|
}
|
|
324
369
|
setPendingBlocks(update.pending);
|
|
325
370
|
if (isFinalize) {
|
|
371
|
+
if (update.pending.length > 0) {
|
|
372
|
+
setCompletedBlocks((prev) => [...prev, ...update.pending]);
|
|
373
|
+
setPendingBlocks([]);
|
|
374
|
+
}
|
|
326
375
|
setIsLoading(false);
|
|
327
376
|
setIsFinalized(true);
|
|
328
377
|
} else {
|
|
@@ -332,7 +381,7 @@ function useIncremark(options = {}) {
|
|
|
332
381
|
},
|
|
333
382
|
[parser, setFootnoteReferenceOrder]
|
|
334
383
|
);
|
|
335
|
-
const { blocks, typewriter, transformer, isAnimationComplete } = useTypewriter({
|
|
384
|
+
const { blocks, typewriter, transformer, isAnimationComplete, displayedFootnoteReferenceOrder } = useTypewriter({
|
|
336
385
|
typewriter: options.typewriter,
|
|
337
386
|
completedBlocks,
|
|
338
387
|
pendingBlocks
|
|
@@ -343,16 +392,10 @@ function useIncremark(options = {}) {
|
|
|
343
392
|
}
|
|
344
393
|
return isFinalized && isAnimationComplete;
|
|
345
394
|
}, [options.typewriter, typewriter.enabled, isFinalized, isAnimationComplete]);
|
|
346
|
-
const ast = useMemo2(
|
|
347
|
-
() => ({
|
|
348
|
-
type: "root",
|
|
349
|
-
children: [...completedBlocks.map((b) => b.node), ...pendingBlocks.map((b) => b.node)]
|
|
350
|
-
}),
|
|
351
|
-
[completedBlocks, pendingBlocks]
|
|
352
|
-
);
|
|
353
395
|
const append = useCallback3(
|
|
354
396
|
(chunk) => {
|
|
355
397
|
const update = parser.append(chunk);
|
|
398
|
+
setAst(update.ast);
|
|
356
399
|
handleUpdate(update, false);
|
|
357
400
|
return update;
|
|
358
401
|
},
|
|
@@ -374,6 +417,7 @@ function useIncremark(options = {}) {
|
|
|
374
417
|
setIsLoading(false);
|
|
375
418
|
setIsFinalized(false);
|
|
376
419
|
setFootnoteReferenceOrder([]);
|
|
420
|
+
setAst({ type: "root", children: [] });
|
|
377
421
|
transformer?.reset();
|
|
378
422
|
}, [parser, transformer, setFootnoteReferenceOrder]);
|
|
379
423
|
const render = useCallback3(
|
|
@@ -398,10 +442,17 @@ function useIncremark(options = {}) {
|
|
|
398
442
|
setIsLoading(false);
|
|
399
443
|
setIsFinalized(false);
|
|
400
444
|
setFootnoteReferenceOrder([]);
|
|
445
|
+
setAst({ type: "root", children: [] });
|
|
401
446
|
transformer?.reset();
|
|
402
447
|
},
|
|
403
448
|
[parser, transformer, setFootnoteReferenceOrder]
|
|
404
449
|
);
|
|
450
|
+
useEffect2(
|
|
451
|
+
() => {
|
|
452
|
+
setFootnoteReferenceOrder(displayedFootnoteReferenceOrder);
|
|
453
|
+
},
|
|
454
|
+
[displayedFootnoteReferenceOrder, setFootnoteReferenceOrder]
|
|
455
|
+
);
|
|
405
456
|
return {
|
|
406
457
|
/** 已收集的完整 Markdown 字符串 */
|
|
407
458
|
markdown,
|
|
@@ -446,12 +497,12 @@ function useIncremark(options = {}) {
|
|
|
446
497
|
}
|
|
447
498
|
|
|
448
499
|
// src/hooks/useDevTools.ts
|
|
449
|
-
import { useEffect as
|
|
500
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
450
501
|
import { createDevTools } from "@incremark/devtools";
|
|
451
502
|
function useDevTools(incremark, options = {}) {
|
|
452
503
|
const devtoolsRef = useRef3(null);
|
|
453
504
|
const optionsRef = useRef3(options);
|
|
454
|
-
|
|
505
|
+
useEffect3(() => {
|
|
455
506
|
const devtools = createDevTools(optionsRef.current);
|
|
456
507
|
devtoolsRef.current = devtools;
|
|
457
508
|
incremark.parser.setOnChange((state) => {
|
|
@@ -478,7 +529,7 @@ function useDevTools(incremark, options = {}) {
|
|
|
478
529
|
}
|
|
479
530
|
|
|
480
531
|
// src/hooks/useBlockTransformer.ts
|
|
481
|
-
import { useState as useState4, useCallback as useCallback4, useRef as useRef4, useEffect as
|
|
532
|
+
import { useState as useState4, useCallback as useCallback4, useRef as useRef4, useEffect as useEffect4 } from "react";
|
|
482
533
|
import {
|
|
483
534
|
createBlockTransformer as createBlockTransformer2
|
|
484
535
|
} from "@incremark/core";
|
|
@@ -499,7 +550,7 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
499
550
|
});
|
|
500
551
|
}
|
|
501
552
|
const transformer = transformerRef.current;
|
|
502
|
-
|
|
553
|
+
useEffect4(() => {
|
|
503
554
|
transformer.push(sourceBlocks);
|
|
504
555
|
const currentDisplaying = displayBlocks.find((b) => !b.isDisplayComplete);
|
|
505
556
|
if (currentDisplaying) {
|
|
@@ -509,7 +560,7 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
509
560
|
}
|
|
510
561
|
}
|
|
511
562
|
}, [sourceBlocks, transformer]);
|
|
512
|
-
|
|
563
|
+
useEffect4(() => {
|
|
513
564
|
return () => {
|
|
514
565
|
transformer.destroy();
|
|
515
566
|
};
|
|
@@ -552,40 +603,34 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
552
603
|
}
|
|
553
604
|
|
|
554
605
|
// src/hooks/useLocale.ts
|
|
555
|
-
import { useContext as useContext2 } from "react";
|
|
606
|
+
import { useContext as useContext2, useMemo as useMemo4 } from "react";
|
|
607
|
+
import { zhCN as zhCN2 } from "@incremark/shared";
|
|
556
608
|
|
|
557
609
|
// src/components/ConfigProvider.tsx
|
|
558
610
|
import { createContext as createContext2, useMemo as useMemo3 } from "react";
|
|
611
|
+
import { zhCN } from "@incremark/shared";
|
|
559
612
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
560
613
|
var LocaleContext = createContext2(null);
|
|
561
|
-
function ConfigProvider({ children, locale
|
|
562
|
-
const contextValue = useMemo3(() => ({ locale }), [locale]);
|
|
614
|
+
function ConfigProvider({ children, locale }) {
|
|
615
|
+
const contextValue = useMemo3(() => ({ locale: locale || zhCN }), [locale]);
|
|
563
616
|
return /* @__PURE__ */ jsx2(LocaleContext.Provider, { value: contextValue, children });
|
|
564
617
|
}
|
|
565
618
|
|
|
566
619
|
// src/hooks/useLocale.ts
|
|
567
620
|
function useLocale() {
|
|
568
621
|
const context = useContext2(LocaleContext);
|
|
569
|
-
|
|
570
|
-
|
|
622
|
+
const { locale } = context || { locale: zhCN2 };
|
|
623
|
+
const t = useMemo4(
|
|
624
|
+
() => (key) => {
|
|
571
625
|
const keys = key.split(".");
|
|
572
|
-
let value =
|
|
626
|
+
let value = locale;
|
|
573
627
|
for (const k of keys) {
|
|
574
628
|
value = value?.[k];
|
|
575
629
|
}
|
|
576
630
|
return value || key;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
const { locale } = context;
|
|
581
|
-
const t = (key) => {
|
|
582
|
-
const keys = key.split(".");
|
|
583
|
-
let value = locale;
|
|
584
|
-
for (const k of keys) {
|
|
585
|
-
value = value?.[k];
|
|
586
|
-
}
|
|
587
|
-
return value || key;
|
|
588
|
-
};
|
|
631
|
+
},
|
|
632
|
+
[locale]
|
|
633
|
+
);
|
|
589
634
|
return { t };
|
|
590
635
|
}
|
|
591
636
|
|
|
@@ -750,7 +795,7 @@ var IncremarkHtmlElement = ({ node }) => {
|
|
|
750
795
|
};
|
|
751
796
|
|
|
752
797
|
// src/components/IncremarkMath.tsx
|
|
753
|
-
import { useState as useState5, useEffect as
|
|
798
|
+
import { useState as useState5, useEffect as useEffect5, useRef as useRef5, useCallback as useCallback5 } from "react";
|
|
754
799
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
755
800
|
var IncremarkMath = ({
|
|
756
801
|
node,
|
|
@@ -795,10 +840,10 @@ var IncremarkMath = ({
|
|
|
795
840
|
doRender();
|
|
796
841
|
}, renderDelay);
|
|
797
842
|
}, [formula, renderDelay, doRender]);
|
|
798
|
-
|
|
843
|
+
useEffect5(() => {
|
|
799
844
|
scheduleRender();
|
|
800
845
|
}, [scheduleRender]);
|
|
801
|
-
|
|
846
|
+
useEffect5(() => {
|
|
802
847
|
return () => {
|
|
803
848
|
if (renderTimerRef.current) {
|
|
804
849
|
clearTimeout(renderTimerRef.current);
|
|
@@ -954,10 +999,10 @@ var IncremarkParagraph = ({ node }) => {
|
|
|
954
999
|
};
|
|
955
1000
|
|
|
956
1001
|
// src/components/IncremarkCode.tsx
|
|
957
|
-
import
|
|
1002
|
+
import React9 from "react";
|
|
958
1003
|
|
|
959
1004
|
// src/components/IncremarkCodeMermaid.tsx
|
|
960
|
-
import { useState as useState6, useEffect as
|
|
1005
|
+
import { useState as useState6, useEffect as useEffect6, useRef as useRef6, useCallback as useCallback6 } from "react";
|
|
961
1006
|
import { GravityMermaid, LucideCode, LucideEye, LucideCopy, LucideCopyCheck } from "@incremark/icons";
|
|
962
1007
|
import { isClipboardAvailable } from "@incremark/shared";
|
|
963
1008
|
|
|
@@ -1041,10 +1086,10 @@ var IncremarkCodeMermaid = ({
|
|
|
1041
1086
|
doRenderMermaid();
|
|
1042
1087
|
}, mermaidDelay);
|
|
1043
1088
|
}, [code, mermaidDelay, doRenderMermaid]);
|
|
1044
|
-
|
|
1089
|
+
useEffect6(() => {
|
|
1045
1090
|
scheduleRenderMermaid();
|
|
1046
1091
|
}, [scheduleRenderMermaid]);
|
|
1047
|
-
|
|
1092
|
+
useEffect6(() => {
|
|
1048
1093
|
return () => {
|
|
1049
1094
|
if (mermaidTimerRef.current) {
|
|
1050
1095
|
clearTimeout(mermaidTimerRef.current);
|
|
@@ -1091,7 +1136,7 @@ var IncremarkCodeMermaid = ({
|
|
|
1091
1136
|
};
|
|
1092
1137
|
|
|
1093
1138
|
// src/components/IncremarkCodeDefault.tsx
|
|
1094
|
-
import { useState as
|
|
1139
|
+
import { useState as useState8, useEffect as useEffect8, useCallback as useCallback7, useRef as useRef8, useMemo as useMemo5 } from "react";
|
|
1095
1140
|
import { LucideCopy as LucideCopy2, LucideCopyCheck as LucideCopyCheck2 } from "@incremark/icons";
|
|
1096
1141
|
import { isClipboardAvailable as isClipboardAvailable2 } from "@incremark/shared";
|
|
1097
1142
|
|
|
@@ -1197,13 +1242,28 @@ function getShikiManager() {
|
|
|
1197
1242
|
}
|
|
1198
1243
|
function useShiki(theme) {
|
|
1199
1244
|
const [isHighlighting, setIsHighlighting] = React6.useState(false);
|
|
1200
|
-
const
|
|
1245
|
+
const [isReady, setIsReady] = React6.useState(false);
|
|
1246
|
+
const [highlighterInfo, setHighlighterInfo] = React6.useState(null);
|
|
1247
|
+
const initHighlighter = React6.useCallback(async () => {
|
|
1248
|
+
if (isReady) return;
|
|
1249
|
+
try {
|
|
1250
|
+
const info = await getShikiManager().getHighlighter(theme);
|
|
1251
|
+
setHighlighterInfo(info);
|
|
1252
|
+
setIsReady(true);
|
|
1253
|
+
} catch (e) {
|
|
1254
|
+
console.warn("Failed to initialize Shiki highlighter:", e);
|
|
1255
|
+
throw e;
|
|
1256
|
+
}
|
|
1257
|
+
}, [theme, isReady]);
|
|
1201
1258
|
const getHighlighter = React6.useCallback(async () => {
|
|
1202
|
-
if (!
|
|
1203
|
-
|
|
1259
|
+
if (!highlighterInfo) {
|
|
1260
|
+
const info = await getShikiManager().getHighlighter(theme);
|
|
1261
|
+
setHighlighterInfo(info);
|
|
1262
|
+
setIsReady(true);
|
|
1263
|
+
return info;
|
|
1204
1264
|
}
|
|
1205
|
-
return
|
|
1206
|
-
}, [theme]);
|
|
1265
|
+
return highlighterInfo;
|
|
1266
|
+
}, [theme, highlighterInfo]);
|
|
1207
1267
|
const highlight = React6.useCallback(async (code, lang, fallbackTheme) => {
|
|
1208
1268
|
setIsHighlighting(true);
|
|
1209
1269
|
try {
|
|
@@ -1223,26 +1283,787 @@ function useShiki(theme) {
|
|
|
1223
1283
|
}
|
|
1224
1284
|
}, [getHighlighter, theme]);
|
|
1225
1285
|
return {
|
|
1286
|
+
highlighterInfo,
|
|
1226
1287
|
isHighlighting,
|
|
1288
|
+
isReady,
|
|
1289
|
+
initHighlighter,
|
|
1227
1290
|
highlight
|
|
1228
1291
|
};
|
|
1229
1292
|
}
|
|
1230
1293
|
|
|
1294
|
+
// src/components/CachedCodeRenderer.tsx
|
|
1295
|
+
import { objectId } from "@antfu/utils";
|
|
1296
|
+
|
|
1297
|
+
// ../../node_modules/.pnpm/@shikijs+vscode-textmate@10.0.2/node_modules/@shikijs/vscode-textmate/dist/index.js
|
|
1298
|
+
function escapeRegExpCharacters(value) {
|
|
1299
|
+
return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, "\\$&");
|
|
1300
|
+
}
|
|
1301
|
+
var CachedFn = class {
|
|
1302
|
+
constructor(fn) {
|
|
1303
|
+
this.fn = fn;
|
|
1304
|
+
}
|
|
1305
|
+
cache = /* @__PURE__ */ new Map();
|
|
1306
|
+
get(key) {
|
|
1307
|
+
if (this.cache.has(key)) {
|
|
1308
|
+
return this.cache.get(key);
|
|
1309
|
+
}
|
|
1310
|
+
const value = this.fn(key);
|
|
1311
|
+
this.cache.set(key, value);
|
|
1312
|
+
return value;
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
var ScopeStack = class _ScopeStack {
|
|
1316
|
+
constructor(parent, scopeName) {
|
|
1317
|
+
this.parent = parent;
|
|
1318
|
+
this.scopeName = scopeName;
|
|
1319
|
+
}
|
|
1320
|
+
static push(path, scopeNames) {
|
|
1321
|
+
for (const name of scopeNames) {
|
|
1322
|
+
path = new _ScopeStack(path, name);
|
|
1323
|
+
}
|
|
1324
|
+
return path;
|
|
1325
|
+
}
|
|
1326
|
+
static from(...segments) {
|
|
1327
|
+
let result = null;
|
|
1328
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1329
|
+
result = new _ScopeStack(result, segments[i]);
|
|
1330
|
+
}
|
|
1331
|
+
return result;
|
|
1332
|
+
}
|
|
1333
|
+
push(scopeName) {
|
|
1334
|
+
return new _ScopeStack(this, scopeName);
|
|
1335
|
+
}
|
|
1336
|
+
getSegments() {
|
|
1337
|
+
let item = this;
|
|
1338
|
+
const result = [];
|
|
1339
|
+
while (item) {
|
|
1340
|
+
result.push(item.scopeName);
|
|
1341
|
+
item = item.parent;
|
|
1342
|
+
}
|
|
1343
|
+
result.reverse();
|
|
1344
|
+
return result;
|
|
1345
|
+
}
|
|
1346
|
+
toString() {
|
|
1347
|
+
return this.getSegments().join(" ");
|
|
1348
|
+
}
|
|
1349
|
+
extends(other) {
|
|
1350
|
+
if (this === other) {
|
|
1351
|
+
return true;
|
|
1352
|
+
}
|
|
1353
|
+
if (this.parent === null) {
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
return this.parent.extends(other);
|
|
1357
|
+
}
|
|
1358
|
+
getExtensionIfDefined(base) {
|
|
1359
|
+
const result = [];
|
|
1360
|
+
let item = this;
|
|
1361
|
+
while (item && item !== base) {
|
|
1362
|
+
result.push(item.scopeName);
|
|
1363
|
+
item = item.parent;
|
|
1364
|
+
}
|
|
1365
|
+
return item === base ? result.reverse() : void 0;
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
var FontStyle = /* @__PURE__ */ ((FontStyle2) => {
|
|
1369
|
+
FontStyle2[FontStyle2["NotSet"] = -1] = "NotSet";
|
|
1370
|
+
FontStyle2[FontStyle2["None"] = 0] = "None";
|
|
1371
|
+
FontStyle2[FontStyle2["Italic"] = 1] = "Italic";
|
|
1372
|
+
FontStyle2[FontStyle2["Bold"] = 2] = "Bold";
|
|
1373
|
+
FontStyle2[FontStyle2["Underline"] = 4] = "Underline";
|
|
1374
|
+
FontStyle2[FontStyle2["Strikethrough"] = 8] = "Strikethrough";
|
|
1375
|
+
return FontStyle2;
|
|
1376
|
+
})(FontStyle || {});
|
|
1377
|
+
var emptyParentScopes = Object.freeze([]);
|
|
1378
|
+
var EncodedTokenMetadata = class _EncodedTokenMetadata {
|
|
1379
|
+
static toBinaryStr(encodedTokenAttributes) {
|
|
1380
|
+
return encodedTokenAttributes.toString(2).padStart(32, "0");
|
|
1381
|
+
}
|
|
1382
|
+
static print(encodedTokenAttributes) {
|
|
1383
|
+
const languageId = _EncodedTokenMetadata.getLanguageId(encodedTokenAttributes);
|
|
1384
|
+
const tokenType = _EncodedTokenMetadata.getTokenType(encodedTokenAttributes);
|
|
1385
|
+
const fontStyle = _EncodedTokenMetadata.getFontStyle(encodedTokenAttributes);
|
|
1386
|
+
const foreground = _EncodedTokenMetadata.getForeground(encodedTokenAttributes);
|
|
1387
|
+
const background = _EncodedTokenMetadata.getBackground(encodedTokenAttributes);
|
|
1388
|
+
console.log({
|
|
1389
|
+
languageId,
|
|
1390
|
+
tokenType,
|
|
1391
|
+
fontStyle,
|
|
1392
|
+
foreground,
|
|
1393
|
+
background
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
static getLanguageId(encodedTokenAttributes) {
|
|
1397
|
+
return (encodedTokenAttributes & 255) >>> 0;
|
|
1398
|
+
}
|
|
1399
|
+
static getTokenType(encodedTokenAttributes) {
|
|
1400
|
+
return (encodedTokenAttributes & 768) >>> 8;
|
|
1401
|
+
}
|
|
1402
|
+
static containsBalancedBrackets(encodedTokenAttributes) {
|
|
1403
|
+
return (encodedTokenAttributes & 1024) !== 0;
|
|
1404
|
+
}
|
|
1405
|
+
static getFontStyle(encodedTokenAttributes) {
|
|
1406
|
+
return (encodedTokenAttributes & 30720) >>> 11;
|
|
1407
|
+
}
|
|
1408
|
+
static getForeground(encodedTokenAttributes) {
|
|
1409
|
+
return (encodedTokenAttributes & 16744448) >>> 15;
|
|
1410
|
+
}
|
|
1411
|
+
static getBackground(encodedTokenAttributes) {
|
|
1412
|
+
return (encodedTokenAttributes & 4278190080) >>> 24;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Updates the fields in `metadata`.
|
|
1416
|
+
* A value of `0`, `NotSet` or `null` indicates that the corresponding field should be left as is.
|
|
1417
|
+
*/
|
|
1418
|
+
static set(encodedTokenAttributes, languageId, tokenType, containsBalancedBrackets, fontStyle, foreground, background) {
|
|
1419
|
+
let _languageId = _EncodedTokenMetadata.getLanguageId(encodedTokenAttributes);
|
|
1420
|
+
let _tokenType = _EncodedTokenMetadata.getTokenType(encodedTokenAttributes);
|
|
1421
|
+
let _containsBalancedBracketsBit = _EncodedTokenMetadata.containsBalancedBrackets(encodedTokenAttributes) ? 1 : 0;
|
|
1422
|
+
let _fontStyle = _EncodedTokenMetadata.getFontStyle(encodedTokenAttributes);
|
|
1423
|
+
let _foreground = _EncodedTokenMetadata.getForeground(encodedTokenAttributes);
|
|
1424
|
+
let _background = _EncodedTokenMetadata.getBackground(encodedTokenAttributes);
|
|
1425
|
+
if (languageId !== 0) {
|
|
1426
|
+
_languageId = languageId;
|
|
1427
|
+
}
|
|
1428
|
+
if (tokenType !== 8) {
|
|
1429
|
+
_tokenType = fromOptionalTokenType(tokenType);
|
|
1430
|
+
}
|
|
1431
|
+
if (containsBalancedBrackets !== null) {
|
|
1432
|
+
_containsBalancedBracketsBit = containsBalancedBrackets ? 1 : 0;
|
|
1433
|
+
}
|
|
1434
|
+
if (fontStyle !== -1) {
|
|
1435
|
+
_fontStyle = fontStyle;
|
|
1436
|
+
}
|
|
1437
|
+
if (foreground !== 0) {
|
|
1438
|
+
_foreground = foreground;
|
|
1439
|
+
}
|
|
1440
|
+
if (background !== 0) {
|
|
1441
|
+
_background = background;
|
|
1442
|
+
}
|
|
1443
|
+
return (_languageId << 0 | _tokenType << 8 | _containsBalancedBracketsBit << 10 | _fontStyle << 11 | _foreground << 15 | _background << 24) >>> 0;
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
function fromOptionalTokenType(standardType) {
|
|
1447
|
+
return standardType;
|
|
1448
|
+
}
|
|
1449
|
+
function ruleIdFromNumber(id) {
|
|
1450
|
+
return id;
|
|
1451
|
+
}
|
|
1452
|
+
function ruleIdToNumber(id) {
|
|
1453
|
+
return id;
|
|
1454
|
+
}
|
|
1455
|
+
var BasicScopeAttributes = class {
|
|
1456
|
+
constructor(languageId, tokenType) {
|
|
1457
|
+
this.languageId = languageId;
|
|
1458
|
+
this.tokenType = tokenType;
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
var BasicScopeAttributesProvider = class _BasicScopeAttributesProvider {
|
|
1462
|
+
_defaultAttributes;
|
|
1463
|
+
_embeddedLanguagesMatcher;
|
|
1464
|
+
constructor(initialLanguageId, embeddedLanguages) {
|
|
1465
|
+
this._defaultAttributes = new BasicScopeAttributes(
|
|
1466
|
+
initialLanguageId,
|
|
1467
|
+
8
|
|
1468
|
+
/* NotSet */
|
|
1469
|
+
);
|
|
1470
|
+
this._embeddedLanguagesMatcher = new ScopeMatcher(Object.entries(embeddedLanguages || {}));
|
|
1471
|
+
}
|
|
1472
|
+
getDefaultAttributes() {
|
|
1473
|
+
return this._defaultAttributes;
|
|
1474
|
+
}
|
|
1475
|
+
getBasicScopeAttributes(scopeName) {
|
|
1476
|
+
if (scopeName === null) {
|
|
1477
|
+
return _BasicScopeAttributesProvider._NULL_SCOPE_METADATA;
|
|
1478
|
+
}
|
|
1479
|
+
return this._getBasicScopeAttributes.get(scopeName);
|
|
1480
|
+
}
|
|
1481
|
+
static _NULL_SCOPE_METADATA = new BasicScopeAttributes(0, 0);
|
|
1482
|
+
_getBasicScopeAttributes = new CachedFn((scopeName) => {
|
|
1483
|
+
const languageId = this._scopeToLanguage(scopeName);
|
|
1484
|
+
const standardTokenType = this._toStandardTokenType(scopeName);
|
|
1485
|
+
return new BasicScopeAttributes(languageId, standardTokenType);
|
|
1486
|
+
});
|
|
1487
|
+
/**
|
|
1488
|
+
* Given a produced TM scope, return the language that token describes or null if unknown.
|
|
1489
|
+
* e.g. source.html => html, source.css.embedded.html => css, punctuation.definition.tag.html => null
|
|
1490
|
+
*/
|
|
1491
|
+
_scopeToLanguage(scope) {
|
|
1492
|
+
return this._embeddedLanguagesMatcher.match(scope) || 0;
|
|
1493
|
+
}
|
|
1494
|
+
_toStandardTokenType(scopeName) {
|
|
1495
|
+
const m = scopeName.match(_BasicScopeAttributesProvider.STANDARD_TOKEN_TYPE_REGEXP);
|
|
1496
|
+
if (!m) {
|
|
1497
|
+
return 8;
|
|
1498
|
+
}
|
|
1499
|
+
switch (m[1]) {
|
|
1500
|
+
case "comment":
|
|
1501
|
+
return 1;
|
|
1502
|
+
case "string":
|
|
1503
|
+
return 2;
|
|
1504
|
+
case "regex":
|
|
1505
|
+
return 3;
|
|
1506
|
+
case "meta.embedded":
|
|
1507
|
+
return 0;
|
|
1508
|
+
}
|
|
1509
|
+
throw new Error("Unexpected match for standard token type!");
|
|
1510
|
+
}
|
|
1511
|
+
static STANDARD_TOKEN_TYPE_REGEXP = /\b(comment|string|regex|meta\.embedded)\b/;
|
|
1512
|
+
};
|
|
1513
|
+
var ScopeMatcher = class {
|
|
1514
|
+
values;
|
|
1515
|
+
scopesRegExp;
|
|
1516
|
+
constructor(values) {
|
|
1517
|
+
if (values.length === 0) {
|
|
1518
|
+
this.values = null;
|
|
1519
|
+
this.scopesRegExp = null;
|
|
1520
|
+
} else {
|
|
1521
|
+
this.values = new Map(values);
|
|
1522
|
+
const escapedScopes = values.map(
|
|
1523
|
+
([scopeName, value]) => escapeRegExpCharacters(scopeName)
|
|
1524
|
+
);
|
|
1525
|
+
escapedScopes.sort();
|
|
1526
|
+
escapedScopes.reverse();
|
|
1527
|
+
this.scopesRegExp = new RegExp(
|
|
1528
|
+
`^((${escapedScopes.join(")|(")}))($|\\.)`,
|
|
1529
|
+
""
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
match(scope) {
|
|
1534
|
+
if (!this.scopesRegExp) {
|
|
1535
|
+
return void 0;
|
|
1536
|
+
}
|
|
1537
|
+
const m = scope.match(this.scopesRegExp);
|
|
1538
|
+
if (!m) {
|
|
1539
|
+
return void 0;
|
|
1540
|
+
}
|
|
1541
|
+
return this.values.get(m[1]);
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
var DebugFlags = {
|
|
1545
|
+
InDebugMode: typeof process !== "undefined" && !!process.env["VSCODE_TEXTMATE_DEBUG"]
|
|
1546
|
+
};
|
|
1547
|
+
var AttributedScopeStack = class _AttributedScopeStack {
|
|
1548
|
+
/**
|
|
1549
|
+
* Invariant:
|
|
1550
|
+
* ```
|
|
1551
|
+
* if (parent && !scopePath.extends(parent.scopePath)) {
|
|
1552
|
+
* throw new Error();
|
|
1553
|
+
* }
|
|
1554
|
+
* ```
|
|
1555
|
+
*/
|
|
1556
|
+
constructor(parent, scopePath, tokenAttributes) {
|
|
1557
|
+
this.parent = parent;
|
|
1558
|
+
this.scopePath = scopePath;
|
|
1559
|
+
this.tokenAttributes = tokenAttributes;
|
|
1560
|
+
}
|
|
1561
|
+
static fromExtension(namesScopeList, contentNameScopesList) {
|
|
1562
|
+
let current = namesScopeList;
|
|
1563
|
+
let scopeNames = namesScopeList?.scopePath ?? null;
|
|
1564
|
+
for (const frame of contentNameScopesList) {
|
|
1565
|
+
scopeNames = ScopeStack.push(scopeNames, frame.scopeNames);
|
|
1566
|
+
current = new _AttributedScopeStack(current, scopeNames, frame.encodedTokenAttributes);
|
|
1567
|
+
}
|
|
1568
|
+
return current;
|
|
1569
|
+
}
|
|
1570
|
+
static createRoot(scopeName, tokenAttributes) {
|
|
1571
|
+
return new _AttributedScopeStack(null, new ScopeStack(null, scopeName), tokenAttributes);
|
|
1572
|
+
}
|
|
1573
|
+
static createRootAndLookUpScopeName(scopeName, tokenAttributes, grammar) {
|
|
1574
|
+
const rawRootMetadata = grammar.getMetadataForScope(scopeName);
|
|
1575
|
+
const scopePath = new ScopeStack(null, scopeName);
|
|
1576
|
+
const rootStyle = grammar.themeProvider.themeMatch(scopePath);
|
|
1577
|
+
const resolvedTokenAttributes = _AttributedScopeStack.mergeAttributes(
|
|
1578
|
+
tokenAttributes,
|
|
1579
|
+
rawRootMetadata,
|
|
1580
|
+
rootStyle
|
|
1581
|
+
);
|
|
1582
|
+
return new _AttributedScopeStack(null, scopePath, resolvedTokenAttributes);
|
|
1583
|
+
}
|
|
1584
|
+
get scopeName() {
|
|
1585
|
+
return this.scopePath.scopeName;
|
|
1586
|
+
}
|
|
1587
|
+
toString() {
|
|
1588
|
+
return this.getScopeNames().join(" ");
|
|
1589
|
+
}
|
|
1590
|
+
equals(other) {
|
|
1591
|
+
return _AttributedScopeStack.equals(this, other);
|
|
1592
|
+
}
|
|
1593
|
+
static equals(a, b) {
|
|
1594
|
+
do {
|
|
1595
|
+
if (a === b) {
|
|
1596
|
+
return true;
|
|
1597
|
+
}
|
|
1598
|
+
if (!a && !b) {
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
if (!a || !b) {
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1604
|
+
if (a.scopeName !== b.scopeName || a.tokenAttributes !== b.tokenAttributes) {
|
|
1605
|
+
return false;
|
|
1606
|
+
}
|
|
1607
|
+
a = a.parent;
|
|
1608
|
+
b = b.parent;
|
|
1609
|
+
} while (true);
|
|
1610
|
+
}
|
|
1611
|
+
static mergeAttributes(existingTokenAttributes, basicScopeAttributes, styleAttributes) {
|
|
1612
|
+
let fontStyle = -1;
|
|
1613
|
+
let foreground = 0;
|
|
1614
|
+
let background = 0;
|
|
1615
|
+
if (styleAttributes !== null) {
|
|
1616
|
+
fontStyle = styleAttributes.fontStyle;
|
|
1617
|
+
foreground = styleAttributes.foregroundId;
|
|
1618
|
+
background = styleAttributes.backgroundId;
|
|
1619
|
+
}
|
|
1620
|
+
return EncodedTokenMetadata.set(
|
|
1621
|
+
existingTokenAttributes,
|
|
1622
|
+
basicScopeAttributes.languageId,
|
|
1623
|
+
basicScopeAttributes.tokenType,
|
|
1624
|
+
null,
|
|
1625
|
+
fontStyle,
|
|
1626
|
+
foreground,
|
|
1627
|
+
background
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
pushAttributed(scopePath, grammar) {
|
|
1631
|
+
if (scopePath === null) {
|
|
1632
|
+
return this;
|
|
1633
|
+
}
|
|
1634
|
+
if (scopePath.indexOf(" ") === -1) {
|
|
1635
|
+
return _AttributedScopeStack._pushAttributed(this, scopePath, grammar);
|
|
1636
|
+
}
|
|
1637
|
+
const scopes = scopePath.split(/ /g);
|
|
1638
|
+
let result = this;
|
|
1639
|
+
for (const scope of scopes) {
|
|
1640
|
+
result = _AttributedScopeStack._pushAttributed(result, scope, grammar);
|
|
1641
|
+
}
|
|
1642
|
+
return result;
|
|
1643
|
+
}
|
|
1644
|
+
static _pushAttributed(target, scopeName, grammar) {
|
|
1645
|
+
const rawMetadata = grammar.getMetadataForScope(scopeName);
|
|
1646
|
+
const newPath = target.scopePath.push(scopeName);
|
|
1647
|
+
const scopeThemeMatchResult = grammar.themeProvider.themeMatch(newPath);
|
|
1648
|
+
const metadata = _AttributedScopeStack.mergeAttributes(
|
|
1649
|
+
target.tokenAttributes,
|
|
1650
|
+
rawMetadata,
|
|
1651
|
+
scopeThemeMatchResult
|
|
1652
|
+
);
|
|
1653
|
+
return new _AttributedScopeStack(target, newPath, metadata);
|
|
1654
|
+
}
|
|
1655
|
+
getScopeNames() {
|
|
1656
|
+
return this.scopePath.getSegments();
|
|
1657
|
+
}
|
|
1658
|
+
getExtensionIfDefined(base) {
|
|
1659
|
+
const result = [];
|
|
1660
|
+
let self = this;
|
|
1661
|
+
while (self && self !== base) {
|
|
1662
|
+
result.push({
|
|
1663
|
+
encodedTokenAttributes: self.tokenAttributes,
|
|
1664
|
+
scopeNames: self.scopePath.getExtensionIfDefined(self.parent?.scopePath ?? null)
|
|
1665
|
+
});
|
|
1666
|
+
self = self.parent;
|
|
1667
|
+
}
|
|
1668
|
+
return self === base ? result.reverse() : void 0;
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
var StateStackImpl = class _StateStackImpl {
|
|
1672
|
+
/**
|
|
1673
|
+
* Invariant:
|
|
1674
|
+
* ```
|
|
1675
|
+
* if (contentNameScopesList !== nameScopesList && contentNameScopesList?.parent !== nameScopesList) {
|
|
1676
|
+
* throw new Error();
|
|
1677
|
+
* }
|
|
1678
|
+
* if (this.parent && !nameScopesList.extends(this.parent.contentNameScopesList)) {
|
|
1679
|
+
* throw new Error();
|
|
1680
|
+
* }
|
|
1681
|
+
* ```
|
|
1682
|
+
*/
|
|
1683
|
+
constructor(parent, ruleId, enterPos, anchorPos, beginRuleCapturedEOL, endRule, nameScopesList, contentNameScopesList) {
|
|
1684
|
+
this.parent = parent;
|
|
1685
|
+
this.ruleId = ruleId;
|
|
1686
|
+
this.beginRuleCapturedEOL = beginRuleCapturedEOL;
|
|
1687
|
+
this.endRule = endRule;
|
|
1688
|
+
this.nameScopesList = nameScopesList;
|
|
1689
|
+
this.contentNameScopesList = contentNameScopesList;
|
|
1690
|
+
this.depth = this.parent ? this.parent.depth + 1 : 1;
|
|
1691
|
+
this._enterPos = enterPos;
|
|
1692
|
+
this._anchorPos = anchorPos;
|
|
1693
|
+
}
|
|
1694
|
+
_stackElementBrand = void 0;
|
|
1695
|
+
// TODO remove me
|
|
1696
|
+
static NULL = new _StateStackImpl(
|
|
1697
|
+
null,
|
|
1698
|
+
0,
|
|
1699
|
+
0,
|
|
1700
|
+
0,
|
|
1701
|
+
false,
|
|
1702
|
+
null,
|
|
1703
|
+
null,
|
|
1704
|
+
null
|
|
1705
|
+
);
|
|
1706
|
+
/**
|
|
1707
|
+
* The position on the current line where this state was pushed.
|
|
1708
|
+
* This is relevant only while tokenizing a line, to detect endless loops.
|
|
1709
|
+
* Its value is meaningless across lines.
|
|
1710
|
+
*/
|
|
1711
|
+
_enterPos;
|
|
1712
|
+
/**
|
|
1713
|
+
* The captured anchor position when this stack element was pushed.
|
|
1714
|
+
* This is relevant only while tokenizing a line, to restore the anchor position when popping.
|
|
1715
|
+
* Its value is meaningless across lines.
|
|
1716
|
+
*/
|
|
1717
|
+
_anchorPos;
|
|
1718
|
+
/**
|
|
1719
|
+
* The depth of the stack.
|
|
1720
|
+
*/
|
|
1721
|
+
depth;
|
|
1722
|
+
equals(other) {
|
|
1723
|
+
if (other === null) {
|
|
1724
|
+
return false;
|
|
1725
|
+
}
|
|
1726
|
+
return _StateStackImpl._equals(this, other);
|
|
1727
|
+
}
|
|
1728
|
+
static _equals(a, b) {
|
|
1729
|
+
if (a === b) {
|
|
1730
|
+
return true;
|
|
1731
|
+
}
|
|
1732
|
+
if (!this._structuralEquals(a, b)) {
|
|
1733
|
+
return false;
|
|
1734
|
+
}
|
|
1735
|
+
return AttributedScopeStack.equals(a.contentNameScopesList, b.contentNameScopesList);
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* A structural equals check. Does not take into account `scopes`.
|
|
1739
|
+
*/
|
|
1740
|
+
static _structuralEquals(a, b) {
|
|
1741
|
+
do {
|
|
1742
|
+
if (a === b) {
|
|
1743
|
+
return true;
|
|
1744
|
+
}
|
|
1745
|
+
if (!a && !b) {
|
|
1746
|
+
return true;
|
|
1747
|
+
}
|
|
1748
|
+
if (!a || !b) {
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1751
|
+
if (a.depth !== b.depth || a.ruleId !== b.ruleId || a.endRule !== b.endRule) {
|
|
1752
|
+
return false;
|
|
1753
|
+
}
|
|
1754
|
+
a = a.parent;
|
|
1755
|
+
b = b.parent;
|
|
1756
|
+
} while (true);
|
|
1757
|
+
}
|
|
1758
|
+
clone() {
|
|
1759
|
+
return this;
|
|
1760
|
+
}
|
|
1761
|
+
static _reset(el) {
|
|
1762
|
+
while (el) {
|
|
1763
|
+
el._enterPos = -1;
|
|
1764
|
+
el._anchorPos = -1;
|
|
1765
|
+
el = el.parent;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
reset() {
|
|
1769
|
+
_StateStackImpl._reset(this);
|
|
1770
|
+
}
|
|
1771
|
+
pop() {
|
|
1772
|
+
return this.parent;
|
|
1773
|
+
}
|
|
1774
|
+
safePop() {
|
|
1775
|
+
if (this.parent) {
|
|
1776
|
+
return this.parent;
|
|
1777
|
+
}
|
|
1778
|
+
return this;
|
|
1779
|
+
}
|
|
1780
|
+
push(ruleId, enterPos, anchorPos, beginRuleCapturedEOL, endRule, nameScopesList, contentNameScopesList) {
|
|
1781
|
+
return new _StateStackImpl(
|
|
1782
|
+
this,
|
|
1783
|
+
ruleId,
|
|
1784
|
+
enterPos,
|
|
1785
|
+
anchorPos,
|
|
1786
|
+
beginRuleCapturedEOL,
|
|
1787
|
+
endRule,
|
|
1788
|
+
nameScopesList,
|
|
1789
|
+
contentNameScopesList
|
|
1790
|
+
);
|
|
1791
|
+
}
|
|
1792
|
+
getEnterPos() {
|
|
1793
|
+
return this._enterPos;
|
|
1794
|
+
}
|
|
1795
|
+
getAnchorPos() {
|
|
1796
|
+
return this._anchorPos;
|
|
1797
|
+
}
|
|
1798
|
+
getRule(grammar) {
|
|
1799
|
+
return grammar.getRule(this.ruleId);
|
|
1800
|
+
}
|
|
1801
|
+
toString() {
|
|
1802
|
+
const r = [];
|
|
1803
|
+
this._writeString(r, 0);
|
|
1804
|
+
return "[" + r.join(",") + "]";
|
|
1805
|
+
}
|
|
1806
|
+
_writeString(res, outIndex) {
|
|
1807
|
+
if (this.parent) {
|
|
1808
|
+
outIndex = this.parent._writeString(res, outIndex);
|
|
1809
|
+
}
|
|
1810
|
+
res[outIndex++] = `(${this.ruleId}, ${this.nameScopesList?.toString()}, ${this.contentNameScopesList?.toString()})`;
|
|
1811
|
+
return outIndex;
|
|
1812
|
+
}
|
|
1813
|
+
withContentNameScopesList(contentNameScopeStack) {
|
|
1814
|
+
if (this.contentNameScopesList === contentNameScopeStack) {
|
|
1815
|
+
return this;
|
|
1816
|
+
}
|
|
1817
|
+
return this.parent.push(
|
|
1818
|
+
this.ruleId,
|
|
1819
|
+
this._enterPos,
|
|
1820
|
+
this._anchorPos,
|
|
1821
|
+
this.beginRuleCapturedEOL,
|
|
1822
|
+
this.endRule,
|
|
1823
|
+
this.nameScopesList,
|
|
1824
|
+
contentNameScopeStack
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
withEndRule(endRule) {
|
|
1828
|
+
if (this.endRule === endRule) {
|
|
1829
|
+
return this;
|
|
1830
|
+
}
|
|
1831
|
+
return new _StateStackImpl(
|
|
1832
|
+
this.parent,
|
|
1833
|
+
this.ruleId,
|
|
1834
|
+
this._enterPos,
|
|
1835
|
+
this._anchorPos,
|
|
1836
|
+
this.beginRuleCapturedEOL,
|
|
1837
|
+
endRule,
|
|
1838
|
+
this.nameScopesList,
|
|
1839
|
+
this.contentNameScopesList
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
// Used to warn of endless loops
|
|
1843
|
+
hasSameRuleAs(other) {
|
|
1844
|
+
let el = this;
|
|
1845
|
+
while (el && el._enterPos === other._enterPos) {
|
|
1846
|
+
if (el.ruleId === other.ruleId) {
|
|
1847
|
+
return true;
|
|
1848
|
+
}
|
|
1849
|
+
el = el.parent;
|
|
1850
|
+
}
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
toStateStackFrame() {
|
|
1854
|
+
return {
|
|
1855
|
+
ruleId: ruleIdToNumber(this.ruleId),
|
|
1856
|
+
beginRuleCapturedEOL: this.beginRuleCapturedEOL,
|
|
1857
|
+
endRule: this.endRule,
|
|
1858
|
+
nameScopesList: this.nameScopesList?.getExtensionIfDefined(this.parent?.nameScopesList ?? null) ?? [],
|
|
1859
|
+
contentNameScopesList: this.contentNameScopesList?.getExtensionIfDefined(this.nameScopesList) ?? []
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
static pushFrame(self, frame) {
|
|
1863
|
+
const namesScopeList = AttributedScopeStack.fromExtension(self?.nameScopesList ?? null, frame.nameScopesList);
|
|
1864
|
+
return new _StateStackImpl(
|
|
1865
|
+
self,
|
|
1866
|
+
ruleIdFromNumber(frame.ruleId),
|
|
1867
|
+
frame.enterPos ?? -1,
|
|
1868
|
+
frame.anchorPos ?? -1,
|
|
1869
|
+
frame.beginRuleCapturedEOL,
|
|
1870
|
+
frame.endRule,
|
|
1871
|
+
namesScopeList,
|
|
1872
|
+
AttributedScopeStack.fromExtension(namesScopeList, frame.contentNameScopesList)
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
var INITIAL = StateStackImpl.NULL;
|
|
1877
|
+
|
|
1878
|
+
// ../../node_modules/.pnpm/@shikijs+core@3.21.0/node_modules/@shikijs/core/dist/index.mjs
|
|
1879
|
+
function getTokenStyleObject(token) {
|
|
1880
|
+
const styles = {};
|
|
1881
|
+
if (token.color)
|
|
1882
|
+
styles.color = token.color;
|
|
1883
|
+
if (token.bgColor)
|
|
1884
|
+
styles["background-color"] = token.bgColor;
|
|
1885
|
+
if (token.fontStyle) {
|
|
1886
|
+
if (token.fontStyle & FontStyle.Italic)
|
|
1887
|
+
styles["font-style"] = "italic";
|
|
1888
|
+
if (token.fontStyle & FontStyle.Bold)
|
|
1889
|
+
styles["font-weight"] = "bold";
|
|
1890
|
+
const decorations = [];
|
|
1891
|
+
if (token.fontStyle & FontStyle.Underline)
|
|
1892
|
+
decorations.push("underline");
|
|
1893
|
+
if (token.fontStyle & FontStyle.Strikethrough)
|
|
1894
|
+
decorations.push("line-through");
|
|
1895
|
+
if (decorations.length)
|
|
1896
|
+
styles["text-decoration"] = decorations.join(" ");
|
|
1897
|
+
}
|
|
1898
|
+
return styles;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// src/components/CachedCodeRenderer.tsx
|
|
1902
|
+
import { useEffect as useEffect7, useRef as useRef7, useState as useState7, forwardRef, useImperativeHandle } from "react";
|
|
1903
|
+
import { CodeToTokenTransformStream } from "shiki-stream";
|
|
1904
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1905
|
+
var CachedCodeRenderer = forwardRef(
|
|
1906
|
+
function CachedCodeRenderer2({ code, lang, theme, highlighter, onStreamStart, onStreamEnd, onStreamError }, ref) {
|
|
1907
|
+
const [hasStreamError, setHasStreamError] = useState7(false);
|
|
1908
|
+
const [tokens, setTokens] = useState7([]);
|
|
1909
|
+
const streamRef = useRef7({
|
|
1910
|
+
controller: null,
|
|
1911
|
+
index: 0,
|
|
1912
|
+
initialized: false,
|
|
1913
|
+
streamConsumed: false
|
|
1914
|
+
});
|
|
1915
|
+
useImperativeHandle(ref, () => ({
|
|
1916
|
+
reset: () => {
|
|
1917
|
+
setHasStreamError(false);
|
|
1918
|
+
setTokens([]);
|
|
1919
|
+
streamRef.current.index = 0;
|
|
1920
|
+
}
|
|
1921
|
+
}));
|
|
1922
|
+
useEffect7(() => {
|
|
1923
|
+
if (streamRef.current.initialized) return;
|
|
1924
|
+
streamRef.current.initialized = true;
|
|
1925
|
+
const textStream = new ReadableStream({
|
|
1926
|
+
start(controller) {
|
|
1927
|
+
streamRef.current.controller = controller;
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
let tokenStream = null;
|
|
1931
|
+
try {
|
|
1932
|
+
tokenStream = textStream.pipeThrough(
|
|
1933
|
+
new CodeToTokenTransformStream({
|
|
1934
|
+
highlighter,
|
|
1935
|
+
lang,
|
|
1936
|
+
theme,
|
|
1937
|
+
allowRecalls: true
|
|
1938
|
+
})
|
|
1939
|
+
);
|
|
1940
|
+
} catch (error) {
|
|
1941
|
+
console.error("Failed to create token stream:", error);
|
|
1942
|
+
setHasStreamError(true);
|
|
1943
|
+
onStreamError?.();
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
let started = false;
|
|
1947
|
+
let tokenCount = 0;
|
|
1948
|
+
tokenStream.pipeTo(new WritableStream({
|
|
1949
|
+
write(token) {
|
|
1950
|
+
if (!started) {
|
|
1951
|
+
started = true;
|
|
1952
|
+
onStreamStart?.();
|
|
1953
|
+
}
|
|
1954
|
+
if ("recall" in token) {
|
|
1955
|
+
setTokens((prev) => {
|
|
1956
|
+
const newTokens = [...prev];
|
|
1957
|
+
newTokens.splice(newTokens.length - token.recall, token.recall);
|
|
1958
|
+
return newTokens;
|
|
1959
|
+
});
|
|
1960
|
+
} else {
|
|
1961
|
+
setTokens((prev) => [...prev, token]);
|
|
1962
|
+
}
|
|
1963
|
+
tokenCount++;
|
|
1964
|
+
},
|
|
1965
|
+
close: () => {
|
|
1966
|
+
console.log(`[React CodeRenderer] Stream completed, total tokens: ${tokenCount}`);
|
|
1967
|
+
onStreamEnd?.();
|
|
1968
|
+
}
|
|
1969
|
+
})).catch((error) => {
|
|
1970
|
+
console.error("Stream error:", error);
|
|
1971
|
+
setHasStreamError(true);
|
|
1972
|
+
onStreamError?.();
|
|
1973
|
+
});
|
|
1974
|
+
streamRef.current.streamConsumed = true;
|
|
1975
|
+
}, []);
|
|
1976
|
+
useEffect7(() => {
|
|
1977
|
+
const { controller, index } = streamRef.current;
|
|
1978
|
+
if (!controller || hasStreamError) return;
|
|
1979
|
+
if (code.length > index) {
|
|
1980
|
+
const incremental = code.slice(index);
|
|
1981
|
+
try {
|
|
1982
|
+
controller.enqueue(incremental);
|
|
1983
|
+
streamRef.current.index = code.length;
|
|
1984
|
+
} catch {
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}, [code, hasStreamError]);
|
|
1988
|
+
if (hasStreamError) {
|
|
1989
|
+
return /* @__PURE__ */ jsx10("pre", { className: "shiki incremark-code-stream", children: /* @__PURE__ */ jsx10("code", { children: code }) });
|
|
1990
|
+
}
|
|
1991
|
+
return /* @__PURE__ */ jsx10("pre", { className: "shiki incremark-code-stream", children: /* @__PURE__ */ jsx10("code", { children: tokens.map((token) => {
|
|
1992
|
+
const styleObj = token.htmlStyle || getTokenStyleObject(token);
|
|
1993
|
+
const reactStyle = {};
|
|
1994
|
+
if (typeof styleObj === "string") {
|
|
1995
|
+
styleObj.split(";").forEach((rule) => {
|
|
1996
|
+
const colonIndex = rule.indexOf(":");
|
|
1997
|
+
if (colonIndex > 0) {
|
|
1998
|
+
const key = rule.slice(0, colonIndex).trim();
|
|
1999
|
+
const value = rule.slice(colonIndex + 1).trim();
|
|
2000
|
+
if (key && value) {
|
|
2001
|
+
const camelKey = key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
2002
|
+
reactStyle[camelKey] = value;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
} else if (styleObj && typeof styleObj === "object") {
|
|
2007
|
+
for (const [key, value] of Object.entries(styleObj)) {
|
|
2008
|
+
const camelKey = key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
2009
|
+
reactStyle[camelKey] = value;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
return /* @__PURE__ */ jsx10("span", { style: reactStyle, children: token.content }, objectId(token));
|
|
2013
|
+
}) }) });
|
|
2014
|
+
}
|
|
2015
|
+
);
|
|
2016
|
+
|
|
1231
2017
|
// src/components/IncremarkCodeDefault.tsx
|
|
1232
|
-
import { jsx as
|
|
2018
|
+
import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1233
2019
|
var IncremarkCodeDefault = ({
|
|
1234
2020
|
node,
|
|
1235
2021
|
theme = "github-dark",
|
|
1236
2022
|
fallbackTheme = "github-dark",
|
|
1237
|
-
disableHighlight = false
|
|
2023
|
+
disableHighlight = false,
|
|
2024
|
+
blockStatus = "pending"
|
|
1238
2025
|
}) => {
|
|
1239
|
-
const [copied, setCopied] =
|
|
1240
|
-
const [
|
|
1241
|
-
const language = node.lang || "text";
|
|
1242
|
-
const code = node.value;
|
|
2026
|
+
const [copied, setCopied] = useState8(false);
|
|
2027
|
+
const [isLanguageLoaded, setIsLanguageLoaded] = useState8(false);
|
|
2028
|
+
const language = useMemo5(() => node.lang || "text", [node.lang]);
|
|
2029
|
+
const code = useMemo5(() => node.value, [node.value]);
|
|
1243
2030
|
const { t } = useLocale();
|
|
1244
|
-
const {
|
|
1245
|
-
const
|
|
2031
|
+
const { highlighterInfo, initHighlighter } = useShiki(theme);
|
|
2032
|
+
const shouldEnableHighlight = useMemo5(() => {
|
|
2033
|
+
return !disableHighlight && code && code.length > 0;
|
|
2034
|
+
}, [disableHighlight, code]);
|
|
2035
|
+
useEffect8(() => {
|
|
2036
|
+
const loadLanguageIfNeeded = async () => {
|
|
2037
|
+
if (!shouldEnableHighlight) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
if (!highlighterInfo) {
|
|
2041
|
+
await initHighlighter();
|
|
2042
|
+
} else if (language && language !== "text") {
|
|
2043
|
+
if (!highlighterInfo.loadedLanguages.has(language)) {
|
|
2044
|
+
try {
|
|
2045
|
+
setIsLanguageLoaded(false);
|
|
2046
|
+
const supportedLangs = highlighterInfo.highlighter.getLoadedLanguages();
|
|
2047
|
+
const bundledLangs = await import("shiki").then((m) => Object.keys(m.bundledLanguages || {}));
|
|
2048
|
+
const isSupported = supportedLangs.includes(language) || bundledLangs.includes(language);
|
|
2049
|
+
if (isSupported) {
|
|
2050
|
+
await highlighterInfo.highlighter.loadLanguage(language);
|
|
2051
|
+
highlighterInfo.loadedLanguages.add(language);
|
|
2052
|
+
}
|
|
2053
|
+
setIsLanguageLoaded(true);
|
|
2054
|
+
} catch {
|
|
2055
|
+
setIsLanguageLoaded(true);
|
|
2056
|
+
}
|
|
2057
|
+
} else {
|
|
2058
|
+
setIsLanguageLoaded(true);
|
|
2059
|
+
}
|
|
2060
|
+
} else {
|
|
2061
|
+
setIsLanguageLoaded(true);
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
loadLanguageIfNeeded();
|
|
2065
|
+
}, [highlighterInfo, language, shouldEnableHighlight, initHighlighter]);
|
|
2066
|
+
const copyTimeoutRef = useRef8(null);
|
|
1246
2067
|
const copyCode = useCallback7(async () => {
|
|
1247
2068
|
if (!isClipboardAvailable2()) return;
|
|
1248
2069
|
try {
|
|
@@ -1255,32 +2076,17 @@ var IncremarkCodeDefault = ({
|
|
|
1255
2076
|
} catch {
|
|
1256
2077
|
}
|
|
1257
2078
|
}, [code]);
|
|
1258
|
-
|
|
2079
|
+
useEffect8(() => {
|
|
1259
2080
|
return () => {
|
|
1260
2081
|
if (copyTimeoutRef.current) {
|
|
1261
2082
|
clearTimeout(copyTimeoutRef.current);
|
|
1262
2083
|
}
|
|
1263
2084
|
};
|
|
1264
2085
|
}, []);
|
|
1265
|
-
const doHighlight = useCallback7(async () => {
|
|
1266
|
-
if (!code || disableHighlight) {
|
|
1267
|
-
setHighlightedHtml("");
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1270
|
-
try {
|
|
1271
|
-
const html = await highlight(code, language, fallbackTheme);
|
|
1272
|
-
setHighlightedHtml(html);
|
|
1273
|
-
} catch {
|
|
1274
|
-
setHighlightedHtml("");
|
|
1275
|
-
}
|
|
1276
|
-
}, [code, language, fallbackTheme, disableHighlight, highlight]);
|
|
1277
|
-
useEffect6(() => {
|
|
1278
|
-
doHighlight();
|
|
1279
|
-
}, [doHighlight]);
|
|
1280
2086
|
return /* @__PURE__ */ jsxs3("div", { className: "incremark-code", children: [
|
|
1281
2087
|
/* @__PURE__ */ jsxs3("div", { className: "code-header", children: [
|
|
1282
|
-
/* @__PURE__ */
|
|
1283
|
-
/* @__PURE__ */
|
|
2088
|
+
/* @__PURE__ */ jsx11("span", { className: "language", children: language }),
|
|
2089
|
+
/* @__PURE__ */ jsx11(
|
|
1284
2090
|
"button",
|
|
1285
2091
|
{
|
|
1286
2092
|
className: "code-btn",
|
|
@@ -1288,16 +2094,27 @@ var IncremarkCodeDefault = ({
|
|
|
1288
2094
|
type: "button",
|
|
1289
2095
|
"aria-label": copied ? t("code.copied") : t("code.copy"),
|
|
1290
2096
|
title: copied ? "Copied!" : "Copy",
|
|
1291
|
-
children: /* @__PURE__ */
|
|
2097
|
+
children: /* @__PURE__ */ jsx11(SvgIcon, { svg: copied ? LucideCopyCheck2 : LucideCopy2 })
|
|
1292
2098
|
}
|
|
1293
2099
|
)
|
|
1294
2100
|
] }),
|
|
1295
|
-
/* @__PURE__ */
|
|
2101
|
+
/* @__PURE__ */ jsx11("div", { className: "code-content", children: /* @__PURE__ */ jsx11("div", { className: "shiki-wrapper", children: shouldEnableHighlight && highlighterInfo && isLanguageLoaded ? /* @__PURE__ */ jsx11(
|
|
2102
|
+
CachedCodeRenderer,
|
|
2103
|
+
{
|
|
2104
|
+
code,
|
|
2105
|
+
lang: language,
|
|
2106
|
+
theme,
|
|
2107
|
+
highlighter: highlighterInfo.highlighter
|
|
2108
|
+
}
|
|
2109
|
+
) : (
|
|
2110
|
+
// 无高亮模式(禁用高亮、无代码内容、或语言未加载完成时显示)
|
|
2111
|
+
/* @__PURE__ */ jsx11("pre", { className: "code-fallback", children: /* @__PURE__ */ jsx11("code", { children: code }) })
|
|
2112
|
+
) }) })
|
|
1296
2113
|
] });
|
|
1297
2114
|
};
|
|
1298
2115
|
|
|
1299
2116
|
// src/components/IncremarkCode.tsx
|
|
1300
|
-
import { jsx as
|
|
2117
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
1301
2118
|
var IncremarkCode = ({
|
|
1302
2119
|
node,
|
|
1303
2120
|
theme = "github-dark",
|
|
@@ -1305,14 +2122,14 @@ var IncremarkCode = ({
|
|
|
1305
2122
|
disableHighlight = false,
|
|
1306
2123
|
mermaidDelay = 500,
|
|
1307
2124
|
customCodeBlocks,
|
|
1308
|
-
blockStatus = "
|
|
2125
|
+
blockStatus = "pending",
|
|
1309
2126
|
codeBlockConfigs,
|
|
1310
2127
|
defaultCodeComponent: DefaultCodeComponent = IncremarkCodeDefault
|
|
1311
2128
|
}) => {
|
|
1312
2129
|
const language = node.lang || "text";
|
|
1313
2130
|
const code = node.value;
|
|
1314
2131
|
const isMermaid = language === "mermaid";
|
|
1315
|
-
const CustomCodeBlock =
|
|
2132
|
+
const CustomCodeBlock = React9.useMemo(() => {
|
|
1316
2133
|
const component = customCodeBlocks?.[language];
|
|
1317
2134
|
if (!component) return null;
|
|
1318
2135
|
const config = codeBlockConfigs?.[language];
|
|
@@ -1326,7 +2143,7 @@ var IncremarkCode = ({
|
|
|
1326
2143
|
}, [customCodeBlocks, language, blockStatus, codeBlockConfigs]);
|
|
1327
2144
|
if (CustomCodeBlock) {
|
|
1328
2145
|
const config = codeBlockConfigs?.[language];
|
|
1329
|
-
return /* @__PURE__ */
|
|
2146
|
+
return /* @__PURE__ */ jsx12(
|
|
1330
2147
|
CustomCodeBlock,
|
|
1331
2148
|
{
|
|
1332
2149
|
codeStr: code,
|
|
@@ -1337,7 +2154,7 @@ var IncremarkCode = ({
|
|
|
1337
2154
|
);
|
|
1338
2155
|
}
|
|
1339
2156
|
if (isMermaid) {
|
|
1340
|
-
return /* @__PURE__ */
|
|
2157
|
+
return /* @__PURE__ */ jsx12(
|
|
1341
2158
|
IncremarkCodeMermaid,
|
|
1342
2159
|
{
|
|
1343
2160
|
node,
|
|
@@ -1345,20 +2162,21 @@ var IncremarkCode = ({
|
|
|
1345
2162
|
}
|
|
1346
2163
|
);
|
|
1347
2164
|
}
|
|
1348
|
-
return /* @__PURE__ */
|
|
2165
|
+
return /* @__PURE__ */ jsx12(
|
|
1349
2166
|
DefaultCodeComponent,
|
|
1350
2167
|
{
|
|
1351
2168
|
node,
|
|
1352
2169
|
theme,
|
|
1353
2170
|
fallbackTheme,
|
|
1354
|
-
disableHighlight
|
|
2171
|
+
disableHighlight,
|
|
2172
|
+
blockStatus
|
|
1355
2173
|
}
|
|
1356
2174
|
);
|
|
1357
2175
|
};
|
|
1358
2176
|
|
|
1359
2177
|
// src/components/IncremarkList.tsx
|
|
1360
|
-
import
|
|
1361
|
-
import { jsx as
|
|
2178
|
+
import React10 from "react";
|
|
2179
|
+
import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1362
2180
|
function getItemInlineContent(item) {
|
|
1363
2181
|
const firstChild = item.children[0];
|
|
1364
2182
|
if (firstChild?.type === "paragraph") {
|
|
@@ -1377,13 +2195,13 @@ function getItemBlockChildren(item) {
|
|
|
1377
2195
|
var IncremarkList = ({ node }) => {
|
|
1378
2196
|
const Tag = node.ordered ? "ol" : "ul";
|
|
1379
2197
|
const isTaskList = node.children?.some((item) => item.checked !== null && item.checked !== void 0);
|
|
1380
|
-
return /* @__PURE__ */
|
|
2198
|
+
return /* @__PURE__ */ jsx13(Tag, { className: `incremark-list ${isTaskList ? "task-list" : ""}`, start: node.start || void 0, children: node.children?.map((item, index) => {
|
|
1381
2199
|
const isTaskItem = item.checked !== null && item.checked !== void 0;
|
|
1382
2200
|
const inlineContent = getItemInlineContent(item);
|
|
1383
2201
|
const blockChildren = getItemBlockChildren(item);
|
|
1384
2202
|
if (isTaskItem) {
|
|
1385
|
-
return /* @__PURE__ */
|
|
1386
|
-
/* @__PURE__ */
|
|
2203
|
+
return /* @__PURE__ */ jsx13("li", { className: "incremark-list-item task-item", children: /* @__PURE__ */ jsxs4("label", { className: "task-label", children: [
|
|
2204
|
+
/* @__PURE__ */ jsx13(
|
|
1387
2205
|
"input",
|
|
1388
2206
|
{
|
|
1389
2207
|
type: "checkbox",
|
|
@@ -1392,43 +2210,43 @@ var IncremarkList = ({ node }) => {
|
|
|
1392
2210
|
className: "checkbox"
|
|
1393
2211
|
}
|
|
1394
2212
|
),
|
|
1395
|
-
/* @__PURE__ */
|
|
2213
|
+
/* @__PURE__ */ jsx13("span", { className: "task-content", children: /* @__PURE__ */ jsx13(IncremarkInline, { nodes: inlineContent }) })
|
|
1396
2214
|
] }) }, index);
|
|
1397
2215
|
}
|
|
1398
2216
|
return /* @__PURE__ */ jsxs4("li", { className: "incremark-list-item", children: [
|
|
1399
|
-
/* @__PURE__ */
|
|
1400
|
-
blockChildren.map((child, childIndex) => /* @__PURE__ */
|
|
2217
|
+
/* @__PURE__ */ jsx13(IncremarkInline, { nodes: inlineContent }),
|
|
2218
|
+
blockChildren.map((child, childIndex) => /* @__PURE__ */ jsx13(React10.Fragment, { children: /* @__PURE__ */ jsx13(IncremarkRenderer, { node: child }) }, childIndex))
|
|
1401
2219
|
] }, index);
|
|
1402
2220
|
}) });
|
|
1403
2221
|
};
|
|
1404
2222
|
|
|
1405
2223
|
// src/components/IncremarkBlockquote.tsx
|
|
1406
|
-
import
|
|
1407
|
-
import { jsx as
|
|
2224
|
+
import React11 from "react";
|
|
2225
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1408
2226
|
var IncremarkBlockquote = ({ node }) => {
|
|
1409
|
-
return /* @__PURE__ */
|
|
2227
|
+
return /* @__PURE__ */ jsx14("blockquote", { className: "incremark-blockquote", children: node.children.map((child, index) => /* @__PURE__ */ jsx14(React11.Fragment, { children: /* @__PURE__ */ jsx14(IncremarkRenderer, { node: child }) }, index)) });
|
|
1410
2228
|
};
|
|
1411
2229
|
|
|
1412
2230
|
// src/components/IncremarkTable.tsx
|
|
1413
|
-
import { jsx as
|
|
2231
|
+
import { jsx as jsx15, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1414
2232
|
function getCellContent(cell) {
|
|
1415
2233
|
return cell.children;
|
|
1416
2234
|
}
|
|
1417
2235
|
var IncremarkTable = ({ node }) => {
|
|
1418
|
-
return /* @__PURE__ */
|
|
1419
|
-
/* @__PURE__ */
|
|
2236
|
+
return /* @__PURE__ */ jsx15("div", { className: "incremark-table-wrapper", children: /* @__PURE__ */ jsxs5("table", { className: "incremark-table", children: [
|
|
2237
|
+
/* @__PURE__ */ jsx15("thead", { children: node.children?.[0] && /* @__PURE__ */ jsx15("tr", { children: node.children[0].children.map((cell, cellIndex) => /* @__PURE__ */ jsx15(
|
|
1420
2238
|
"th",
|
|
1421
2239
|
{
|
|
1422
2240
|
className: `incremark-table-align-${node.align?.[cellIndex] || "left"}`,
|
|
1423
|
-
children: /* @__PURE__ */
|
|
2241
|
+
children: /* @__PURE__ */ jsx15(IncremarkInline, { nodes: getCellContent(cell) })
|
|
1424
2242
|
},
|
|
1425
2243
|
cellIndex
|
|
1426
2244
|
)) }) }),
|
|
1427
|
-
/* @__PURE__ */
|
|
2245
|
+
/* @__PURE__ */ jsx15("tbody", { children: node.children?.slice(1).map((row, rowIndex) => /* @__PURE__ */ jsx15("tr", { children: row.children.map((cell, cellIndex) => /* @__PURE__ */ jsx15(
|
|
1428
2246
|
"td",
|
|
1429
2247
|
{
|
|
1430
2248
|
className: `incremark-table-align-${node.align?.[cellIndex] || "left"}`,
|
|
1431
|
-
children: /* @__PURE__ */
|
|
2249
|
+
children: /* @__PURE__ */ jsx15(IncremarkInline, { nodes: getCellContent(cell) })
|
|
1432
2250
|
},
|
|
1433
2251
|
cellIndex
|
|
1434
2252
|
)) }, rowIndex)) })
|
|
@@ -1436,13 +2254,13 @@ var IncremarkTable = ({ node }) => {
|
|
|
1436
2254
|
};
|
|
1437
2255
|
|
|
1438
2256
|
// src/components/IncremarkThematicBreak.tsx
|
|
1439
|
-
import { jsx as
|
|
2257
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
1440
2258
|
var IncremarkThematicBreak = () => {
|
|
1441
|
-
return /* @__PURE__ */
|
|
2259
|
+
return /* @__PURE__ */ jsx16("hr", { className: "incremark-hr" });
|
|
1442
2260
|
};
|
|
1443
2261
|
|
|
1444
2262
|
// src/components/IncremarkContainer.tsx
|
|
1445
|
-
import { jsx as
|
|
2263
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
1446
2264
|
function parseOptions(attributes) {
|
|
1447
2265
|
if (!attributes) return {};
|
|
1448
2266
|
const options = {};
|
|
@@ -1460,22 +2278,22 @@ var IncremarkContainer = ({ node, customContainers }) => {
|
|
|
1460
2278
|
const options = parseOptions(node.attributes);
|
|
1461
2279
|
const CustomContainer = customContainers?.[containerName];
|
|
1462
2280
|
if (CustomContainer) {
|
|
1463
|
-
return /* @__PURE__ */
|
|
2281
|
+
return /* @__PURE__ */ jsx17(CustomContainer, { name: containerName, options, children: node.children?.map((child, index) => /* @__PURE__ */ jsx17(IncremarkRenderer, { node: child }, index)) });
|
|
1464
2282
|
}
|
|
1465
|
-
return /* @__PURE__ */
|
|
2283
|
+
return /* @__PURE__ */ jsx17("div", { className: `incremark-container incremark-container-${containerName}`, children: node.children && node.children.length > 0 && /* @__PURE__ */ jsx17("div", { className: "incremark-container-content", children: node.children.map((child, index) => /* @__PURE__ */ jsx17(IncremarkRenderer, { node: child }, index)) }) });
|
|
1466
2284
|
};
|
|
1467
2285
|
|
|
1468
2286
|
// src/components/IncremarkDefault.tsx
|
|
1469
|
-
import { jsx as
|
|
2287
|
+
import { jsx as jsx18, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1470
2288
|
var IncremarkDefault = ({ node }) => {
|
|
1471
2289
|
return /* @__PURE__ */ jsxs6("div", { className: "incremark-default", children: [
|
|
1472
|
-
/* @__PURE__ */
|
|
1473
|
-
/* @__PURE__ */
|
|
2290
|
+
/* @__PURE__ */ jsx18("span", { className: "type-badge", children: node.type }),
|
|
2291
|
+
/* @__PURE__ */ jsx18("pre", { children: JSON.stringify(node, null, 2) })
|
|
1474
2292
|
] });
|
|
1475
2293
|
};
|
|
1476
2294
|
|
|
1477
2295
|
// src/components/IncremarkRenderer.tsx
|
|
1478
|
-
import { jsx as
|
|
2296
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
1479
2297
|
var defaultComponents = {
|
|
1480
2298
|
heading: IncremarkHeading,
|
|
1481
2299
|
paragraph: IncremarkParagraph,
|
|
@@ -1511,10 +2329,10 @@ var IncremarkRenderer = ({
|
|
|
1511
2329
|
return null;
|
|
1512
2330
|
}
|
|
1513
2331
|
if (isHtmlNode2(node)) {
|
|
1514
|
-
return /* @__PURE__ */
|
|
2332
|
+
return /* @__PURE__ */ jsx19("pre", { className: "incremark-html-code", children: /* @__PURE__ */ jsx19("code", { children: node.value }) });
|
|
1515
2333
|
}
|
|
1516
2334
|
if (isContainerNode(node)) {
|
|
1517
|
-
return /* @__PURE__ */
|
|
2335
|
+
return /* @__PURE__ */ jsx19(
|
|
1518
2336
|
IncremarkContainer,
|
|
1519
2337
|
{
|
|
1520
2338
|
node,
|
|
@@ -1523,7 +2341,7 @@ var IncremarkRenderer = ({
|
|
|
1523
2341
|
);
|
|
1524
2342
|
}
|
|
1525
2343
|
if (node.type === "code") {
|
|
1526
|
-
return /* @__PURE__ */
|
|
2344
|
+
return /* @__PURE__ */ jsx19(
|
|
1527
2345
|
IncremarkCode,
|
|
1528
2346
|
{
|
|
1529
2347
|
node,
|
|
@@ -1535,15 +2353,15 @@ var IncremarkRenderer = ({
|
|
|
1535
2353
|
);
|
|
1536
2354
|
}
|
|
1537
2355
|
const Component = getComponent(node.type, components);
|
|
1538
|
-
return /* @__PURE__ */
|
|
2356
|
+
return /* @__PURE__ */ jsx19(Component, { node });
|
|
1539
2357
|
};
|
|
1540
2358
|
|
|
1541
2359
|
// src/components/IncremarkFootnotes.tsx
|
|
1542
|
-
import
|
|
1543
|
-
import { jsx as
|
|
2360
|
+
import React12 from "react";
|
|
2361
|
+
import { jsx as jsx20, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1544
2362
|
var IncremarkFootnotes = () => {
|
|
1545
2363
|
const { footnoteDefinitions, footnoteReferenceOrder } = useDefinitions();
|
|
1546
|
-
const orderedFootnotes =
|
|
2364
|
+
const orderedFootnotes = React12.useMemo(() => {
|
|
1547
2365
|
return footnoteReferenceOrder.map((identifier) => ({
|
|
1548
2366
|
identifier,
|
|
1549
2367
|
definition: footnoteDefinitions[identifier]
|
|
@@ -1553,8 +2371,8 @@ var IncremarkFootnotes = () => {
|
|
|
1553
2371
|
return null;
|
|
1554
2372
|
}
|
|
1555
2373
|
return /* @__PURE__ */ jsxs7("section", { className: "incremark-footnotes", children: [
|
|
1556
|
-
/* @__PURE__ */
|
|
1557
|
-
/* @__PURE__ */
|
|
2374
|
+
/* @__PURE__ */ jsx20("hr", { className: "incremark-footnotes-divider" }),
|
|
2375
|
+
/* @__PURE__ */ jsx20("ol", { className: "incremark-footnotes-list", children: orderedFootnotes.map((item, index) => /* @__PURE__ */ jsxs7(
|
|
1558
2376
|
"li",
|
|
1559
2377
|
{
|
|
1560
2378
|
id: `fn-${item.identifier}`,
|
|
@@ -1565,9 +2383,9 @@ var IncremarkFootnotes = () => {
|
|
|
1565
2383
|
index + 1,
|
|
1566
2384
|
"."
|
|
1567
2385
|
] }),
|
|
1568
|
-
/* @__PURE__ */
|
|
2386
|
+
/* @__PURE__ */ jsx20("div", { className: "incremark-footnote-body", children: item.definition.children.map((child, childIndex) => /* @__PURE__ */ jsx20(IncremarkRenderer, { node: child }, childIndex)) })
|
|
1569
2387
|
] }),
|
|
1570
|
-
/* @__PURE__ */
|
|
2388
|
+
/* @__PURE__ */ jsx20(
|
|
1571
2389
|
"a",
|
|
1572
2390
|
{
|
|
1573
2391
|
href: `#fnref-${item.identifier}`,
|
|
@@ -1584,13 +2402,13 @@ var IncremarkFootnotes = () => {
|
|
|
1584
2402
|
};
|
|
1585
2403
|
|
|
1586
2404
|
// src/components/IncremarkContainerProvider.tsx
|
|
1587
|
-
import { jsx as
|
|
2405
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
1588
2406
|
var IncremarkContainerProvider = ({ children, definitions }) => {
|
|
1589
|
-
return /* @__PURE__ */
|
|
2407
|
+
return /* @__PURE__ */ jsx21(DefinitionsContext.Provider, { value: definitions, children });
|
|
1590
2408
|
};
|
|
1591
2409
|
|
|
1592
2410
|
// src/components/Incremark.tsx
|
|
1593
|
-
import { jsx as
|
|
2411
|
+
import { jsx as jsx22, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1594
2412
|
var Incremark = (props) => {
|
|
1595
2413
|
const {
|
|
1596
2414
|
blocks: propsBlocks,
|
|
@@ -1606,7 +2424,7 @@ var Incremark = (props) => {
|
|
|
1606
2424
|
} = props;
|
|
1607
2425
|
if (incremark) {
|
|
1608
2426
|
const { blocks: blocks2, isDisplayComplete: isDisplayComplete2, _definitionsContextValue } = incremark;
|
|
1609
|
-
return /* @__PURE__ */
|
|
2427
|
+
return /* @__PURE__ */ jsx22(IncremarkContainerProvider, { definitions: _definitionsContextValue, children: /* @__PURE__ */ jsx22(
|
|
1610
2428
|
IncremarkInternal,
|
|
1611
2429
|
{
|
|
1612
2430
|
blocks: blocks2,
|
|
@@ -1623,7 +2441,7 @@ var Incremark = (props) => {
|
|
|
1623
2441
|
}
|
|
1624
2442
|
const blocks = propsBlocks || [];
|
|
1625
2443
|
const isDisplayComplete = propsIsDisplayComplete;
|
|
1626
|
-
return /* @__PURE__ */
|
|
2444
|
+
return /* @__PURE__ */ jsx22(
|
|
1627
2445
|
IncremarkInternal,
|
|
1628
2446
|
{
|
|
1629
2447
|
blocks,
|
|
@@ -1662,7 +2480,7 @@ var IncremarkInternal = ({
|
|
|
1662
2480
|
showBlockStatus && "incremark-show-status",
|
|
1663
2481
|
block.isLastPending && "incremark-last-pending"
|
|
1664
2482
|
].filter(Boolean).join(" ");
|
|
1665
|
-
return /* @__PURE__ */
|
|
2483
|
+
return /* @__PURE__ */ jsx22("div", { className: classes, children: /* @__PURE__ */ jsx22(
|
|
1666
2484
|
IncremarkRenderer,
|
|
1667
2485
|
{
|
|
1668
2486
|
node: block.node,
|
|
@@ -1674,13 +2492,13 @@ var IncremarkInternal = ({
|
|
|
1674
2492
|
}
|
|
1675
2493
|
) }, block.id);
|
|
1676
2494
|
}),
|
|
1677
|
-
isDisplayComplete && /* @__PURE__ */
|
|
2495
|
+
isDisplayComplete && /* @__PURE__ */ jsx22(IncremarkFootnotes, {})
|
|
1678
2496
|
] });
|
|
1679
2497
|
};
|
|
1680
2498
|
|
|
1681
2499
|
// src/components/IncremarkContent.tsx
|
|
1682
|
-
import { useEffect as
|
|
1683
|
-
import { jsx as
|
|
2500
|
+
import { useEffect as useEffect9, useRef as useRef9, useMemo as useMemo6, useCallback as useCallback8 } from "react";
|
|
2501
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
1684
2502
|
var IncremarkContent = (props) => {
|
|
1685
2503
|
const {
|
|
1686
2504
|
stream,
|
|
@@ -1694,7 +2512,7 @@ var IncremarkContent = (props) => {
|
|
|
1694
2512
|
showBlockStatus,
|
|
1695
2513
|
pendingClass
|
|
1696
2514
|
} = props;
|
|
1697
|
-
const initialOptionsRef =
|
|
2515
|
+
const initialOptionsRef = useRef9({
|
|
1698
2516
|
gfm: true,
|
|
1699
2517
|
htmlTree: true,
|
|
1700
2518
|
containers: true,
|
|
@@ -1702,8 +2520,8 @@ var IncremarkContent = (props) => {
|
|
|
1702
2520
|
...incremarkOptions
|
|
1703
2521
|
});
|
|
1704
2522
|
const { blocks, append, finalize, render, reset, updateOptions, isDisplayComplete, markdown, typewriter, _definitionsContextValue } = useIncremark(initialOptionsRef.current);
|
|
1705
|
-
const prevOptionsRef =
|
|
1706
|
-
|
|
2523
|
+
const prevOptionsRef = useRef9(incremarkOptions);
|
|
2524
|
+
useEffect9(() => {
|
|
1707
2525
|
const prev = prevOptionsRef.current;
|
|
1708
2526
|
const current = incremarkOptions;
|
|
1709
2527
|
if (prev === current) return;
|
|
@@ -1725,9 +2543,9 @@ var IncremarkContent = (props) => {
|
|
|
1725
2543
|
typewriter.setOptions(current.typewriter);
|
|
1726
2544
|
}
|
|
1727
2545
|
}, [incremarkOptions, updateOptions, typewriter]);
|
|
1728
|
-
const isStreamMode =
|
|
1729
|
-
const prevContentRef =
|
|
1730
|
-
const isStreamingRef =
|
|
2546
|
+
const isStreamMode = useMemo6(() => typeof stream === "function", [stream]);
|
|
2547
|
+
const prevContentRef = useRef9(void 0);
|
|
2548
|
+
const isStreamingRef = useRef9(false);
|
|
1731
2549
|
const handleStreamInput = useCallback8(async () => {
|
|
1732
2550
|
if (!stream || isStreamingRef.current) return;
|
|
1733
2551
|
isStreamingRef.current = true;
|
|
@@ -1758,7 +2576,7 @@ var IncremarkContent = (props) => {
|
|
|
1758
2576
|
render(newContent);
|
|
1759
2577
|
}
|
|
1760
2578
|
}, [append, render, reset]);
|
|
1761
|
-
|
|
2579
|
+
useEffect9(() => {
|
|
1762
2580
|
if (isStreamMode) {
|
|
1763
2581
|
handleStreamInput();
|
|
1764
2582
|
} else {
|
|
@@ -1766,12 +2584,12 @@ var IncremarkContent = (props) => {
|
|
|
1766
2584
|
}
|
|
1767
2585
|
prevContentRef.current = content;
|
|
1768
2586
|
}, [content, isStreamMode, handleStreamInput, handleContentInput]);
|
|
1769
|
-
|
|
2587
|
+
useEffect9(() => {
|
|
1770
2588
|
if (isFinished && content === markdown) {
|
|
1771
2589
|
finalize();
|
|
1772
2590
|
}
|
|
1773
2591
|
}, [isFinished, content, markdown, finalize]);
|
|
1774
|
-
return /* @__PURE__ */
|
|
2592
|
+
return /* @__PURE__ */ jsx23(IncremarkContainerProvider, { definitions: _definitionsContextValue, children: /* @__PURE__ */ jsx23(
|
|
1775
2593
|
Incremark,
|
|
1776
2594
|
{
|
|
1777
2595
|
blocks,
|
|
@@ -1788,15 +2606,15 @@ var IncremarkContent = (props) => {
|
|
|
1788
2606
|
|
|
1789
2607
|
// src/components/AutoScrollContainer.tsx
|
|
1790
2608
|
import {
|
|
1791
|
-
useRef as
|
|
1792
|
-
useEffect as
|
|
2609
|
+
useRef as useRef10,
|
|
2610
|
+
useEffect as useEffect10,
|
|
1793
2611
|
useCallback as useCallback9,
|
|
1794
|
-
useState as
|
|
1795
|
-
forwardRef,
|
|
1796
|
-
useImperativeHandle
|
|
2612
|
+
useState as useState9,
|
|
2613
|
+
forwardRef as forwardRef2,
|
|
2614
|
+
useImperativeHandle as useImperativeHandle2
|
|
1797
2615
|
} from "react";
|
|
1798
|
-
import { jsx as
|
|
1799
|
-
var AutoScrollContainer =
|
|
2616
|
+
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2617
|
+
var AutoScrollContainer = forwardRef2(
|
|
1800
2618
|
({
|
|
1801
2619
|
children,
|
|
1802
2620
|
enabled = true,
|
|
@@ -1805,10 +2623,10 @@ var AutoScrollContainer = forwardRef(
|
|
|
1805
2623
|
style,
|
|
1806
2624
|
className
|
|
1807
2625
|
}, ref) => {
|
|
1808
|
-
const containerRef =
|
|
1809
|
-
const [isUserScrolledUp, setIsUserScrolledUp] =
|
|
1810
|
-
const lastScrollTopRef =
|
|
1811
|
-
const lastScrollHeightRef =
|
|
2626
|
+
const containerRef = useRef10(null);
|
|
2627
|
+
const [isUserScrolledUp, setIsUserScrolledUp] = useState9(false);
|
|
2628
|
+
const lastScrollTopRef = useRef10(0);
|
|
2629
|
+
const lastScrollHeightRef = useRef10(0);
|
|
1812
2630
|
const isNearBottom = useCallback9(() => {
|
|
1813
2631
|
const container = containerRef.current;
|
|
1814
2632
|
if (!container) return true;
|
|
@@ -1854,14 +2672,14 @@ var AutoScrollContainer = forwardRef(
|
|
|
1854
2672
|
lastScrollTopRef.current = scrollTop;
|
|
1855
2673
|
lastScrollHeightRef.current = scrollHeight;
|
|
1856
2674
|
}, [isNearBottom]);
|
|
1857
|
-
|
|
2675
|
+
useEffect10(() => {
|
|
1858
2676
|
const container = containerRef.current;
|
|
1859
2677
|
if (container) {
|
|
1860
2678
|
lastScrollTopRef.current = container.scrollTop;
|
|
1861
2679
|
lastScrollHeightRef.current = container.scrollHeight;
|
|
1862
2680
|
}
|
|
1863
2681
|
}, []);
|
|
1864
|
-
|
|
2682
|
+
useEffect10(() => {
|
|
1865
2683
|
const container = containerRef.current;
|
|
1866
2684
|
if (!container || !enabled) return;
|
|
1867
2685
|
const observer = new MutationObserver(() => {
|
|
@@ -1884,7 +2702,7 @@ var AutoScrollContainer = forwardRef(
|
|
|
1884
2702
|
});
|
|
1885
2703
|
return () => observer.disconnect();
|
|
1886
2704
|
}, [enabled, isUserScrolledUp, scrollToBottom]);
|
|
1887
|
-
|
|
2705
|
+
useImperativeHandle2(
|
|
1888
2706
|
ref,
|
|
1889
2707
|
() => ({
|
|
1890
2708
|
scrollToBottom: () => scrollToBottom(true),
|
|
@@ -1893,7 +2711,7 @@ var AutoScrollContainer = forwardRef(
|
|
|
1893
2711
|
}),
|
|
1894
2712
|
[scrollToBottom, isUserScrolledUp]
|
|
1895
2713
|
);
|
|
1896
|
-
return /* @__PURE__ */
|
|
2714
|
+
return /* @__PURE__ */ jsx24(
|
|
1897
2715
|
"div",
|
|
1898
2716
|
{
|
|
1899
2717
|
ref: containerRef,
|
|
@@ -1908,21 +2726,21 @@ var AutoScrollContainer = forwardRef(
|
|
|
1908
2726
|
AutoScrollContainer.displayName = "AutoScrollContainer";
|
|
1909
2727
|
|
|
1910
2728
|
// src/ThemeProvider.tsx
|
|
1911
|
-
import { useEffect as
|
|
2729
|
+
import { useEffect as useEffect11, useRef as useRef11 } from "react";
|
|
1912
2730
|
import { applyTheme } from "@incremark/theme";
|
|
1913
|
-
import { jsx as
|
|
2731
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
1914
2732
|
var ThemeProvider = ({
|
|
1915
2733
|
theme,
|
|
1916
2734
|
children,
|
|
1917
2735
|
className = ""
|
|
1918
2736
|
}) => {
|
|
1919
|
-
const containerRef =
|
|
1920
|
-
|
|
2737
|
+
const containerRef = useRef11(null);
|
|
2738
|
+
useEffect11(() => {
|
|
1921
2739
|
if (containerRef.current) {
|
|
1922
2740
|
applyTheme(containerRef.current, theme);
|
|
1923
2741
|
}
|
|
1924
2742
|
}, [theme]);
|
|
1925
|
-
return /* @__PURE__ */
|
|
2743
|
+
return /* @__PURE__ */ jsx25("div", { ref: containerRef, className: `incremark-theme-provider ${className}`.trim(), children });
|
|
1926
2744
|
};
|
|
1927
2745
|
|
|
1928
2746
|
// src/index.ts
|
|
@@ -1935,7 +2753,7 @@ import {
|
|
|
1935
2753
|
codeBlockPlugin,
|
|
1936
2754
|
mermaidPlugin,
|
|
1937
2755
|
imagePlugin,
|
|
1938
|
-
mathPlugin,
|
|
2756
|
+
mathPlugin as mathPlugin2,
|
|
1939
2757
|
thematicBreakPlugin,
|
|
1940
2758
|
defaultPlugins as defaultPlugins2,
|
|
1941
2759
|
allPlugins,
|
|
@@ -1975,7 +2793,7 @@ export {
|
|
|
1975
2793
|
enShared as en,
|
|
1976
2794
|
generateCSSVars,
|
|
1977
2795
|
imagePlugin,
|
|
1978
|
-
mathPlugin,
|
|
2796
|
+
mathPlugin2 as mathPlugin,
|
|
1979
2797
|
mergeTheme,
|
|
1980
2798
|
mermaidPlugin,
|
|
1981
2799
|
sliceAst,
|