@godxjp/markdown 33.21.0 → 33.22.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.
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // src/katex-styles.ts
4
+ import "../katex.css";
package/dist/lazy.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { e as MarkdownProps } from './fixtures-kHqqmyjB.js';
3
+ export { D as DirectiveRenderProps, a as DirectiveRenderer, H as HeadingIdResolver, b as HeadingInfo, M as MARKDOWN_FIXTURES, c as MARKDOWN_FORMAT, d as MarkdownFixture, f as MermaidDiagram, g as MermaidDiagramProps, h as MermaidSvgCheck, R as RENDERER_VERSION, S as SchemaExtension, i as checkMermaidSvg, j as extendSchema, m as markdownSchema, r as rehypeHeadingIds, s as safeUrl } from './fixtures-kHqqmyjB.js';
4
+ export { D as DirectiveBlock } from './directive-DqwrNF2I.js';
5
+ import 'react-markdown';
6
+ import 'hast';
7
+ import 'rehype-sanitize';
8
+
9
+ /**
10
+ * Loads the engines a body needs (both when `markdown` is omitted). Await it before a server
11
+ * render or a hydration that must match the eager entry's HTML.
12
+ */
13
+ declare function preloadMarkdownRuntime(markdown?: string): Promise<void>;
14
+ /** `<Markdown>` with its engines loaded on demand (see the module comment). Same props. */
15
+ declare function Markdown(props: MarkdownProps): React.JSX.Element;
16
+
17
+ export { Markdown, MarkdownProps, preloadMarkdownRuntime };
package/dist/lazy.js ADDED
@@ -0,0 +1,126 @@
1
+ "use client";
2
+ import {
3
+ MARKDOWN_FIXTURES,
4
+ MARKDOWN_FORMAT,
5
+ MarkdownCore,
6
+ MermaidDiagram,
7
+ RENDERER_VERSION,
8
+ checkMermaidSvg,
9
+ extendSchema,
10
+ fromMarkdownExtensions,
11
+ markdownSchema,
12
+ micromarkExtensions,
13
+ rehypeHeadingIds,
14
+ safeUrl
15
+ } from "./chunk-RRNN4HLQ.js";
16
+ import "./chunk-ANYWBQJT.js";
17
+ import "./chunk-AKKOCR2Y.js";
18
+
19
+ // src/lazy.tsx
20
+ import * as React from "react";
21
+
22
+ // src/codec/parse.ts
23
+ import { fromMarkdown } from "mdast-util-from-markdown";
24
+ import { toMarkdown } from "mdast-util-to-markdown";
25
+ function parseMdast(markdown) {
26
+ return fromMarkdown(markdown, {
27
+ extensions: micromarkExtensions(),
28
+ mdastExtensions: fromMarkdownExtensions()
29
+ });
30
+ }
31
+
32
+ // src/lazy.tsx
33
+ import { jsx } from "react/jsx-runtime";
34
+ var loaded = {};
35
+ var mathLoad;
36
+ var highlightLoad;
37
+ function loadMath() {
38
+ mathLoad ??= Promise.all([
39
+ import("./math-DOI7WLLZ.js"),
40
+ // The stylesheet only where there is a document to style (a server has none, and cannot
41
+ // import CSS).
42
+ typeof document === "undefined" ? void 0 : import("./katex-styles-JVRNFDYG.js")
43
+ ]).then(
44
+ ([math]) => {
45
+ loaded.math = math.rehypeMath;
46
+ },
47
+ (error) => {
48
+ mathLoad = void 0;
49
+ throw error;
50
+ }
51
+ );
52
+ return mathLoad;
53
+ }
54
+ function loadHighlight() {
55
+ highlightLoad ??= import("./highlight-TYIW3L3V.js").then(
56
+ (highlight) => {
57
+ loaded.highlight = highlight.rehypeHighlight;
58
+ },
59
+ (error) => {
60
+ highlightLoad = void 0;
61
+ throw error;
62
+ }
63
+ );
64
+ return highlightLoad;
65
+ }
66
+ function needsOf(tree) {
67
+ const needs = { math: false, highlight: false };
68
+ const walk = (node) => {
69
+ if (node.type === "inlineMath" || node.type === "math") needs.math = true;
70
+ else if (node.type === "code" && node.lang) {
71
+ if (node.lang === "math") needs.math = true;
72
+ else if (node.lang !== "mermaid") needs.highlight = true;
73
+ }
74
+ if ("children" in node) for (const child of node.children) walk(child);
75
+ };
76
+ walk(tree);
77
+ return needs;
78
+ }
79
+ function preloadMarkdownRuntime(markdown) {
80
+ const needs = markdown === void 0 ? { math: true, highlight: true } : needsOf(parseMdast(markdown));
81
+ return Promise.all([
82
+ needs.math ? loadMath() : void 0,
83
+ needs.highlight ? loadHighlight() : void 0
84
+ ]).then(() => void 0);
85
+ }
86
+ function Markdown(props) {
87
+ const needs = React.useRef({ math: false, highlight: false });
88
+ const [, rerender] = React.useReducer((n) => n + 1, 0);
89
+ const probe = React.useMemo(
90
+ () => () => (tree) => {
91
+ needs.current = needsOf(tree);
92
+ },
93
+ []
94
+ );
95
+ const highlight = props.highlight !== false;
96
+ React.useEffect(() => {
97
+ const pending = [
98
+ needs.current.math && !loaded.math ? loadMath() : void 0,
99
+ highlight && needs.current.highlight && !loaded.highlight ? loadHighlight() : void 0
100
+ ].filter(Boolean);
101
+ if (pending.length === 0) return;
102
+ let mounted = true;
103
+ Promise.all(pending).then(
104
+ () => mounted && rerender(),
105
+ () => void 0
106
+ // the fallback stays: a body without colour is still the body
107
+ );
108
+ return () => {
109
+ mounted = false;
110
+ };
111
+ });
112
+ return /* @__PURE__ */ jsx(MarkdownCore, { ...props, runtime: { math: loaded.math, highlight: loaded.highlight, probe } });
113
+ }
114
+ export {
115
+ MARKDOWN_FIXTURES,
116
+ MARKDOWN_FORMAT,
117
+ Markdown,
118
+ MermaidDiagram,
119
+ RENDERER_VERSION,
120
+ checkMermaidSvg,
121
+ extendSchema,
122
+ markdownSchema,
123
+ preloadMarkdownRuntime,
124
+ rehypeHeadingIds,
125
+ safeUrl
126
+ };
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import {
3
+ rehypeMath
4
+ } from "./chunk-JJ2A3D7U.js";
5
+ import {
6
+ KATEX_OPTIONS,
7
+ katexSchema
8
+ } from "./chunk-AKKOCR2Y.js";
9
+ export {
10
+ KATEX_OPTIONS,
11
+ katexSchema,
12
+ rehypeMath
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godxjp/markdown",
3
- "version": "33.21.0",
3
+ "version": "33.22.2",
4
4
  "description": "The one Markdown renderer for GoDX apps: GFM + heading anchors, KaTeX math, highlighted code, one sanitiser schema, a shared fixture corpus, and Mermaid drawn only after its SVG passes a fail-closed gate.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,10 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js"
13
13
  },
14
+ "./lazy": {
15
+ "types": "./dist/lazy.d.ts",
16
+ "import": "./dist/lazy.js"
17
+ },
14
18
  "./codec": {
15
19
  "types": "./dist/codec/index.d.ts",
16
20
  "import": "./dist/codec/index.js"
@@ -19,7 +23,8 @@
19
23
  "./package.json": "./package.json"
20
24
  },
21
25
  "sideEffects": [
22
- "*.css"
26
+ "*.css",
27
+ "./dist/katex-styles-*.js"
23
28
  ],
24
29
  "files": [
25
30
  "dist",