markstream-solid 0.0.0-stage → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -2
- package/dist/client/extended-BTbixd9o.js +38 -0
- package/dist/client/index.js +5640 -0
- package/dist/client/katexWorkerClient-ZLzkPVv_.js +260 -0
- package/dist/client/languageIcon-CDTPjsAQ.js +280 -0
- package/dist/client/mermaidWorkerClient-BAvGYsCO.js +243 -0
- package/dist/client/utils/index.js +31 -0
- package/dist/client/utils/katex-threshold.js +32 -0
- package/dist/client/utils/performance-monitor.js +73 -0
- package/dist/client/utils/safeRaf.js +27 -0
- package/dist/client/workers/katexCdnWorker.js +177 -0
- package/dist/client/workers/katexRenderer.worker.js +45 -0
- package/dist/client/workers/katexWorkerClient.js +16 -0
- package/dist/client/workers/mermaidCdnWorker.js +226 -0
- package/dist/client/workers/mermaidParser.worker.js +73 -0
- package/dist/client/workers/mermaidWorkerClient.js +13 -0
- package/dist/components/BuiltinNodes.d.ts +42 -0
- package/dist/components/CodeBlockNode.d.ts +10 -0
- package/dist/components/DiagramBlockNode.d.ts +27 -0
- package/dist/components/HtmlPreviewFrame.d.ts +10 -0
- package/dist/components/MarkstreamProvider.d.ts +5 -0
- package/dist/components/MarkstreamVirtualTimeline.d.ts +35 -0
- package/dist/components/MathNode.d.ts +6 -0
- package/dist/components/NodeRenderer.d.ts +27 -0
- package/dist/components/NodeSlot.d.ts +11 -0
- package/dist/components/PreCodeBlock.d.ts +3 -0
- package/dist/components/PreCodeNode.d.ts +9 -0
- package/dist/components/RenderNode.d.ts +11 -0
- package/dist/components/StreamingTextNode.d.ts +2 -0
- package/dist/components/ToolbarButton.d.ts +14 -0
- package/dist/components/ToolbarIcon.d.ts +18 -0
- package/dist/components/Tooltip.d.ts +13 -0
- package/dist/components/lifecycle.d.ts +6 -0
- package/dist/components/mathHeightCache.d.ts +5 -0
- package/dist/components/rendererModeDefaults.d.ts +4 -0
- package/dist/components/shared/diagram-height.d.ts +16 -0
- package/dist/components/shared/node-helpers.d.ts +78 -0
- package/dist/components/shared/node-outlet-helpers.d.ts +10 -0
- package/dist/components/shared/render-window.d.ts +18 -0
- package/dist/components/shared/reuseParsedNodes.d.ts +3 -0
- package/dist/components/viewport.d.ts +5 -0
- package/dist/components/virtualLayoutKey.d.ts +13 -0
- package/dist/configuration.d.ts +9 -0
- package/dist/customComponents.d.ts +36 -0
- package/dist/enhanceRenderedHtml.d.ts +25 -0
- package/dist/hydrateCustomTagContent.d.ts +2 -0
- package/dist/i18n/useSafeI18n.d.ts +4 -0
- package/dist/icon-themes/index.d.ts +2 -0
- package/dist/icon-themes/material/core.d.ts +2 -0
- package/dist/icon-themes/material/extended.d.ts +2 -0
- package/dist/icon-themes/material/index.d.ts +2 -0
- package/dist/icon-themes/registry.d.ts +9 -0
- package/dist/icon-themes/types.d.ts +11 -0
- package/dist/index.css +3279 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.px.css +3279 -0
- package/dist/index.tailwind.css +3279 -0
- package/dist/optional/d2.d.ts +17 -0
- package/dist/optional/infographic.d.ts +31 -0
- package/dist/optional/katex.d.ts +9 -0
- package/dist/optional/mermaid.d.ts +27 -0
- package/dist/optional/streamDiffs.d.ts +29 -0
- package/dist/renderMarkdownHtml.d.ts +30 -0
- package/dist/sanitizeHtmlContent.d.ts +2 -0
- package/dist/server/extended-CKyCqQt3.js +69 -0
- package/dist/server/index.js +6264 -0
- package/dist/server/languageIcon-TXkIEBPf.js +353 -0
- package/dist/server/utils/index.js +31 -0
- package/dist/server/utils/katex-threshold.js +41 -0
- package/dist/server/utils/performance-monitor.js +120 -0
- package/dist/server/utils/safeRaf.js +28 -0
- package/dist/server/workers/katexCdnWorker.js +190 -0
- package/dist/server/workers/katexWorkerClient.js +373 -0
- package/dist/server/workers/mermaidCdnWorker.js +238 -0
- package/dist/server/workers/mermaidWorkerClient.js +333 -0
- package/dist/streamDiffsWorker.d.ts +72 -0
- package/dist/tailwind.d.ts +2 -0
- package/dist/tailwind.js +3 -0
- package/dist/tooltip/singletonTooltip.d.ts +7 -0
- package/dist/types/component-props.d.ts +253 -0
- package/dist/types/node-renderer-props.d.ts +333 -0
- package/dist/useSmoothMarkdownStream.d.ts +22 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/d2RenderSalt.d.ts +1 -0
- package/dist/utils/footnoteTarget.d.ts +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/katex-threshold.d.ts +20 -0
- package/dist/utils/languageIcon.d.ts +8 -0
- package/dist/utils/mermaidRenderId.d.ts +1 -0
- package/dist/utils/normalizeKaTeXRenderInput.d.ts +1 -0
- package/dist/utils/performance-monitor.d.ts +121 -0
- package/dist/utils/resolveLanguageIcon.d.ts +2 -0
- package/dist/utils/safeRaf.d.ts +2 -0
- package/dist/utils/virtualItemMeasurement.d.ts +5 -0
- package/dist/virtual-adapter.d.ts +165 -0
- package/dist/workers/katexCdnWorker.d.ts +20 -0
- package/dist/workers/katexRenderer.worker.d.ts +1 -0
- package/dist/workers/katexWorkerClient.d.ts +35 -0
- package/dist/workers/mermaidCdnWorker.d.ts +15 -0
- package/dist/workers/mermaidParser.worker.d.ts +1 -0
- package/dist/workers/mermaidWorkerClient.d.ts +15 -0
- package/package.json +149 -3
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { createContext, useContext, createEffect, onCleanup, createSignal } from "solid-js";
|
|
2
|
+
const NodeLifecycleContext = createContext();
|
|
3
|
+
function useNodeLifecycle(props, pending, element) {
|
|
4
|
+
const lifecycle = useContext(NodeLifecycleContext);
|
|
5
|
+
createEffect(() => {
|
|
6
|
+
const key = props.indexKey;
|
|
7
|
+
if (key == null || !lifecycle)
|
|
8
|
+
return;
|
|
9
|
+
if (pending()) {
|
|
10
|
+
lifecycle.markPending(key);
|
|
11
|
+
} else {
|
|
12
|
+
lifecycle.markSettled(key);
|
|
13
|
+
const root = element();
|
|
14
|
+
if (root)
|
|
15
|
+
lifecycle.reportHeight(key, root.getBoundingClientRect().height);
|
|
16
|
+
}
|
|
17
|
+
onCleanup(() => lifecycle.markSettled(key));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function useMarkstreamNodeLifecycle() {
|
|
21
|
+
return useContext(NodeLifecycleContext) ?? null;
|
|
22
|
+
}
|
|
23
|
+
let streamDiffsModule = null;
|
|
24
|
+
let importAttempted = false;
|
|
25
|
+
let pendingImport = null;
|
|
26
|
+
let runtimePreloaded = false;
|
|
27
|
+
let codeBlockRuntimeReady = false;
|
|
28
|
+
function normalizeStreamDiffsModule(value) {
|
|
29
|
+
const moduleValue = value;
|
|
30
|
+
const source = typeof moduleValue?.createCodeBlockRuntime === "function" || typeof moduleValue?.useMonaco === "function" ? moduleValue : value?.default;
|
|
31
|
+
const factory = source?.createCodeBlockRuntime ?? source?.useMonaco;
|
|
32
|
+
if (typeof factory !== "function")
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
createCodeBlockRuntime: (options) => factory.call(source, options),
|
|
36
|
+
preloadStreamDiffs: source?.preloadStreamDiffs?.bind(source)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function isCodeBlockRuntimeReady() {
|
|
40
|
+
return codeBlockRuntimeReady;
|
|
41
|
+
}
|
|
42
|
+
async function preloadCodeBlockRuntime() {
|
|
43
|
+
const runtime = await getStreamDiffsRuntime();
|
|
44
|
+
return !!runtime;
|
|
45
|
+
}
|
|
46
|
+
async function preloadRuntime(mod) {
|
|
47
|
+
if (runtimePreloaded)
|
|
48
|
+
return;
|
|
49
|
+
runtimePreloaded = true;
|
|
50
|
+
if (typeof mod?.preloadStreamDiffs === "function")
|
|
51
|
+
await mod.preloadStreamDiffs();
|
|
52
|
+
}
|
|
53
|
+
async function getStreamDiffsRuntime() {
|
|
54
|
+
if (streamDiffsModule)
|
|
55
|
+
return streamDiffsModule;
|
|
56
|
+
if (pendingImport)
|
|
57
|
+
return await pendingImport;
|
|
58
|
+
if (importAttempted)
|
|
59
|
+
return null;
|
|
60
|
+
pendingImport = (async () => {
|
|
61
|
+
try {
|
|
62
|
+
const candidate = normalizeStreamDiffsModule(await import("stream-diffs/markstream"));
|
|
63
|
+
if (!candidate)
|
|
64
|
+
return null;
|
|
65
|
+
streamDiffsModule = candidate;
|
|
66
|
+
await preloadRuntime(streamDiffsModule);
|
|
67
|
+
codeBlockRuntimeReady = true;
|
|
68
|
+
return streamDiffsModule;
|
|
69
|
+
} catch {
|
|
70
|
+
importAttempted = true;
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
try {
|
|
75
|
+
return await pendingImport;
|
|
76
|
+
} finally {
|
|
77
|
+
pendingImport = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const CIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#0288d1" d="M19.563 22A5.57 5.57 0 0 1 14 16.437v-2.873A5.57 5.57 0 0 1 19.563 8H24V2h-4.437A11.563 11.563 0 0 0 8 13.563v2.873A11.564 11.564 0 0 0 19.563 28H24v-6Z"/></svg>';
|
|
81
|
+
const CppIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#0288d1" d="M28 14v-4h-2v4h-6v-4h-2v4h-4v2h4v4h2v-4h6v4h2v-4h4v-2z"/><path fill="#0288d1" d="M13.563 22A5.57 5.57 0 0 1 8 16.437v-2.873A5.57 5.57 0 0 1 13.563 8H18V2h-4.437A11.563 11.563 0 0 0 2 13.563v2.873A11.564 11.564 0 0 0 13.563 28H18v-6Z"/></svg>';
|
|
82
|
+
const CsharpIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#0288d1" d="M30 14v-2h-2V8h-2v4h-2V8h-2v4h-2v2h2v2h-2v2h2v4h2v-4h2v4h2v-4h2v-2h-2v-2Zm-4 2h-2v-2h2Zm-12.437 6A5.57 5.57 0 0 1 8 16.437v-2.873A5.57 5.57 0 0 1 13.563 8H18V2h-4.437A11.563 11.563 0 0 0 2 13.563v2.873A11.564 11.564 0 0 0 13.563 28H18v-6Z"/></svg>';
|
|
83
|
+
const CssIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#7e57c2" d="M20 18h-2v-2h-2v2c0 .193 0 .703 1.254 1.033A3.345 3.345 0 0 1 20 22h2v2h2v-2c0-.388-.562-.851-1.254-1.034C20.356 20.34 20 18.84 20 18m-3.254 2.966C14.356 20.34 14 18.84 14 18h-2v-2h-2v8h2v-2h4v2h2v-2c0-.388-.562-.851-1.254-1.034"/><path fill="#7e57c2" d="M24 4H4v20a4 4 0 0 0 4 4h16.16A3.84 3.84 0 0 0 28 24.16V8a4 4 0 0 0-4-4m2 14h-2v-2h-2v2c0 .193 0 .703 1.254 1.033A3.345 3.345 0 0 1 26 22v2a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2 2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2 2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2 2 2 0 0 1 2-2h2a2 2 0 0 1 2 2 2 2 0 0 1 2-2h2a2 2 0 0 1 2 2Z"/></svg>';
|
|
84
|
+
const GoIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#00acc1" d="M2 12h4v2H2zm-2 4h6v2H0zm4 4h2v2H4zm16.954-5H14v3h3.239a4.42 4.42 0 0 1-3.531 2 2.65 2.65 0 0 1-2.053-.858 2.86 2.86 0 0 1-.628-2.28A4.515 4.515 0 0 1 15.292 13a2.73 2.73 0 0 1 1.749.584l2.962-1.185A5.6 5.6 0 0 0 15.292 10a7.526 7.526 0 0 0-7.243 6.5 5.614 5.614 0 0 0 5.659 6.5 7.526 7.526 0 0 0 7.243-6.5 6.4 6.4 0 0 0 .003-1.5"/><path fill="#00acc1" d="M26.292 10a7.526 7.526 0 0 0-7.243 6.5 5.614 5.614 0 0 0 5.659 6.5 7.526 7.526 0 0 0 7.243-6.5 5.614 5.614 0 0 0-5.659-6.5m2.681 6.137A4.515 4.515 0 0 1 24.708 20a2.65 2.65 0 0 1-2.053-.858 2.86 2.86 0 0 1-.628-2.28A4.515 4.515 0 0 1 26.292 13a2.65 2.65 0 0 1 2.053.858 2.86 2.86 0 0 1 .628 2.28Z"/></svg>';
|
|
85
|
+
const HtmlIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#e65100" d="m4 4 2 22 10 2 10-2 2-22Zm19.72 7H11.28l.29 3h11.86l-.802 9.335L15.99 25l-6.635-1.646L8.93 19h3.02l.19 2 3.86.77 3.84-.77.29-4H8.84L8 8h16Z"/></svg>';
|
|
86
|
+
const JavaIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#f44336" d="M4 26h24v2H4zM28 4H7a1 1 0 0 0-1 1v13a4 4 0 0 0 4 4h10a4 4 0 0 0 4-4v-4h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2m0 8h-4V6h4Z"/></svg>';
|
|
87
|
+
const JsIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#ffca28" d="M2 2v12h12V2zm6 6h1v4a1.003 1.003 0 0 1-1 1H7a1.003 1.003 0 0 1-1-1v-1h1v1h1zm3 0h2v1h-2v1h1a1.003 1.003 0 0 1 1 1v1a1.003 1.003 0 0 1-1 1h-2v-1h2v-1h-1a1.003 1.003 0 0 1-1-1V9a1.003 1.003 0 0 1 1-1"/></svg>';
|
|
88
|
+
const JsonIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="#f9a825" d="M560-160v-80h120q17 0 28.5-11.5T720-280v-80q0-38 22-69t58-44v-14q-36-13-58-44t-22-69v-80q0-17-11.5-28.5T680-720H560v-80h120q50 0 85 35t35 85v80q0 17 11.5 28.5T840-560h40v160h-40q-17 0-28.5 11.5T800-360v80q0 50-35 85t-85 35zm-280 0q-50 0-85-35t-35-85v-80q0-17-11.5-28.5T120-400H80v-160h40q17 0 28.5-11.5T160-600v-80q0-50 35-85t85-35h120v80H280q-17 0-28.5 11.5T240-680v80q0 38-22 69t-58 44v14q36 13 58 44t22 69v80q0 17 11.5 28.5T280-240h120v80z"/></svg>';
|
|
89
|
+
const JsxIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#00bcd4" d="M16 12c7.444 0 12 2.59 12 4s-4.556 4-12 4-12-2.59-12-4 4.556-4 12-4m0-2c-7.732 0-14 2.686-14 6s6.268 6 14 6 14-2.686 14-6-6.268-6-14-6"/><path fill="#00bcd4" d="M16 14a2 2 0 1 0 2 2 2 2 0 0 0-2-2"/><path fill="#00bcd4" d="M10.458 5.507c2.017 0 5.937 3.177 9.006 8.493 3.722 6.447 3.757 11.687 2.536 12.392a.9.9 0 0 1-.457.1c-2.017 0-5.938-3.176-9.007-8.492C8.814 11.553 8.779 6.313 10 5.608a.9.9 0 0 1 .458-.1m-.001-2A2.87 2.87 0 0 0 9 3.875C6.13 5.532 6.938 12.304 10.804 19c3.284 5.69 7.72 9.493 10.74 9.493A2.87 2.87 0 0 0 23 28.124c2.87-1.656 2.062-8.428-1.804-15.124-3.284-5.69-7.72-9.493-10.74-9.493Z"/><path fill="#00bcd4" d="M21.543 5.507a.9.9 0 0 1 .457.1c1.221.706 1.186 5.946-2.536 12.393-3.07 5.316-6.99 8.493-9.007 8.493a.9.9 0 0 1-.457-.1C8.779 25.686 8.814 20.446 12.536 14c3.07-5.316 6.99-8.493 9.007-8.493m0-2c-3.02 0-7.455 3.804-10.74 9.493C6.939 19.696 6.13 26.468 9 28.124a2.87 2.87 0 0 0 1.457.369c3.02 0 7.455-3.804 10.74-9.493C25.061 12.304 25.87 5.532 23 3.876a2.87 2.87 0 0 0-1.457-.369"/></svg>';
|
|
90
|
+
const KotlinIcon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><defs><linearGradient id="a" x1="1.725" x2="22.185" y1="22.67" y2="1.982" gradientTransform="translate(1.306 1.129)scale(.89324)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#7c4dff"/><stop offset=".5" stop-color="#d500f9"/><stop offset="1" stop-color="#ef5350"/></linearGradient></defs><path fill="url(#a)" d="M2.975 2.976v18.048h18.05v-.03l-4.478-4.511-4.48-4.515 4.48-4.515 4.443-4.477z"/></svg>';
|
|
91
|
+
const MarkdownIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#42a5f5" d="m14 10-4 3.5L6 10H4v12h4v-6l2 2 2-2v6h4V10zm12 6v-6h-4v6h-4l6 8 6-8z"/></svg>';
|
|
92
|
+
const MermaidIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#42a5f5" d="m14 10-4 3.5L6 10H4v12h4v-6l2 2 2-2v6h4V10zm12 6v-6h-4v6h-4l6 8 6-8z"/></svg>';
|
|
93
|
+
const PhpIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#1e88e5" d="M12 18.08c-6.63 0-12-2.72-12-6.08s5.37-6.08 12-6.08S24 8.64 24 12s-5.37 6.08-12 6.08m-5.19-7.95c.54 0 .91.1 1.09.31.18.2.22.56.13 1.03-.1.53-.29.87-.58 1.09q-.42.33-1.29.33h-.87l.53-2.76zm-3.5 5.55h1.44l.34-1.75h1.23c.54 0 .98-.06 1.33-.17.35-.12.67-.31.96-.58.24-.22.43-.46.58-.73.15-.26.26-.56.31-.88.16-.78.05-1.39-.33-1.82-.39-.44-.99-.65-1.82-.65H4.59zm7.25-8.33-1.28 6.58h1.42l.74-3.77h1.14c.36 0 .6.06.71.18s.13.34.07.66l-.57 2.93h1.45l.59-3.07c.13-.62.03-1.07-.27-1.36-.3-.27-.85-.4-1.65-.4h-1.27L12 7.35zM18 10.13c.55 0 .91.1 1.09.31.18.2.22.56.13 1.03-.1.53-.29.87-.57 1.09-.29.22-.72.33-1.3.33h-.85l.5-2.76zm-3.5 5.55h1.44l.34-1.75h1.22c.55 0 1-.06 1.35-.17.35-.12.65-.31.95-.58.24-.22.44-.46.58-.73.15-.26.26-.56.32-.88.15-.78.04-1.39-.34-1.82-.36-.44-.99-.65-1.82-.65h-2.75z"/></svg>';
|
|
94
|
+
const PlainIcon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/><path fill="#42a5f5" d="M8 16h8v2H8zm0-4h8v2H8zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8zm4 18H6V4h7v5h5z"/></svg>';
|
|
95
|
+
const PowershellIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#03a9f4" d="M29.07 6H7.677A1.535 1.535 0 0 0 6.24 7.113l-4.2 17.774A.852.852 0 0 0 2.93 26h21.393a1.535 1.535 0 0 0 1.436-1.113L29.96 7.112A.852.852 0 0 0 29.07 6M8.626 23.797a1.4 1.4 0 0 1-1.814-.31l-.007-.009a1.075 1.075 0 0 1 .315-1.599l9.6-6.061-6.102-5.852-.01-.01a1.068 1.068 0 0 1 .084-1.625l.037-.03a1.38 1.38 0 0 1 1.8.07l7.233 6.957a1.1 1.1 0 0 1 .236.739 1.08 1.08 0 0 1-.412.79c-.074.04-.146.119-10.951 6.935ZM24 22.94A1.135 1.135 0 0 1 22.803 24h-5.634a1.061 1.061 0 1 1 .001-2.112h5.633A1.134 1.134 0 0 1 24 22.938Z"/></svg>';
|
|
96
|
+
const PythonIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#0288d1" d="M9.86 2A2.86 2.86 0 0 0 7 4.86v1.68h4.29c.39 0 .71.57.71.96H4.86A2.86 2.86 0 0 0 2 10.36v3.781a2.86 2.86 0 0 0 2.86 2.86h1.18v-2.68a2.85 2.85 0 0 1 2.85-2.86h5.25c1.58 0 2.86-1.271 2.86-2.851V4.86A2.86 2.86 0 0 0 14.14 2zm-.72 1.61c.4 0 .72.12.72.71s-.32.891-.72.891c-.39 0-.71-.3-.71-.89s.32-.711.71-.711"/><path fill="#fdd835" d="M17.959 7v2.68a2.85 2.85 0 0 1-2.85 2.859H9.86A2.85 2.85 0 0 0 7 15.389v3.75a2.86 2.86 0 0 0 2.86 2.86h4.28A2.86 2.86 0 0 0 17 19.14v-1.68h-4.291c-.39 0-.709-.57-.709-.96h7.14A2.86 2.86 0 0 0 22 13.64V9.86A2.86 2.86 0 0 0 19.14 7zM8.32 11.513l-.004.004.038-.004zm6.54 7.276c.39 0 .71.3.71.89a.71.71 0 0 1-.71.71c-.4 0-.72-.12-.72-.71s.32-.89.72-.89"/></svg>';
|
|
97
|
+
const RubyIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#f44336" d="M18.041 3.177c2.24.382 2.879 1.919 2.843 3.527V6.67l-1.013 13.266-13.132.897h.008c-1.093-.044-3.518-.151-3.634-3.545l1.217-2.222 2.462 5.74 2.097-6.77-.045.009.018-.018 6.85 2.186L13.945 9.3l6.53-.409-5.144-4.212 2.71-1.51v.009M3.113 17.252v.017zM6.916 6.874c2.63-2.622 6.033-4.168 7.34-2.844 1.297 1.306-.072 4.523-2.702 7.135-2.666 2.613-6.015 4.248-7.322 2.933-1.306-1.324.036-4.612 2.675-7.224z"/></svg>';
|
|
98
|
+
const RustIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#ff7043" d="m30 12-4-2V6h-4l-2-4-4 2-4-2-2 4H6v4l-4 2 2 4-2 4 4 2v4h4l2 4 4-2 4 2 2-4h4v-4l4-2-2-4ZM6 16a9.9 9.9 0 0 1 .842-4H10v8H6.842A9.9 9.9 0 0 1 6 16m10 10a9.98 9.98 0 0 1-7.978-4H16v-2h-2v-2h4c.819.819.297 2.308 1.179 3.37a1.89 1.89 0 0 0 1.46.63h3.34A9.98 9.98 0 0 1 16 26m-2-12v-2h4a1 1 0 0 1 0 2Zm11.158 6H24a2.006 2.006 0 0 1-2-2 2 2 0 0 0-2-2 3 3 0 0 0 3-3q0-.08-.004-.161A3.115 3.115 0 0 0 19.83 10H8.022a9.986 9.986 0 0 1 17.136 10"/></svg>';
|
|
99
|
+
const ScssIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#ec407a" d="M27.837 5.673a4.33 4.33 0 0 0-2.293-2.701c-2.362-1.261-6.11-1.298-9.548-.092a26.3 26.3 0 0 0-8.76 4.966c-2.752 2.542-3.438 4.925-3.189 6.194.523 2.668 3.274 4.539 5.485 6.042.418.284.822.559 1.175.816-1.429.76-4.261 2.444-5.088 4.248a3.88 3.88 0 0 0-.118 3.332A2.37 2.37 0 0 0 6.869 29.8a5.6 5.6 0 0 0 1.49.2 6.35 6.35 0 0 0 5.19-2.856 6.74 6.74 0 0 0 .864-5.382 7.3 7.3 0 0 1 2.044-.03 3.92 3.92 0 0 1 2.816 1.311 1.82 1.82 0 0 1 .423 1.262 1.55 1.55 0 0 1-.772 1.05c-.234.14-.586.355-.504.803.036.194.198.633.894.512a2.93 2.93 0 0 0 2.145-2.651 4 4 0 0 0-1.197-2.904 5.94 5.94 0 0 0-4.396-1.626 10.6 10.6 0 0 0-2.672.304 20 20 0 0 0-2.203-1.846c-1.712-1.3-3.33-2.529-3.235-4.26.125-2.263 2.468-4.532 6.964-6.744 4.016-1.976 7.254-2.037 8.944-1.438a2 2 0 0 1 1.204.883 2.77 2.77 0 0 1-.36 2.47 9.71 9.71 0 0 1-7.425 4.304 3.86 3.86 0 0 1-3.238-.757c-.278-.302-.593-.645-1.074-.383q-.565.31-.225 1.189a3.9 3.9 0 0 0 2.407 1.92 11.7 11.7 0 0 0 7.128-.671c3.527-1.35 6.681-5.202 5.756-8.787M11.895 24.475a4 4 0 0 1-.192.468 4.5 4.5 0 0 1-.753 1.081 2.83 2.83 0 0 1-2.533 1.107c-.056-.032-.078-.146-.085-.193a3.28 3.28 0 0 1 1.076-2.284 11.3 11.3 0 0 1 2.644-1.933 3.85 3.85 0 0 1-.157 1.754"/></svg>';
|
|
100
|
+
const ShellIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#ff7043" d="M2 2a1 1 0 0 0-1 1v10c0 .554.446 1 1 1h12c.554 0 1-.446 1-1V3a1 1 0 0 0-1-1zm0 3h12v8H2zm1 2 2 2-2 2 1 1 3-3-3-3zm5 3.5V12h5v-1.5z"/></svg>';
|
|
101
|
+
const SqlIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#ffca28" d="M16 24c-5.525 0-10-.9-10-2v4c0 1.1 4.475 2 10 2s10-.9 10-2v-4c0 1.1-4.475 2-10 2m0-8c-5.525 0-10-.9-10-2v4c0 1.1 4.475 2 10 2s10-.9 10-2v-4c0 1.1-4.475 2-10 2m0-12C10.477 4 6 4.895 6 6v4c0 1.1 4.475 2 10 2s10-.9 10-2V6c0-1.105-4.477-2-10-2"/></svg>';
|
|
102
|
+
const TextIcon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/><path fill="#42a5f5" d="M8 16h8v2H8zm0-4h8v2H8zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8zm4 18H6V4h7v5h5z"/></svg>';
|
|
103
|
+
const TsxIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path fill="#0288d1" d="M16 12c7.444 0 12 2.59 12 4s-4.556 4-12 4-12-2.59-12-4 4.556-4 12-4m0-2c-7.732 0-14 2.686-14 6s6.268 6 14 6 14-2.686 14-6-6.268-6-14-6"/><path fill="#0288d1" d="M16 14a2 2 0 1 0 2 2 2 2 0 0 0-2-2"/><path fill="#0288d1" d="M10.458 5.507c2.017 0 5.937 3.177 9.006 8.493 3.722 6.447 3.757 11.687 2.536 12.392a.9.9 0 0 1-.457.1c-2.017 0-5.938-3.176-9.007-8.492C8.814 11.553 8.779 6.313 10 5.608a.9.9 0 0 1 .458-.1m-.001-2A2.87 2.87 0 0 0 9 3.875C6.13 5.532 6.938 12.304 10.804 19c3.284 5.69 7.72 9.493 10.74 9.493A2.87 2.87 0 0 0 23 28.124c2.87-1.656 2.062-8.428-1.804-15.124-3.284-5.69-7.72-9.493-10.74-9.493Z"/><path fill="#0288d1" d="M21.543 5.507a.9.9 0 0 1 .457.1c1.221.706 1.186 5.946-2.536 12.393-3.07 5.316-6.99 8.493-9.007 8.493a.9.9 0 0 1-.457-.1C8.779 25.686 8.814 20.446 12.536 14c3.07-5.316 6.99-8.493 9.007-8.493m0-2c-3.02 0-7.455 3.804-10.74 9.493C6.939 19.696 6.13 26.468 9 28.124a2.87 2.87 0 0 0 1.457.369c3.02 0 7.455-3.804 10.74-9.493C25.061 12.304 25.87 5.532 23 3.876a2.87 2.87 0 0 0-1.457-.369"/></svg>';
|
|
104
|
+
const TsIcon = '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 16 16"><path fill="#0288d1" d="M2 2v12h12V2zm4 6h3v1H8v4H7V9H6zm5 0h2v1h-2v1h1a1.003 1.003 0 0 1 1 1v1a1.003 1.003 0 0 1-1 1h-2v-1h2v-1h-1a1.003 1.003 0 0 1-1-1V9a1.003 1.003 0 0 1 1-1"/></svg>';
|
|
105
|
+
const VueIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#41b883" d="M1.791 3.851 12 21.471 22.209 3.936V3.85H18.24l-6.18 10.616L5.906 3.851z"/><path fill="#35495e" d="m5.907 3.851 6.152 10.617L18.24 3.851h-3.723L12.084 8.03 9.66 3.85z"/></svg>';
|
|
106
|
+
const XmlIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#8bc34a" d="M13 9h5.5L13 3.5zM6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m.12 13.5 3.74 3.74 1.42-1.41-2.33-2.33 2.33-2.33-1.42-1.41zm11.16 0-3.74-3.74-1.42 1.41 2.33 2.33-2.33 2.33 1.42 1.41z"/></svg>';
|
|
107
|
+
const YamlIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#ff5252" d="M13 9h5.5L13 3.5zM6 2h8l6 6v12c0 1.1-.9 2-2 2H6c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2m12 16v-2H9v2zm-4-4v-2H6v2z"/></svg>';
|
|
108
|
+
const materialCoreMap = {
|
|
109
|
+
"": TextIcon,
|
|
110
|
+
"plain": PlainIcon,
|
|
111
|
+
"text": TextIcon,
|
|
112
|
+
"javascript": JsIcon,
|
|
113
|
+
"typescript": TsIcon,
|
|
114
|
+
"jsx": JsxIcon,
|
|
115
|
+
"tsx": TsxIcon,
|
|
116
|
+
"html": HtmlIcon,
|
|
117
|
+
"css": CssIcon,
|
|
118
|
+
"scss": ScssIcon,
|
|
119
|
+
"json": JsonIcon,
|
|
120
|
+
"python": PythonIcon,
|
|
121
|
+
"ruby": RubyIcon,
|
|
122
|
+
"go": GoIcon,
|
|
123
|
+
"java": JavaIcon,
|
|
124
|
+
"kotlin": KotlinIcon,
|
|
125
|
+
"c": CIcon,
|
|
126
|
+
"cpp": CppIcon,
|
|
127
|
+
"cs": CsharpIcon,
|
|
128
|
+
"csharp": CsharpIcon,
|
|
129
|
+
"php": PhpIcon,
|
|
130
|
+
"shell": ShellIcon,
|
|
131
|
+
"powershell": PowershellIcon,
|
|
132
|
+
"sql": SqlIcon,
|
|
133
|
+
"yaml": YamlIcon,
|
|
134
|
+
"markdown": MarkdownIcon,
|
|
135
|
+
"xml": XmlIcon,
|
|
136
|
+
"rust": RustIcon,
|
|
137
|
+
"vue": VueIcon,
|
|
138
|
+
"mermaid": MermaidIcon
|
|
139
|
+
};
|
|
140
|
+
const FallbackIcon = '<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#ff7043" d="M2 2a1 1 0 0 0-1 1v10c0 .554.446 1 1 1h12c.554 0 1-.446 1-1V3a1 1 0 0 0-1-1zm0 3h12v8H2zm1 2 2 2-2 2 1 1 3-3-3-3zm5 3.5V12h5v-1.5z"/></svg>';
|
|
141
|
+
const materialIconTheme = {
|
|
142
|
+
id: "material",
|
|
143
|
+
core: materialCoreMap,
|
|
144
|
+
fallback: FallbackIcon,
|
|
145
|
+
loadExtended: () => import("./extended-CKyCqQt3.js").then((m) => m.materialExtendedMap)
|
|
146
|
+
};
|
|
147
|
+
const themes = /* @__PURE__ */ new Map();
|
|
148
|
+
let activeThemeId = "material";
|
|
149
|
+
const extendedCache = /* @__PURE__ */ new Map();
|
|
150
|
+
const extendedPromises = /* @__PURE__ */ new Map();
|
|
151
|
+
let _bumpRevision = null;
|
|
152
|
+
function _setRevisionBumper(fn) {
|
|
153
|
+
_bumpRevision = fn;
|
|
154
|
+
}
|
|
155
|
+
function registerIconTheme(theme) {
|
|
156
|
+
themes.set(theme.id, theme);
|
|
157
|
+
}
|
|
158
|
+
function setIconTheme(id) {
|
|
159
|
+
if (!themes.has(id))
|
|
160
|
+
throw new Error(`[markstream-vue] Unknown icon theme: "${id}". Registered: ${[...themes.keys()].join(", ")}`);
|
|
161
|
+
activeThemeId = id;
|
|
162
|
+
_bumpRevision?.();
|
|
163
|
+
const theme = themes.get(id);
|
|
164
|
+
if (theme.loadExtended && !extendedCache.has(id))
|
|
165
|
+
void loadThemeExtended(theme);
|
|
166
|
+
}
|
|
167
|
+
function getRegisteredThemes() {
|
|
168
|
+
return [...themes.keys()];
|
|
169
|
+
}
|
|
170
|
+
function resolveFromTheme(normalized) {
|
|
171
|
+
const theme = themes.get(activeThemeId);
|
|
172
|
+
if (!theme)
|
|
173
|
+
return void 0;
|
|
174
|
+
const coreHit = theme.core[normalized];
|
|
175
|
+
if (coreHit)
|
|
176
|
+
return coreHit;
|
|
177
|
+
const ext = extendedCache.get(theme.id);
|
|
178
|
+
if (ext) {
|
|
179
|
+
const extHit = ext[normalized];
|
|
180
|
+
if (extHit)
|
|
181
|
+
return extHit;
|
|
182
|
+
}
|
|
183
|
+
if (theme.loadExtended && !extendedCache.has(theme.id))
|
|
184
|
+
void loadThemeExtended(theme);
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
function getThemeFallback() {
|
|
188
|
+
return themes.get(activeThemeId)?.fallback ?? "";
|
|
189
|
+
}
|
|
190
|
+
async function loadThemeExtended(theme) {
|
|
191
|
+
if (extendedCache.has(theme.id))
|
|
192
|
+
return extendedCache.get(theme.id) ?? null;
|
|
193
|
+
let promise = extendedPromises.get(theme.id);
|
|
194
|
+
if (!promise) {
|
|
195
|
+
promise = (theme.loadExtended?.() ?? Promise.resolve(null)).then((map) => {
|
|
196
|
+
extendedCache.set(theme.id, map);
|
|
197
|
+
_bumpRevision?.();
|
|
198
|
+
return map;
|
|
199
|
+
}).catch(() => {
|
|
200
|
+
extendedCache.set(theme.id, null);
|
|
201
|
+
return null;
|
|
202
|
+
});
|
|
203
|
+
extendedPromises.set(theme.id, promise);
|
|
204
|
+
}
|
|
205
|
+
return promise;
|
|
206
|
+
}
|
|
207
|
+
async function preloadActiveThemeExtended() {
|
|
208
|
+
const theme = themes.get(activeThemeId);
|
|
209
|
+
if (theme?.loadExtended)
|
|
210
|
+
await loadThemeExtended(theme);
|
|
211
|
+
}
|
|
212
|
+
let userLanguageIconResolver = null;
|
|
213
|
+
const [iconRevision, setIconRevision] = createSignal(0);
|
|
214
|
+
const languageIconsRevision = iconRevision;
|
|
215
|
+
_setRevisionBumper(() => {
|
|
216
|
+
setIconRevision((value) => value + 1);
|
|
217
|
+
});
|
|
218
|
+
registerIconTheme(materialIconTheme);
|
|
219
|
+
const LANGUAGE_ALIAS_MAP = {
|
|
220
|
+
"": "",
|
|
221
|
+
"javascript": "javascript",
|
|
222
|
+
"js": "javascript",
|
|
223
|
+
"mjs": "javascript",
|
|
224
|
+
"cjs": "javascript",
|
|
225
|
+
"typescript": "typescript",
|
|
226
|
+
"ts": "typescript",
|
|
227
|
+
"jsx": "jsx",
|
|
228
|
+
"tsx": "tsx",
|
|
229
|
+
"golang": "go",
|
|
230
|
+
"py": "python",
|
|
231
|
+
"rb": "ruby",
|
|
232
|
+
"sh": "shell",
|
|
233
|
+
"bash": "shell",
|
|
234
|
+
"zsh": "shell",
|
|
235
|
+
"shellscript": "shell",
|
|
236
|
+
"bat": "shell",
|
|
237
|
+
"batch": "shell",
|
|
238
|
+
"ps1": "powershell",
|
|
239
|
+
"plaintext": "plain",
|
|
240
|
+
"text": "plain",
|
|
241
|
+
"txt": "plain",
|
|
242
|
+
"c++": "cpp",
|
|
243
|
+
"c#": "csharp",
|
|
244
|
+
"cs": "csharp",
|
|
245
|
+
"objective-c": "objectivec",
|
|
246
|
+
"objective-c++": "objectivecpp",
|
|
247
|
+
"yml": "yaml",
|
|
248
|
+
"md": "markdown",
|
|
249
|
+
"rs": "rust",
|
|
250
|
+
"kt": "kotlin"
|
|
251
|
+
};
|
|
252
|
+
function extractLanguageToken(lang) {
|
|
253
|
+
if (!lang)
|
|
254
|
+
return "";
|
|
255
|
+
const trimmed = lang.trim();
|
|
256
|
+
if (!trimmed)
|
|
257
|
+
return "";
|
|
258
|
+
const [firstToken] = trimmed.split(/\s+/);
|
|
259
|
+
const [base] = firstToken.split(":");
|
|
260
|
+
return base.toLowerCase();
|
|
261
|
+
}
|
|
262
|
+
function setLanguageIconResolver(resolver) {
|
|
263
|
+
userLanguageIconResolver = resolver ?? null;
|
|
264
|
+
}
|
|
265
|
+
function normalizeLanguageIdentifier(lang) {
|
|
266
|
+
const token = extractLanguageToken(lang);
|
|
267
|
+
return LANGUAGE_ALIAS_MAP[token] ?? token;
|
|
268
|
+
}
|
|
269
|
+
function resolveLanguageId(lang) {
|
|
270
|
+
const canonical = normalizeLanguageIdentifier(lang);
|
|
271
|
+
if (!canonical)
|
|
272
|
+
return "plaintext";
|
|
273
|
+
switch (canonical) {
|
|
274
|
+
case "plain":
|
|
275
|
+
return "plaintext";
|
|
276
|
+
case "shell":
|
|
277
|
+
return "zsh";
|
|
278
|
+
case "svg":
|
|
279
|
+
return "xml";
|
|
280
|
+
case "objectivec":
|
|
281
|
+
return "objective-c";
|
|
282
|
+
case "objectivecpp":
|
|
283
|
+
return "objective-cpp";
|
|
284
|
+
default:
|
|
285
|
+
return canonical;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function preloadExtendedLanguageIcons() {
|
|
289
|
+
await preloadActiveThemeExtended();
|
|
290
|
+
}
|
|
291
|
+
function getLanguageIcon(lang) {
|
|
292
|
+
if (userLanguageIconResolver) {
|
|
293
|
+
const hit = userLanguageIconResolver(lang);
|
|
294
|
+
if (hit != null && hit !== "")
|
|
295
|
+
return hit;
|
|
296
|
+
}
|
|
297
|
+
const normalized = normalizeLanguageIdentifier(lang);
|
|
298
|
+
const themeHit = resolveFromTheme(normalized);
|
|
299
|
+
if (themeHit)
|
|
300
|
+
return themeHit;
|
|
301
|
+
return getThemeFallback();
|
|
302
|
+
}
|
|
303
|
+
const languageMap = {
|
|
304
|
+
"js": "JavaScript",
|
|
305
|
+
"javascript": "JavaScript",
|
|
306
|
+
"ts": "TypeScript",
|
|
307
|
+
"typescript": "TypeScript",
|
|
308
|
+
"jsx": "JSX",
|
|
309
|
+
"tsx": "TSX",
|
|
310
|
+
"html": "HTML",
|
|
311
|
+
"css": "CSS",
|
|
312
|
+
"scss": "SCSS",
|
|
313
|
+
"json": "JSON",
|
|
314
|
+
"py": "Python",
|
|
315
|
+
"python": "Python",
|
|
316
|
+
"rb": "Ruby",
|
|
317
|
+
"go": "Go",
|
|
318
|
+
"java": "Java",
|
|
319
|
+
"c": "C",
|
|
320
|
+
"cpp": "C++",
|
|
321
|
+
"cs": "C#",
|
|
322
|
+
"csharp": "C#",
|
|
323
|
+
"php": "PHP",
|
|
324
|
+
"sh": "Shell",
|
|
325
|
+
"bash": "Bash",
|
|
326
|
+
"sql": "SQL",
|
|
327
|
+
"yaml": "YAML",
|
|
328
|
+
"md": "Markdown",
|
|
329
|
+
"d2": "D2",
|
|
330
|
+
"d2lang": "D2",
|
|
331
|
+
"": "Plain Text",
|
|
332
|
+
"plain": "Plain Text"
|
|
333
|
+
};
|
|
334
|
+
export {
|
|
335
|
+
NodeLifecycleContext as N,
|
|
336
|
+
getRegisteredThemes as a,
|
|
337
|
+
getStreamDiffsRuntime as b,
|
|
338
|
+
getThemeFallback as c,
|
|
339
|
+
languageMap as d,
|
|
340
|
+
preloadExtendedLanguageIcons as e,
|
|
341
|
+
resolveFromTheme as f,
|
|
342
|
+
getLanguageIcon as g,
|
|
343
|
+
resolveLanguageId as h,
|
|
344
|
+
isCodeBlockRuntimeReady as i,
|
|
345
|
+
setLanguageIconResolver as j,
|
|
346
|
+
useNodeLifecycle as k,
|
|
347
|
+
languageIconsRevision as l,
|
|
348
|
+
normalizeLanguageIdentifier as n,
|
|
349
|
+
preloadCodeBlockRuntime as p,
|
|
350
|
+
registerIconTheme as r,
|
|
351
|
+
setIconTheme as s,
|
|
352
|
+
useMarkstreamNodeLifecycle as u
|
|
353
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { N, g, a, i, l, d, n, p, e, r, h, s, j, u } from "../languageIcon-TXkIEBPf.js";
|
|
2
|
+
import { defaultRByClass, estimateRByFormula, recommendNForSamples, recommendWorkerThreshold } from "./katex-threshold.js";
|
|
3
|
+
import { disablePerfMonitoring, enablePerfMonitoring, getPerfReport, perfMonitor } from "./performance-monitor.js";
|
|
4
|
+
import { safeCancelRaf, safeRaf } from "./safeRaf.js";
|
|
5
|
+
export * from "stream-markdown-parser";
|
|
6
|
+
export {
|
|
7
|
+
N as MARKSTREAM_NODE_LIFECYCLE_KEY,
|
|
8
|
+
defaultRByClass,
|
|
9
|
+
disablePerfMonitoring,
|
|
10
|
+
enablePerfMonitoring,
|
|
11
|
+
estimateRByFormula,
|
|
12
|
+
g as getLanguageIcon,
|
|
13
|
+
getPerfReport,
|
|
14
|
+
a as getRegisteredThemes,
|
|
15
|
+
i as isCodeBlockRuntimeReady,
|
|
16
|
+
l as languageIconsRevision,
|
|
17
|
+
d as languageMap,
|
|
18
|
+
n as normalizeLanguageIdentifier,
|
|
19
|
+
perfMonitor,
|
|
20
|
+
p as preloadCodeBlockRuntime,
|
|
21
|
+
e as preloadExtendedLanguageIcons,
|
|
22
|
+
recommendNForSamples,
|
|
23
|
+
recommendWorkerThreshold,
|
|
24
|
+
r as registerIconTheme,
|
|
25
|
+
h as resolveLanguageId,
|
|
26
|
+
safeCancelRaf,
|
|
27
|
+
safeRaf,
|
|
28
|
+
s as setIconTheme,
|
|
29
|
+
j as setLanguageIconResolver,
|
|
30
|
+
u as useMarkstreamNodeLifecycle
|
|
31
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function recommendWorkerThreshold({ R, H = 0, B = 50 }) {
|
|
2
|
+
const denom = R * (1 - H) || 1e-6;
|
|
3
|
+
const N = Math.max(1, Math.floor(B / denom));
|
|
4
|
+
return N;
|
|
5
|
+
}
|
|
6
|
+
function estimateRByFormula(sample) {
|
|
7
|
+
const len = sample.length;
|
|
8
|
+
const slashes = (sample.match(/\\/g) || []).length;
|
|
9
|
+
const score = len + slashes * 10;
|
|
10
|
+
if (score < 10)
|
|
11
|
+
return "simple";
|
|
12
|
+
if (score < 40)
|
|
13
|
+
return "medium";
|
|
14
|
+
return "complex";
|
|
15
|
+
}
|
|
16
|
+
function defaultRByClass(cls) {
|
|
17
|
+
switch (cls) {
|
|
18
|
+
case "simple":
|
|
19
|
+
return 3;
|
|
20
|
+
case "medium":
|
|
21
|
+
return 10;
|
|
22
|
+
case "complex":
|
|
23
|
+
return 30;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function recommendNForSamples(formulas, opts) {
|
|
27
|
+
let maxR = 0;
|
|
28
|
+
for (const f of formulas) {
|
|
29
|
+
const cls = estimateRByFormula(f);
|
|
30
|
+
const R = defaultRByClass(cls);
|
|
31
|
+
if (R > maxR)
|
|
32
|
+
maxR = R;
|
|
33
|
+
}
|
|
34
|
+
return recommendWorkerThreshold({ R: maxR, H: opts?.H ?? 0, B: opts?.B ?? 50 });
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
defaultRByClass,
|
|
38
|
+
estimateRByFormula,
|
|
39
|
+
recommendNForSamples,
|
|
40
|
+
recommendWorkerThreshold
|
|
41
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
class PerformanceMonitor {
|
|
2
|
+
metrics = [];
|
|
3
|
+
enabled = false;
|
|
4
|
+
maxMetrics = 1e3;
|
|
5
|
+
// Prevent memory leak
|
|
6
|
+
enable() {
|
|
7
|
+
this.enabled = true;
|
|
8
|
+
}
|
|
9
|
+
disable() {
|
|
10
|
+
this.enabled = false;
|
|
11
|
+
}
|
|
12
|
+
recordRender(metrics) {
|
|
13
|
+
if (!this.enabled)
|
|
14
|
+
return;
|
|
15
|
+
this.metrics.push(metrics);
|
|
16
|
+
if (this.metrics.length > this.maxMetrics) {
|
|
17
|
+
this.metrics.shift();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getStats() {
|
|
21
|
+
if (this.metrics.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
totalRenders: 0,
|
|
24
|
+
cacheHitRate: 0,
|
|
25
|
+
averageWorkerTime: 0,
|
|
26
|
+
averageDirectTime: 0,
|
|
27
|
+
averageCacheHitTime: 0,
|
|
28
|
+
workerSavings: 0,
|
|
29
|
+
recommendation: "Insufficient data"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const workerMetrics = this.metrics.filter((m) => m.type === "worker" && m.success);
|
|
33
|
+
const directMetrics = this.metrics.filter((m) => m.type === "direct" && m.success);
|
|
34
|
+
const cacheHitMetrics = this.metrics.filter((m) => m.type === "cache-hit");
|
|
35
|
+
const totalRenders = this.metrics.length;
|
|
36
|
+
const cacheHits = cacheHitMetrics.length;
|
|
37
|
+
const cacheHitRate = cacheHits / totalRenders * 100;
|
|
38
|
+
const avgWorkerTime = workerMetrics.length > 0 ? workerMetrics.reduce((sum, m) => sum + m.duration, 0) / workerMetrics.length : 0;
|
|
39
|
+
const avgDirectTime = directMetrics.length > 0 ? directMetrics.reduce((sum, m) => sum + m.duration, 0) / directMetrics.length : 0;
|
|
40
|
+
const avgCacheHitTime = cacheHitMetrics.length > 0 ? cacheHitMetrics.reduce((sum, m) => sum + m.duration, 0) / cacheHitMetrics.length : 0;
|
|
41
|
+
const estimatedDirectTime = totalRenders * avgDirectTime;
|
|
42
|
+
const actualTime = workerMetrics.reduce((sum, m) => sum + m.duration, 0) + directMetrics.reduce((sum, m) => sum + m.duration, 0) + cacheHitMetrics.reduce((sum, m) => sum + m.duration, 0);
|
|
43
|
+
const workerSavings = estimatedDirectTime - actualTime;
|
|
44
|
+
let recommendation = "";
|
|
45
|
+
if (cacheHitRate > 70 && avgWorkerTime < avgDirectTime * 2) {
|
|
46
|
+
recommendation = "✅ Worker + Cache is highly beneficial";
|
|
47
|
+
} else if (cacheHitRate > 50) {
|
|
48
|
+
recommendation = "✅ Worker + Cache is beneficial";
|
|
49
|
+
} else if (avgWorkerTime > avgDirectTime * 3) {
|
|
50
|
+
recommendation = "⚠️ Worker overhead too high, consider direct rendering";
|
|
51
|
+
} else if (avgDirectTime < 5) {
|
|
52
|
+
recommendation = "⚠️ Formulas too simple, Worker overhead may not be worth it";
|
|
53
|
+
} else {
|
|
54
|
+
recommendation = "✅ Worker prevents main thread blocking";
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
totalRenders,
|
|
58
|
+
cacheHits,
|
|
59
|
+
cacheHitRate: cacheHitRate.toFixed(1),
|
|
60
|
+
workerCalls: workerMetrics.length,
|
|
61
|
+
directCalls: directMetrics.length,
|
|
62
|
+
averageWorkerTime: avgWorkerTime.toFixed(2),
|
|
63
|
+
averageDirectTime: avgDirectTime.toFixed(2),
|
|
64
|
+
averageCacheHitTime: avgCacheHitTime.toFixed(3),
|
|
65
|
+
workerSavings: workerSavings.toFixed(2),
|
|
66
|
+
recommendation
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
printReport() {
|
|
70
|
+
const stats = this.getStats();
|
|
71
|
+
console.group("📊 KaTeX Rendering Performance Report");
|
|
72
|
+
console.log(`Total renders: ${stats.totalRenders}`);
|
|
73
|
+
console.log(`Cache hits: ${stats.cacheHits} (${stats.cacheHitRate}%)`);
|
|
74
|
+
console.log(`Worker calls: ${stats.workerCalls}`);
|
|
75
|
+
console.log(`Direct calls: ${stats.directCalls}`);
|
|
76
|
+
console.log("");
|
|
77
|
+
console.log("Timing:");
|
|
78
|
+
console.log(` Worker average: ${stats.averageWorkerTime}ms`);
|
|
79
|
+
console.log(` Direct average: ${stats.averageDirectTime}ms`);
|
|
80
|
+
console.log(` Cache hit average: ${stats.averageCacheHitTime}ms`);
|
|
81
|
+
console.log("");
|
|
82
|
+
console.log(`Time saved: ${stats.workerSavings}ms`);
|
|
83
|
+
console.log(`Recommendation: ${stats.recommendation}`);
|
|
84
|
+
console.groupEnd();
|
|
85
|
+
return stats;
|
|
86
|
+
}
|
|
87
|
+
reset() {
|
|
88
|
+
this.metrics = [];
|
|
89
|
+
}
|
|
90
|
+
// Export metrics for analysis
|
|
91
|
+
exportMetrics() {
|
|
92
|
+
return {
|
|
93
|
+
metrics: [...this.metrics],
|
|
94
|
+
stats: this.getStats(),
|
|
95
|
+
timestamp: Date.now()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const perfMonitor = new PerformanceMonitor();
|
|
100
|
+
function enablePerfMonitoring() {
|
|
101
|
+
perfMonitor.enable();
|
|
102
|
+
console.log("📊 KaTeX performance monitoring enabled");
|
|
103
|
+
}
|
|
104
|
+
function disablePerfMonitoring() {
|
|
105
|
+
perfMonitor.disable();
|
|
106
|
+
console.log("📊 KaTeX performance monitoring disabled");
|
|
107
|
+
}
|
|
108
|
+
function getPerfReport() {
|
|
109
|
+
return perfMonitor.printReport();
|
|
110
|
+
}
|
|
111
|
+
if (typeof window !== "undefined") {
|
|
112
|
+
window.__katexPerfReport = getPerfReport;
|
|
113
|
+
window.__katexPerfMonitor = perfMonitor;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
disablePerfMonitoring,
|
|
117
|
+
enablePerfMonitoring,
|
|
118
|
+
getPerfReport,
|
|
119
|
+
perfMonitor
|
|
120
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function safeRaf(cb) {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.requestAnimationFrame === "function")
|
|
4
|
+
return globalThis.requestAnimationFrame(cb);
|
|
5
|
+
} catch {
|
|
6
|
+
}
|
|
7
|
+
return globalThis.setTimeout(cb, 0);
|
|
8
|
+
}
|
|
9
|
+
function safeCancelRaf(id) {
|
|
10
|
+
try {
|
|
11
|
+
if (id == null)
|
|
12
|
+
return;
|
|
13
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.cancelAnimationFrame === "function") {
|
|
14
|
+
globalThis.cancelAnimationFrame(id);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
;
|
|
21
|
+
globalThis.clearTimeout(id);
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
safeCancelRaf,
|
|
27
|
+
safeRaf
|
|
28
|
+
};
|