@octanejs/streamdown 0.1.0
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/LICENSE +13 -0
- package/README.md +39 -0
- package/UPSTREAM.md +15 -0
- package/dist/client/chunks/chunk-6IDAODM4.js +4809 -0
- package/dist/client/chunks/highlighted-body-PYQZ7NZ4.js +69 -0
- package/dist/client/chunks/mermaid-I6WR5JDC.js +7 -0
- package/dist/client/cjk.js +104 -0
- package/dist/client/code.js +115 -0
- package/dist/client/index.js +57 -0
- package/dist/client/math.js +30 -0
- package/dist/client/mermaid.js +46 -0
- package/dist/server/chunks/chunk-55X6YY2C.js +4526 -0
- package/dist/server/chunks/highlighted-body-NLELYOBH.js +60 -0
- package/dist/server/chunks/mermaid-SICAYVAP.js +7 -0
- package/dist/server/cjk.js +104 -0
- package/dist/server/code.js +115 -0
- package/dist/server/index.js +57 -0
- package/dist/server/math.js +30 -0
- package/dist/server/mermaid.js +46 -0
- package/dist/styles.css +35 -0
- package/dist/types/cjk.d.ts +32 -0
- package/dist/types/code.d.ts +58 -0
- package/dist/types/hooks/use-deferred-render.d.ts +60 -0
- package/dist/types/index.d.ts +161 -0
- package/dist/types/lib/animate.d.ts +33 -0
- package/dist/types/lib/block-incomplete-context.d.ts +15 -0
- package/dist/types/lib/code-block/body.d.ts +12 -0
- package/dist/types/lib/code-block/container.d.ts +10 -0
- package/dist/types/lib/code-block/context.d.ts +7 -0
- package/dist/types/lib/code-block/copy-button.d.ts +10 -0
- package/dist/types/lib/code-block/download-button.d.ts +10 -0
- package/dist/types/lib/code-block/header.d.ts +6 -0
- package/dist/types/lib/code-block/highlighted-body.d.ts +12 -0
- package/dist/types/lib/code-block/index.d.ts +14 -0
- package/dist/types/lib/code-block/skeleton.d.ts +2 -0
- package/dist/types/lib/components.d.ts +3 -0
- package/dist/types/lib/detect-direction.d.ts +14 -0
- package/dist/types/lib/icon-context.d.ts +25 -0
- package/dist/types/lib/icons.d.ts +17 -0
- package/dist/types/lib/image.d.ts +6 -0
- package/dist/types/lib/incomplete-code-utils.d.ts +25 -0
- package/dist/types/lib/link-modal.d.ts +9 -0
- package/dist/types/lib/markdown.d.ts +33 -0
- package/dist/types/lib/mermaid/download-button.d.ts +13 -0
- package/dist/types/lib/mermaid/fullscreen-button.d.ts +11 -0
- package/dist/types/lib/mermaid/index.d.ts +11 -0
- package/dist/types/lib/mermaid/pan-zoom.d.ts +14 -0
- package/dist/types/lib/mermaid/utils.d.ts +7 -0
- package/dist/types/lib/parse-blocks.d.ts +2 -0
- package/dist/types/lib/plugin-context.d.ts +30 -0
- package/dist/types/lib/plugin-types.d.ts +151 -0
- package/dist/types/lib/prefix-context.d.ts +13 -0
- package/dist/types/lib/preprocess-custom-tags.d.ts +20 -0
- package/dist/types/lib/preprocess-literal-tag-content.d.ts +25 -0
- package/dist/types/lib/rehype/literal-tag-content.d.ts +13 -0
- package/dist/types/lib/remark/code-meta.d.ts +10 -0
- package/dist/types/lib/remark/escape-html.d.ts +4 -0
- package/dist/types/lib/scroll-lock.d.ts +3 -0
- package/dist/types/lib/table/copy-dropdown.d.ts +10 -0
- package/dist/types/lib/table/download-dropdown.d.ts +18 -0
- package/dist/types/lib/table/fullscreen-button.d.ts +10 -0
- package/dist/types/lib/table/index.d.ts +10 -0
- package/dist/types/lib/table/utils.d.ts +11 -0
- package/dist/types/lib/translations-context.d.ts +35 -0
- package/dist/types/lib/types.d.ts +17 -0
- package/dist/types/lib/utils.d.ts +19 -0
- package/dist/types/math.d.ts +44 -0
- package/dist/types/mermaid-plugin.d.ts +44 -0
- package/package.json +121 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
import {
|
|
3
|
+
CodeBlockBody,
|
|
4
|
+
StreamdownContext,
|
|
5
|
+
useCodePlugin
|
|
6
|
+
} from "./chunk-6IDAODM4.js";
|
|
7
|
+
|
|
8
|
+
// src/lib/code-block/highlighted-body.tsrx
|
|
9
|
+
import {
|
|
10
|
+
createElement as _$createElement,
|
|
11
|
+
createScopedValue as _$createScopedValue,
|
|
12
|
+
hookSlots as _$hookSlots,
|
|
13
|
+
useContext,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
withSlot as _$withSlot
|
|
19
|
+
} from "octane";
|
|
20
|
+
var _hs$ = /* @__PURE__ */ _$hookSlots(5);
|
|
21
|
+
var _h$0 = /* @__PURE__ */ Symbol(_hs$);
|
|
22
|
+
var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
|
|
23
|
+
var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
|
|
24
|
+
var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
|
|
25
|
+
var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
|
|
26
|
+
var HighlightedCodeBlockBody = ({
|
|
27
|
+
code,
|
|
28
|
+
language,
|
|
29
|
+
raw,
|
|
30
|
+
className,
|
|
31
|
+
startLine,
|
|
32
|
+
lineNumbers,
|
|
33
|
+
...rest
|
|
34
|
+
}) => {
|
|
35
|
+
const { shikiTheme } = useContext(StreamdownContext);
|
|
36
|
+
const codePlugin = _$withSlot(_h$0, useCodePlugin, _h$0);
|
|
37
|
+
const request = useMemo(() => ({ code, language, plugin: codePlugin, themes: shikiTheme }), [code, language, codePlugin, shikiTheme], _h$1);
|
|
38
|
+
const [highlight, setHighlight] = useState({ request, result: raw }, _h$2);
|
|
39
|
+
const requestRef = useRef(request, _h$3);
|
|
40
|
+
requestRef.current = request;
|
|
41
|
+
const result = highlight.request === request ? highlight.result : raw;
|
|
42
|
+
useEffect(
|
|
43
|
+
() => {
|
|
44
|
+
const commit = (nextResult) => {
|
|
45
|
+
if (requestRef.current !== request) return;
|
|
46
|
+
setHighlight({ request, result: nextResult });
|
|
47
|
+
};
|
|
48
|
+
if (!request.plugin) {
|
|
49
|
+
commit(raw);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const cachedResult = request.plugin.highlight(
|
|
53
|
+
{
|
|
54
|
+
code: request.code,
|
|
55
|
+
language: request.language,
|
|
56
|
+
themes: request.themes
|
|
57
|
+
},
|
|
58
|
+
commit
|
|
59
|
+
);
|
|
60
|
+
if (cachedResult) commit(cachedResult);
|
|
61
|
+
},
|
|
62
|
+
[request, raw],
|
|
63
|
+
_h$4
|
|
64
|
+
);
|
|
65
|
+
return _$createScopedValue(() => _$createElement(CodeBlockBody, { className, language, lineNumbers, result, startLine, ...rest }));
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
HighlightedCodeBlockBody
|
|
69
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/cjk.ts
|
|
5
|
+
import remarkCjkFriendly from "remark-cjk-friendly";
|
|
6
|
+
import remarkCjkFriendlyGfmStrikethrough from "remark-cjk-friendly-gfm-strikethrough";
|
|
7
|
+
import { visit } from "unist-util-visit";
|
|
8
|
+
var CJK_AUTOLINK_BOUNDARY_CHARS = /* @__PURE__ */ new Set([
|
|
9
|
+
"\u3002",
|
|
10
|
+
"\uFF0E",
|
|
11
|
+
"\uFF0C",
|
|
12
|
+
"\u3001",
|
|
13
|
+
"\uFF1F",
|
|
14
|
+
"\uFF01",
|
|
15
|
+
"\uFF1A",
|
|
16
|
+
"\uFF1B",
|
|
17
|
+
"\uFF08",
|
|
18
|
+
"\uFF09",
|
|
19
|
+
"\u3010",
|
|
20
|
+
"\u3011",
|
|
21
|
+
"\u300C",
|
|
22
|
+
"\u300D",
|
|
23
|
+
"\u300E",
|
|
24
|
+
"\u300F",
|
|
25
|
+
"\u3008",
|
|
26
|
+
"\u3009",
|
|
27
|
+
"\u300A",
|
|
28
|
+
"\u300B"
|
|
29
|
+
]);
|
|
30
|
+
var AUTOLINK_PREFIX_PATTERN = /^(https?:\/\/|mailto:|www\.)/i;
|
|
31
|
+
var isAutolinkLiteral = (node) => {
|
|
32
|
+
if (node.children.length !== 1) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const child = node.children[0];
|
|
36
|
+
return child.type === "text" && child.value === node.url;
|
|
37
|
+
};
|
|
38
|
+
var findCjkBoundaryIndex = (url) => {
|
|
39
|
+
let index = 0;
|
|
40
|
+
for (const char of url) {
|
|
41
|
+
if (CJK_AUTOLINK_BOUNDARY_CHARS.has(char)) {
|
|
42
|
+
return index;
|
|
43
|
+
}
|
|
44
|
+
index += char.length;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
var buildAutolink = (url, source) => ({
|
|
49
|
+
...source,
|
|
50
|
+
url,
|
|
51
|
+
children: [
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
value: url
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
var buildTrailingText = (value) => ({
|
|
59
|
+
type: "text",
|
|
60
|
+
value
|
|
61
|
+
});
|
|
62
|
+
var remarkCjkAutolinkBoundary = () => (tree) => {
|
|
63
|
+
visit(tree, "link", (node, index, parent) => {
|
|
64
|
+
if (!parent || typeof index !== "number") {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!isAutolinkLiteral(node)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!AUTOLINK_PREFIX_PATTERN.test(node.url)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const boundaryIndex = findCjkBoundaryIndex(node.url);
|
|
74
|
+
if (boundaryIndex === null || boundaryIndex === 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const trimmedUrl = node.url.slice(0, boundaryIndex);
|
|
78
|
+
const trailing = node.url.slice(boundaryIndex);
|
|
79
|
+
const trimmedLink = buildAutolink(trimmedUrl, node);
|
|
80
|
+
const trailingText = buildTrailingText(trailing);
|
|
81
|
+
parent.children.splice(index, 1, trimmedLink, trailingText);
|
|
82
|
+
return index + 1;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
function createCjkPlugin() {
|
|
86
|
+
const remarkPluginsBefore = [remarkCjkFriendly];
|
|
87
|
+
const remarkPluginsAfter = [
|
|
88
|
+
remarkCjkAutolinkBoundary,
|
|
89
|
+
remarkCjkFriendlyGfmStrikethrough
|
|
90
|
+
];
|
|
91
|
+
const remarkPlugins = [...remarkPluginsBefore, ...remarkPluginsAfter];
|
|
92
|
+
return {
|
|
93
|
+
name: "cjk",
|
|
94
|
+
type: "cjk",
|
|
95
|
+
remarkPluginsBefore,
|
|
96
|
+
remarkPluginsAfter,
|
|
97
|
+
remarkPlugins
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var cjk = createCjkPlugin();
|
|
101
|
+
export {
|
|
102
|
+
cjk,
|
|
103
|
+
createCjkPlugin
|
|
104
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/code.ts
|
|
5
|
+
import {
|
|
6
|
+
bundledLanguages,
|
|
7
|
+
bundledLanguagesInfo,
|
|
8
|
+
createHighlighter
|
|
9
|
+
} from "shiki";
|
|
10
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
11
|
+
var jsEngine = createJavaScriptRegexEngine({ forgiving: true });
|
|
12
|
+
var languageAliases = Object.fromEntries(
|
|
13
|
+
bundledLanguagesInfo.flatMap(
|
|
14
|
+
(info) => (info.aliases ?? []).map((alias) => [alias, info.id])
|
|
15
|
+
)
|
|
16
|
+
);
|
|
17
|
+
var languageNames = new Set(Object.keys(bundledLanguages));
|
|
18
|
+
var normalizeLanguage = (language) => {
|
|
19
|
+
const trimmed = language.trim();
|
|
20
|
+
const lower = trimmed.toLowerCase();
|
|
21
|
+
const alias = languageAliases[lower];
|
|
22
|
+
if (alias) {
|
|
23
|
+
return alias;
|
|
24
|
+
}
|
|
25
|
+
if (languageNames.has(lower)) {
|
|
26
|
+
return lower;
|
|
27
|
+
}
|
|
28
|
+
return lower;
|
|
29
|
+
};
|
|
30
|
+
var highlighterCache = /* @__PURE__ */ new Map();
|
|
31
|
+
var tokensCache = /* @__PURE__ */ new Map();
|
|
32
|
+
var subscribers = /* @__PURE__ */ new Map();
|
|
33
|
+
var getThemeName = (theme) => typeof theme === "string" ? theme : theme.name ?? "custom";
|
|
34
|
+
var getHighlighterCacheKey = (language, themes) => `${language}-${getThemeName(themes[0])}-${getThemeName(themes[1])}`;
|
|
35
|
+
var getTokensCacheKey = (code2, language, themeNames) => {
|
|
36
|
+
const start = code2.slice(0, 100);
|
|
37
|
+
const end = code2.length > 100 ? code2.slice(-100) : "";
|
|
38
|
+
return `${language}:${themeNames[0]}:${themeNames[1]}:${code2.length}:${start}:${end}`;
|
|
39
|
+
};
|
|
40
|
+
var getHighlighter = (language, themes) => {
|
|
41
|
+
const cacheKey = getHighlighterCacheKey(language, themes);
|
|
42
|
+
if (highlighterCache.has(cacheKey)) {
|
|
43
|
+
return highlighterCache.get(cacheKey);
|
|
44
|
+
}
|
|
45
|
+
const highlighterPromise = createHighlighter({
|
|
46
|
+
themes,
|
|
47
|
+
langs: [language],
|
|
48
|
+
engine: jsEngine
|
|
49
|
+
});
|
|
50
|
+
highlighterCache.set(cacheKey, highlighterPromise);
|
|
51
|
+
return highlighterPromise;
|
|
52
|
+
};
|
|
53
|
+
function createCodePlugin(options = {}) {
|
|
54
|
+
const defaultThemes = options.themes ?? ["github-light", "github-dark"];
|
|
55
|
+
return {
|
|
56
|
+
name: "shiki",
|
|
57
|
+
type: "code-highlighter",
|
|
58
|
+
supportsLanguage(language) {
|
|
59
|
+
const resolvedLanguage = normalizeLanguage(language);
|
|
60
|
+
return languageNames.has(resolvedLanguage);
|
|
61
|
+
},
|
|
62
|
+
getSupportedLanguages() {
|
|
63
|
+
return Array.from(languageNames);
|
|
64
|
+
},
|
|
65
|
+
getThemes() {
|
|
66
|
+
return defaultThemes;
|
|
67
|
+
},
|
|
68
|
+
highlight({ code: code2, language, themes }, callback) {
|
|
69
|
+
const resolvedLanguage = normalizeLanguage(language);
|
|
70
|
+
const themeNames = [getThemeName(themes[0]), getThemeName(themes[1])];
|
|
71
|
+
const tokensCacheKey = getTokensCacheKey(code2, resolvedLanguage, themeNames);
|
|
72
|
+
if (tokensCache.has(tokensCacheKey)) {
|
|
73
|
+
return tokensCache.get(tokensCacheKey);
|
|
74
|
+
}
|
|
75
|
+
if (callback) {
|
|
76
|
+
if (!subscribers.has(tokensCacheKey)) {
|
|
77
|
+
subscribers.set(tokensCacheKey, /* @__PURE__ */ new Set());
|
|
78
|
+
}
|
|
79
|
+
const subs = subscribers.get(tokensCacheKey);
|
|
80
|
+
subs.add(callback);
|
|
81
|
+
}
|
|
82
|
+
const safeLanguage = languageNames.has(
|
|
83
|
+
resolvedLanguage
|
|
84
|
+
) ? resolvedLanguage : "text";
|
|
85
|
+
getHighlighter(safeLanguage, themes).then((highlighter) => {
|
|
86
|
+
const availableLangs = highlighter.getLoadedLanguages();
|
|
87
|
+
const langToUse = availableLangs.includes(resolvedLanguage) ? resolvedLanguage : "text";
|
|
88
|
+
const result = highlighter.codeToTokens(code2, {
|
|
89
|
+
lang: langToUse,
|
|
90
|
+
themes: {
|
|
91
|
+
light: themeNames[0],
|
|
92
|
+
dark: themeNames[1]
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
tokensCache.set(tokensCacheKey, result);
|
|
96
|
+
const subs = subscribers.get(tokensCacheKey);
|
|
97
|
+
if (subs) {
|
|
98
|
+
for (const sub of subs) {
|
|
99
|
+
sub(result);
|
|
100
|
+
}
|
|
101
|
+
subscribers.delete(tokensCacheKey);
|
|
102
|
+
}
|
|
103
|
+
}).catch((error) => {
|
|
104
|
+
console.error("[Streamdown Code] Failed to highlight code:", error);
|
|
105
|
+
subscribers.delete(tokensCacheKey);
|
|
106
|
+
});
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var code = createCodePlugin();
|
|
112
|
+
export {
|
|
113
|
+
code,
|
|
114
|
+
createCodePlugin
|
|
115
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
import {
|
|
3
|
+
Block,
|
|
4
|
+
CodeBlock,
|
|
5
|
+
CodeBlockContainer,
|
|
6
|
+
CodeBlockCopyButton,
|
|
7
|
+
CodeBlockDownloadButton,
|
|
8
|
+
CodeBlockHeader,
|
|
9
|
+
CodeBlockSkeleton,
|
|
10
|
+
Streamdown,
|
|
11
|
+
StreamdownContext,
|
|
12
|
+
TableCopyDropdown,
|
|
13
|
+
TableDownloadButton,
|
|
14
|
+
TableDownloadDropdown,
|
|
15
|
+
createAnimatePlugin,
|
|
16
|
+
defaultRehypePlugins,
|
|
17
|
+
defaultRemarkPlugins,
|
|
18
|
+
defaultTranslations,
|
|
19
|
+
defaultUrlTransform,
|
|
20
|
+
detectTextDirection,
|
|
21
|
+
escapeMarkdownTableCell,
|
|
22
|
+
extractTableDataFromElement,
|
|
23
|
+
normalizeHtmlIndentation,
|
|
24
|
+
parseMarkdownIntoBlocks,
|
|
25
|
+
tableDataToCSV,
|
|
26
|
+
tableDataToMarkdown,
|
|
27
|
+
tableDataToTSV,
|
|
28
|
+
useIsCodeFenceIncomplete
|
|
29
|
+
} from "./chunks/chunk-6IDAODM4.js";
|
|
30
|
+
export {
|
|
31
|
+
Block,
|
|
32
|
+
CodeBlock,
|
|
33
|
+
CodeBlockContainer,
|
|
34
|
+
CodeBlockCopyButton,
|
|
35
|
+
CodeBlockDownloadButton,
|
|
36
|
+
CodeBlockHeader,
|
|
37
|
+
CodeBlockSkeleton,
|
|
38
|
+
Streamdown,
|
|
39
|
+
StreamdownContext,
|
|
40
|
+
TableCopyDropdown,
|
|
41
|
+
TableDownloadButton,
|
|
42
|
+
TableDownloadDropdown,
|
|
43
|
+
createAnimatePlugin,
|
|
44
|
+
defaultRehypePlugins,
|
|
45
|
+
defaultRemarkPlugins,
|
|
46
|
+
defaultTranslations,
|
|
47
|
+
defaultUrlTransform,
|
|
48
|
+
detectTextDirection,
|
|
49
|
+
escapeMarkdownTableCell,
|
|
50
|
+
extractTableDataFromElement,
|
|
51
|
+
normalizeHtmlIndentation,
|
|
52
|
+
parseMarkdownIntoBlocks,
|
|
53
|
+
tableDataToCSV,
|
|
54
|
+
tableDataToMarkdown,
|
|
55
|
+
tableDataToTSV,
|
|
56
|
+
useIsCodeFenceIncomplete
|
|
57
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/math.ts
|
|
5
|
+
import rehypeKatex from "rehype-katex";
|
|
6
|
+
import remarkMath from "remark-math";
|
|
7
|
+
function createMathPlugin(options = {}) {
|
|
8
|
+
const remarkMathPlugin = [
|
|
9
|
+
remarkMath,
|
|
10
|
+
{ singleDollarTextMath: options.singleDollarTextMath ?? false }
|
|
11
|
+
];
|
|
12
|
+
const rehypeKatexPlugin = [
|
|
13
|
+
rehypeKatex,
|
|
14
|
+
{ errorColor: options.errorColor ?? "var(--color-muted-foreground)" }
|
|
15
|
+
];
|
|
16
|
+
return {
|
|
17
|
+
name: "katex",
|
|
18
|
+
type: "math",
|
|
19
|
+
remarkPlugin: remarkMathPlugin,
|
|
20
|
+
rehypePlugin: rehypeKatexPlugin,
|
|
21
|
+
getStyles() {
|
|
22
|
+
return "katex/dist/katex.min.css";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var math = createMathPlugin();
|
|
27
|
+
export {
|
|
28
|
+
createMathPlugin,
|
|
29
|
+
math
|
|
30
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// octane-no-slot: this package already contains compiler-assigned hook slots.
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/mermaid-plugin.ts
|
|
5
|
+
import mermaidLib from "mermaid";
|
|
6
|
+
var defaultConfig = {
|
|
7
|
+
startOnLoad: false,
|
|
8
|
+
theme: "default",
|
|
9
|
+
securityLevel: "strict",
|
|
10
|
+
fontFamily: "monospace",
|
|
11
|
+
suppressErrorRendering: true
|
|
12
|
+
};
|
|
13
|
+
function createMermaidPlugin(options = {}) {
|
|
14
|
+
let initialized = false;
|
|
15
|
+
let currentConfig = { ...defaultConfig, ...options.config };
|
|
16
|
+
const mermaidInstance = {
|
|
17
|
+
initialize(config) {
|
|
18
|
+
currentConfig = { ...defaultConfig, ...options.config, ...config };
|
|
19
|
+
mermaidLib.initialize(currentConfig);
|
|
20
|
+
initialized = true;
|
|
21
|
+
},
|
|
22
|
+
async render(id, source) {
|
|
23
|
+
if (!initialized) {
|
|
24
|
+
mermaidLib.initialize(currentConfig);
|
|
25
|
+
initialized = true;
|
|
26
|
+
}
|
|
27
|
+
return await mermaidLib.render(id, source);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
name: "mermaid",
|
|
32
|
+
type: "diagram",
|
|
33
|
+
language: "mermaid",
|
|
34
|
+
getMermaid(config) {
|
|
35
|
+
if (config) {
|
|
36
|
+
mermaidInstance.initialize(config);
|
|
37
|
+
}
|
|
38
|
+
return mermaidInstance;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var mermaid = createMermaidPlugin();
|
|
43
|
+
export {
|
|
44
|
+
createMermaidPlugin,
|
|
45
|
+
mermaid
|
|
46
|
+
};
|