@incremark/vue 0.3.2 → 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/dist/index.d.ts +1 -0
- package/dist/index.js +54 -52
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './components';
|
|
|
6
6
|
export { default as ThemeProvider } from './ThemeProvider.vue';
|
|
7
7
|
export { default as ConfigProvider } from './components/ConfigProvider.vue';
|
|
8
8
|
export type { ParsedBlock, IncrementalUpdate, ParserOptions, BlockStatus, Root, RootContent, SourceBlock, DisplayBlock, TransformerPlugin, TransformerOptions, TransformerState, AnimationEffect } from '@incremark/core';
|
|
9
|
+
export type { Root as MdastRoot, Parent, Heading, Paragraph, Code, Blockquote, List, ListItem, Table, TableCell, ThematicBreak, Text, PhrasingContent, InlineCode, Link, LinkReference, Image, ImageReference, HTML, Definition, FootnoteDefinition } from 'mdast';
|
|
9
10
|
export { BlockTransformer, createBlockTransformer, countChars, sliceAst, cloneNode, codeBlockPlugin, mermaidPlugin, imagePlugin, mathPlugin, thematicBreakPlugin, defaultPlugins, allPlugins, createPlugin } from '@incremark/core';
|
|
10
11
|
export { type DesignTokens, defaultTheme, darkTheme, generateCSSVars, mergeTheme, applyTheme } from '@incremark/theme';
|
|
11
12
|
import { en as enShared, zhCN as zhCNShared } from '@incremark/shared';
|
package/dist/index.js
CHANGED
|
@@ -577,7 +577,7 @@ var IncremarkMath_default = /* @__PURE__ */ _defineComponent({
|
|
|
577
577
|
__name: "IncremarkMath",
|
|
578
578
|
props: {
|
|
579
579
|
node: { type: Object, required: true },
|
|
580
|
-
renderDelay: { type: Number, required: false, default:
|
|
580
|
+
renderDelay: { type: Number, required: false, default: 0 }
|
|
581
581
|
},
|
|
582
582
|
setup(__props, { expose: __expose }) {
|
|
583
583
|
__expose();
|
|
@@ -2372,71 +2372,69 @@ var CachedCodeRenderer_default = /* @__PURE__ */ _defineComponent8({
|
|
|
2372
2372
|
__expose();
|
|
2373
2373
|
const props = __props;
|
|
2374
2374
|
const emit = __emit;
|
|
2375
|
+
const isBrowser = typeof window !== "undefined";
|
|
2375
2376
|
const hasStreamError = ref8(false);
|
|
2377
|
+
const tokens = reactive([]);
|
|
2376
2378
|
const index = ref8(0);
|
|
2377
2379
|
let controller = null;
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2380
|
+
let textStream = null;
|
|
2381
|
+
let tokenStream = null;
|
|
2382
|
+
if (isBrowser) {
|
|
2383
|
+
textStream = new ReadableStream({
|
|
2384
|
+
start(_controller) {
|
|
2385
|
+
controller = _controller;
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
try {
|
|
2389
|
+
tokenStream = textStream.pipeThrough(
|
|
2390
|
+
new CodeToTokenTransformStream({
|
|
2391
|
+
highlighter: props.highlighter,
|
|
2392
|
+
lang: props.lang,
|
|
2393
|
+
theme: props.theme,
|
|
2394
|
+
allowRecalls: true
|
|
2395
|
+
})
|
|
2396
|
+
);
|
|
2397
|
+
} catch (error) {
|
|
2398
|
+
console.error("Failed to create token stream:", error);
|
|
2399
|
+
hasStreamError.value = true;
|
|
2400
|
+
emit("stream-error");
|
|
2381
2401
|
}
|
|
2382
|
-
|
|
2402
|
+
if (tokenStream) {
|
|
2403
|
+
tokenStream.pipeTo(new WritableStream({
|
|
2404
|
+
write(token) {
|
|
2405
|
+
if ("recall" in token)
|
|
2406
|
+
tokens.splice(tokens.length - token.recall, token.recall);
|
|
2407
|
+
else
|
|
2408
|
+
tokens.push(token);
|
|
2409
|
+
},
|
|
2410
|
+
close: () => {
|
|
2411
|
+
emit("stream-end");
|
|
2412
|
+
}
|
|
2413
|
+
})).catch((error) => {
|
|
2414
|
+
console.error("Stream error:", error);
|
|
2415
|
+
hasStreamError.value = true;
|
|
2416
|
+
emit("stream-error");
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2383
2420
|
watch6(() => props.code, (newCode) => {
|
|
2421
|
+
if (!isBrowser || !controller) return;
|
|
2384
2422
|
if (newCode.length > index.value && !hasStreamError.value) {
|
|
2385
2423
|
const incremental = newCode.slice(index.value);
|
|
2386
|
-
controller
|
|
2424
|
+
controller.enqueue(incremental);
|
|
2387
2425
|
index.value = newCode.length;
|
|
2388
2426
|
}
|
|
2389
2427
|
}, { immediate: true });
|
|
2390
|
-
let tokenStream = null;
|
|
2391
|
-
try {
|
|
2392
|
-
tokenStream = textStream.pipeThrough(
|
|
2393
|
-
new CodeToTokenTransformStream({
|
|
2394
|
-
highlighter: props.highlighter,
|
|
2395
|
-
lang: props.lang,
|
|
2396
|
-
theme: props.theme,
|
|
2397
|
-
allowRecalls: true
|
|
2398
|
-
})
|
|
2399
|
-
);
|
|
2400
|
-
} catch (error) {
|
|
2401
|
-
console.error("Failed to create token stream:", error);
|
|
2402
|
-
hasStreamError.value = true;
|
|
2403
|
-
emit("stream-error");
|
|
2404
|
-
}
|
|
2405
|
-
const tokens = reactive([]);
|
|
2406
|
-
if (tokenStream) {
|
|
2407
|
-
let tokenCount = 0;
|
|
2408
|
-
tokenStream.pipeTo(new WritableStream({
|
|
2409
|
-
write(token) {
|
|
2410
|
-
const start = performance.now();
|
|
2411
|
-
if ("recall" in token)
|
|
2412
|
-
tokens.splice(tokens.length - token.recall, token.recall);
|
|
2413
|
-
else
|
|
2414
|
-
tokens.push(token);
|
|
2415
|
-
const elapsed = performance.now() - start;
|
|
2416
|
-
tokenCount++;
|
|
2417
|
-
if (elapsed > 1) {
|
|
2418
|
-
console.log(`[Vue CodeRenderer] Token #${tokenCount} update took ${elapsed.toFixed(2)}ms, total tokens: ${tokens.length}`);
|
|
2419
|
-
}
|
|
2420
|
-
},
|
|
2421
|
-
close: () => {
|
|
2422
|
-
console.log(`[Vue CodeRenderer] Stream completed, total tokens: ${tokenCount}`);
|
|
2423
|
-
emit("stream-end");
|
|
2424
|
-
}
|
|
2425
|
-
})).catch((error) => {
|
|
2426
|
-
console.error("Stream error:", error);
|
|
2427
|
-
hasStreamError.value = true;
|
|
2428
|
-
emit("stream-error");
|
|
2429
|
-
});
|
|
2430
|
-
}
|
|
2431
2428
|
const render24 = () => {
|
|
2432
|
-
if (hasStreamError.value) {
|
|
2433
|
-
return h("pre", { class: "shiki incremark-code-stream" }, h("code", props.code));
|
|
2429
|
+
if (hasStreamError.value || !isBrowser || tokens.length === 0) {
|
|
2430
|
+
return h("pre", { class: "shiki incremark-code-stream" }, h("code", {}, props.code));
|
|
2434
2431
|
}
|
|
2435
2432
|
return h(
|
|
2436
2433
|
"pre",
|
|
2437
2434
|
{ class: "shiki incremark-code-stream" },
|
|
2438
2435
|
h(
|
|
2439
2436
|
"code",
|
|
2437
|
+
{},
|
|
2440
2438
|
renderList(tokens, (token) => h("span", { key: objectId(token), style: token.htmlStyle || getTokenStyleObject(token) }, token.content))
|
|
2441
2439
|
)
|
|
2442
2440
|
);
|
|
@@ -2446,15 +2444,19 @@ var CachedCodeRenderer_default = /* @__PURE__ */ _defineComponent8({
|
|
|
2446
2444
|
tokens.length = 0;
|
|
2447
2445
|
index.value = 0;
|
|
2448
2446
|
});
|
|
2449
|
-
const __returned__ = { props, emit, hasStreamError, index, get controller() {
|
|
2447
|
+
const __returned__ = { props, emit, isBrowser, hasStreamError, tokens, index, get controller() {
|
|
2450
2448
|
return controller;
|
|
2451
2449
|
}, set controller(v) {
|
|
2452
2450
|
controller = v;
|
|
2453
|
-
},
|
|
2451
|
+
}, get textStream() {
|
|
2452
|
+
return textStream;
|
|
2453
|
+
}, set textStream(v) {
|
|
2454
|
+
textStream = v;
|
|
2455
|
+
}, get tokenStream() {
|
|
2454
2456
|
return tokenStream;
|
|
2455
2457
|
}, set tokenStream(v) {
|
|
2456
2458
|
tokenStream = v;
|
|
2457
|
-
},
|
|
2459
|
+
}, render: render24 };
|
|
2458
2460
|
Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
|
|
2459
2461
|
return __returned__;
|
|
2460
2462
|
}
|