@affanhamid/markdown-renderer 2.3.0 → 2.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.cjs CHANGED
@@ -1069,39 +1069,45 @@ var MarkdownRenderer = ({
1069
1069
  };
1070
1070
  }, [html, handleRun]);
1071
1071
  (0, import_react.useEffect)(() => {
1072
- const container = containerRef.current;
1073
- if (!container) return;
1074
- const mermaidBlocks = container.querySelectorAll(".md-mermaid");
1075
- if (mermaidBlocks.length === 0) return;
1076
1072
  let alive = true;
1077
- void (async () => {
1078
- try {
1079
- const mermaid = (await import("mermaid")).default;
1080
- mermaid.initialize({
1081
- startOnLoad: false,
1082
- securityLevel: "antiscript",
1083
- theme: "neutral",
1084
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
1085
- fontSize: 13,
1086
- htmlLabels: false,
1087
- flowchart: { useMaxWidth: true, htmlLabels: false },
1088
- sequence: { useMaxWidth: true }
1089
- });
1090
- for (const block of Array.from(mermaidBlocks)) {
1091
- if (!alive) break;
1092
- const code = block.getAttribute("data-mermaid-code") || "";
1093
- const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
1094
- try {
1095
- const { svg } = await mermaid.render(id, code.trim());
1096
- block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
1097
- } catch {
1073
+ const rafId = requestAnimationFrame(() => {
1074
+ const container = containerRef.current;
1075
+ if (!container || !alive) return;
1076
+ const mermaidBlocks = container.querySelectorAll(".md-mermaid");
1077
+ if (mermaidBlocks.length === 0) return;
1078
+ void (async () => {
1079
+ try {
1080
+ const mermaid = (await import("mermaid")).default;
1081
+ if (!alive) return;
1082
+ mermaid.initialize({
1083
+ startOnLoad: false,
1084
+ securityLevel: "antiscript",
1085
+ theme: "neutral",
1086
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
1087
+ fontSize: 13,
1088
+ htmlLabels: false,
1089
+ flowchart: { useMaxWidth: true, htmlLabels: false },
1090
+ sequence: { useMaxWidth: true }
1091
+ });
1092
+ for (const block of Array.from(mermaidBlocks)) {
1093
+ if (!alive) break;
1094
+ const code = block.getAttribute("data-mermaid-code") || "";
1095
+ const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
1096
+ try {
1097
+ const { svg } = await mermaid.render(id, code.trim());
1098
+ if (alive) {
1099
+ block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
1100
+ }
1101
+ } catch {
1102
+ }
1098
1103
  }
1104
+ } catch {
1099
1105
  }
1100
- } catch {
1101
- }
1102
- })();
1106
+ })();
1107
+ });
1103
1108
  return () => {
1104
1109
  alive = false;
1110
+ cancelAnimationFrame(rafId);
1105
1111
  };
1106
1112
  }, [html]);
1107
1113
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: containerRef, className, dangerouslySetInnerHTML: { __html: html } });
package/dist/index.js CHANGED
@@ -1030,39 +1030,45 @@ var MarkdownRenderer = ({
1030
1030
  };
1031
1031
  }, [html, handleRun]);
1032
1032
  useEffect(() => {
1033
- const container = containerRef.current;
1034
- if (!container) return;
1035
- const mermaidBlocks = container.querySelectorAll(".md-mermaid");
1036
- if (mermaidBlocks.length === 0) return;
1037
1033
  let alive = true;
1038
- void (async () => {
1039
- try {
1040
- const mermaid = (await import("mermaid")).default;
1041
- mermaid.initialize({
1042
- startOnLoad: false,
1043
- securityLevel: "antiscript",
1044
- theme: "neutral",
1045
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
1046
- fontSize: 13,
1047
- htmlLabels: false,
1048
- flowchart: { useMaxWidth: true, htmlLabels: false },
1049
- sequence: { useMaxWidth: true }
1050
- });
1051
- for (const block of Array.from(mermaidBlocks)) {
1052
- if (!alive) break;
1053
- const code = block.getAttribute("data-mermaid-code") || "";
1054
- const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
1055
- try {
1056
- const { svg } = await mermaid.render(id, code.trim());
1057
- block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
1058
- } catch {
1034
+ const rafId = requestAnimationFrame(() => {
1035
+ const container = containerRef.current;
1036
+ if (!container || !alive) return;
1037
+ const mermaidBlocks = container.querySelectorAll(".md-mermaid");
1038
+ if (mermaidBlocks.length === 0) return;
1039
+ void (async () => {
1040
+ try {
1041
+ const mermaid = (await import("mermaid")).default;
1042
+ if (!alive) return;
1043
+ mermaid.initialize({
1044
+ startOnLoad: false,
1045
+ securityLevel: "antiscript",
1046
+ theme: "neutral",
1047
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
1048
+ fontSize: 13,
1049
+ htmlLabels: false,
1050
+ flowchart: { useMaxWidth: true, htmlLabels: false },
1051
+ sequence: { useMaxWidth: true }
1052
+ });
1053
+ for (const block of Array.from(mermaidBlocks)) {
1054
+ if (!alive) break;
1055
+ const code = block.getAttribute("data-mermaid-code") || "";
1056
+ const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
1057
+ try {
1058
+ const { svg } = await mermaid.render(id, code.trim());
1059
+ if (alive) {
1060
+ block.innerHTML = `<div style="display:flex;justify-content:center;overflow:auto;padding:1rem">${svg}</div>`;
1061
+ }
1062
+ } catch {
1063
+ }
1059
1064
  }
1065
+ } catch {
1060
1066
  }
1061
- } catch {
1062
- }
1063
- })();
1067
+ })();
1068
+ });
1064
1069
  return () => {
1065
1070
  alive = false;
1071
+ cancelAnimationFrame(rafId);
1066
1072
  };
1067
1073
  }, [html]);
1068
1074
  return /* @__PURE__ */ jsx("div", { ref: containerRef, className, dangerouslySetInnerHTML: { __html: html } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affanhamid/markdown-renderer",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Custom markdown renderer with KaTeX support",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",