@stream-mdx/react 0.4.0 → 1.0.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +385 -4
  2. package/README.md +141 -16
  3. package/dist/blocks-renderer-DAOBFBfi.d.ts +29 -0
  4. package/dist/blocks-renderer-DQEL1kJW.d.cts +29 -0
  5. package/dist/components/bottom-stick-scroll-area.cjs +268 -0
  6. package/dist/components/bottom-stick-scroll-area.d.cts +36 -0
  7. package/dist/components/bottom-stick-scroll-area.d.ts +36 -0
  8. package/dist/components/bottom-stick-scroll-area.mjs +249 -0
  9. package/dist/components/diff-renderer.cjs +86 -0
  10. package/dist/components/diff-renderer.d.cts +11 -0
  11. package/dist/components/diff-renderer.d.ts +11 -0
  12. package/dist/components/diff-renderer.mjs +66 -0
  13. package/dist/components/index.cjs +2879 -1295
  14. package/dist/components/index.d.cts +9 -2
  15. package/dist/components/index.d.ts +9 -2
  16. package/dist/components/index.mjs +2842 -1277
  17. package/dist/components/katex-math.cjs +220 -0
  18. package/dist/components/katex-math.d.cts +10 -0
  19. package/dist/components/katex-math.d.ts +10 -0
  20. package/dist/components/katex-math.mjs +188 -0
  21. package/dist/contexts/math-tracker.cjs +240 -521
  22. package/dist/contexts/math-tracker.mjs +235 -513
  23. package/dist/index-Cmne1yUK.d.cts +723 -0
  24. package/dist/index-D7dyyu3q.d.ts +723 -0
  25. package/dist/index.cjs +13180 -5640
  26. package/dist/index.d.cts +72 -40
  27. package/dist/index.d.ts +72 -40
  28. package/dist/index.mjs +12587 -5038
  29. package/dist/math/display-wrapper.cjs +7 -15
  30. package/dist/math/display-wrapper.d.cts +2 -2
  31. package/dist/math/display-wrapper.d.ts +2 -2
  32. package/dist/math/display-wrapper.mjs +2 -6
  33. package/dist/node-views-Bpc6Gkgl.d.cts +13 -0
  34. package/dist/node-views-DpnYdaAS.d.ts +13 -0
  35. package/dist/renderer/hooks.cjs +35 -20
  36. package/dist/renderer/hooks.d.cts +22 -1
  37. package/dist/renderer/hooks.d.ts +22 -1
  38. package/dist/renderer/hooks.mjs +27 -12
  39. package/dist/renderer/patch-batching.cjs +7 -8
  40. package/dist/renderer/patch-batching.d.cts +1 -1
  41. package/dist/renderer/patch-batching.d.ts +1 -1
  42. package/dist/renderer/patch-batching.mjs +2 -1
  43. package/dist/renderer/patch-coalescing.cjs +5 -8
  44. package/dist/renderer/patch-commit-scheduler.cjs +160 -326
  45. package/dist/renderer/patch-commit-scheduler.d.cts +28 -4
  46. package/dist/renderer/patch-commit-scheduler.d.ts +28 -4
  47. package/dist/renderer/patch-commit-scheduler.mjs +157 -318
  48. package/dist/renderer/store.cjs +3847 -1099
  49. package/dist/renderer/store.d.cts +111 -3
  50. package/dist/renderer/store.d.ts +111 -3
  51. package/dist/renderer/store.mjs +3847 -1085
  52. package/dist/renderer/virtualized-code.cjs +415 -71
  53. package/dist/renderer/virtualized-code.d.cts +24 -23
  54. package/dist/renderer/virtualized-code.d.ts +24 -23
  55. package/dist/renderer/virtualized-code.mjs +409 -62
  56. package/dist/renderer.cjs +10939 -3974
  57. package/dist/renderer.d.cts +100 -29
  58. package/dist/renderer.d.ts +100 -29
  59. package/dist/renderer.mjs +10711 -3697
  60. package/dist/server-regions-CPLHGli0.d.cts +32 -0
  61. package/dist/server-regions-mUhyoKi7.d.ts +32 -0
  62. package/dist/server.cjs +10286 -3365
  63. package/dist/server.d.cts +17 -247
  64. package/dist/server.d.ts +17 -247
  65. package/dist/server.mjs +10565 -3619
  66. package/dist/{streaming-markdown-DOc2uLiP.d.ts → streaming-markdown-yELbJxyH.d.ts} +51 -55
  67. package/dist/{streaming-markdown-D-JcByd9.d.cts → streaming-markdown-zVwFuaJG.d.cts} +51 -55
  68. package/dist/streaming-markdown.cjs +11828 -4879
  69. package/dist/streaming-markdown.d.cts +9 -2
  70. package/dist/streaming-markdown.d.ts +9 -2
  71. package/dist/streaming-markdown.mjs +11820 -4821
  72. package/dist/trusted-mdx/index.cjs +833 -0
  73. package/dist/trusted-mdx/index.d.cts +11 -0
  74. package/dist/trusted-mdx/index.d.ts +11 -0
  75. package/dist/trusted-mdx/index.mjs +807 -0
  76. package/dist/trusted-mdx/native-children-slot.cjs +45 -0
  77. package/dist/trusted-mdx/native-children-slot.d.cts +11 -0
  78. package/dist/trusted-mdx/native-children-slot.d.ts +11 -0
  79. package/dist/trusted-mdx/native-children-slot.mjs +24 -0
  80. package/dist/trusted-mdx/server.cjs +752 -0
  81. package/dist/trusted-mdx/server.d.cts +24 -0
  82. package/dist/trusted-mdx/server.d.ts +24 -0
  83. package/dist/trusted-mdx/server.mjs +724 -0
  84. package/dist/trusted-mdx-contract-ElKpkDI5.d.cts +113 -0
  85. package/dist/trusted-mdx-contract-ElKpkDI5.d.ts +113 -0
  86. package/dist/utils/inline-html.cjs +246 -147
  87. package/dist/utils/inline-html.d.cts +39 -6
  88. package/dist/utils/inline-html.d.ts +39 -6
  89. package/dist/utils/inline-html.mjs +237 -134
  90. package/package.json +52 -18
  91. package/shadcn/README.md +28 -0
  92. package/shadcn/bottom-stick-scroll-area.tsx +358 -0
  93. package/dist/index-D2MYusAM.d.cts +0 -248
  94. package/dist/index-D2MYusAM.d.ts +0 -248
  95. package/dist/mdx-client.cjs +0 -408
  96. package/dist/mdx-client.d.cts +0 -113
  97. package/dist/mdx-client.d.ts +0 -113
  98. package/dist/mdx-client.mjs +0 -369
  99. package/dist/mdx-coordinator.cjs +0 -563
  100. package/dist/mdx-coordinator.d.cts +0 -21
  101. package/dist/mdx-coordinator.d.ts +0 -21
  102. package/dist/mdx-coordinator.mjs +0 -529
  103. package/dist/renderer/node-views.cjs +0 -1642
  104. package/dist/renderer/node-views.d.cts +0 -12
  105. package/dist/renderer/node-views.d.ts +0 -12
  106. package/dist/renderer/node-views.mjs +0 -1616
@@ -1,248 +0,0 @@
1
- import { InlineNode, TokenLineV1, CompiledMdxModule, InlineHtmlDescriptor, Block, LazyTokenizationPriority, FormatAnticipationConfig, CodeHighlightingMode, CodeHighlightOutputMode, MixedContentSegment } from '@stream-mdx/core';
2
- import React from 'react';
3
-
4
- type GenericComponent = React.ComponentType<any>;
5
- interface TableElements {
6
- Table: GenericComponent;
7
- Thead: GenericComponent;
8
- Tbody: GenericComponent;
9
- Tr: GenericComponent;
10
- Th: GenericComponent;
11
- Td: GenericComponent;
12
- }
13
- type HtmlElements = Record<string, GenericComponent>;
14
- type InlineHtmlRenderer = (descriptor: InlineHtmlDescriptor, context: {
15
- key?: React.Key;
16
- defaultRender: () => React.ReactElement | null;
17
- }) => React.ReactElement | null;
18
- type InlineHtmlRendererMap = Record<string, InlineHtmlRenderer>;
19
- interface BlockComponents {
20
- paragraph: React.FC<{
21
- inlines: InlineNode[];
22
- raw?: string;
23
- meta?: Record<string, unknown>;
24
- children?: React.ReactNode;
25
- }>;
26
- heading: React.FC<{
27
- level: 1 | 2 | 3 | 4 | 5 | 6;
28
- inlines: InlineNode[];
29
- text?: string;
30
- meta?: Record<string, unknown>;
31
- }>;
32
- code: React.FC<{
33
- html: string;
34
- meta?: Record<string, unknown>;
35
- lines?: ReadonlyArray<{
36
- id: string;
37
- index: number;
38
- text: string;
39
- html?: string | null;
40
- tokens?: TokenLineV1 | null;
41
- }>;
42
- lang?: string;
43
- preAttrs?: Record<string, string>;
44
- codeAttrs?: Record<string, string>;
45
- }>;
46
- blockquote: React.FC<{
47
- inlines: InlineNode[];
48
- renderedContent?: React.ReactNode;
49
- }>;
50
- list: React.FC<{
51
- ordered: boolean;
52
- items: InlineNode[][];
53
- }>;
54
- html: React.FC<{
55
- __trustedHtml: TrustedHTML | string;
56
- elements?: Record<string, GenericComponent>;
57
- }>;
58
- mdx: React.FC<{
59
- compiledRef?: {
60
- id: string;
61
- };
62
- compiledModule?: CompiledMdxModule | null;
63
- status?: "pending" | "compiled" | "error";
64
- errorMessage?: string;
65
- raw?: string;
66
- }>;
67
- hr: React.FC<React.HTMLAttributes<HTMLHRElement>>;
68
- table: React.FC<{
69
- header?: InlineNode[][];
70
- rows: InlineNode[][][];
71
- align?: Array<"left" | "center" | "right" | null>;
72
- elements?: Partial<TableElements>;
73
- }>;
74
- [k: string]: GenericComponent;
75
- }
76
- type InlineComponents = Record<string, GenericComponent> & {
77
- text: React.FC<{
78
- text: string;
79
- }>;
80
- strong: React.FC<{
81
- children: React.ReactNode;
82
- }>;
83
- em: React.FC<{
84
- children: React.ReactNode;
85
- }>;
86
- strike?: React.FC<{
87
- children: React.ReactNode;
88
- }>;
89
- code: React.FC<{
90
- text: string;
91
- }>;
92
- link: React.FC<{
93
- href?: string;
94
- title?: string;
95
- children: React.ReactNode;
96
- }>;
97
- image: React.FC<{
98
- src: string;
99
- alt?: string;
100
- title?: string;
101
- }>;
102
- br: React.FC<Record<string, never>>;
103
- };
104
- interface RendererConfig {
105
- themes?: {
106
- light: string;
107
- dark: string;
108
- };
109
- highlight?: {
110
- browserEngine?: "js" | "wasm";
111
- serverEngine?: "wasm";
112
- langs?: string[];
113
- };
114
- sanitization?: {
115
- schemaId?: string;
116
- };
117
- mdx?: {
118
- enabled?: boolean;
119
- compileEndpoint?: string;
120
- compileStrategy?: "server" | "worker";
121
- components?: Record<string, GenericComponent>;
122
- };
123
- plugins?: {
124
- footnotes?: boolean;
125
- html?: boolean;
126
- mdx?: boolean;
127
- tables?: boolean;
128
- callouts?: boolean;
129
- math?: boolean;
130
- formatAnticipation?: FormatAnticipationConfig;
131
- codeHighlighting?: CodeHighlightingMode;
132
- outputMode?: CodeHighlightOutputMode;
133
- liveCodeHighlighting?: boolean;
134
- liveTokenization?: boolean;
135
- emitHighlightTokens?: boolean;
136
- emitDiffBlocks?: boolean;
137
- };
138
- performance?: {
139
- frameBudgetMs?: number;
140
- flushTimeoutMs?: number;
141
- maxBatchesPerFlush?: number;
142
- maxLowPriorityBatchesPerFlush?: number;
143
- lowPriorityFrameBudgetMs?: number;
144
- urgentQueueThreshold?: number;
145
- batch?: "rAF" | "microtask" | "timeout";
146
- historyLimit?: number;
147
- };
148
- }
149
- interface RendererStore {
150
- reset(blocks: Block[]): void;
151
- getBlocks(): ReadonlyArray<Block>;
152
- getVersion(): number;
153
- subscribe(listener: () => void): () => void;
154
- }
155
- type CodeHighlightRangeRequest = {
156
- blockId: string;
157
- startLine: number;
158
- endLine: number;
159
- priority?: LazyTokenizationPriority;
160
- };
161
- interface Renderer {
162
- attachWorker(worker: Worker, options?: {
163
- skipInit?: boolean;
164
- }): void;
165
- append(text: string): void;
166
- renderStatic(text: string): Promise<Block[]>;
167
- onUpdate(cb: (blocks: ReadonlyArray<Block>) => void): () => void;
168
- setBlockComponents(map: Partial<BlockComponents>): void;
169
- setInlineComponents(map: Partial<InlineComponents>): void;
170
- setMdxComponents(map: Record<string, GenericComponent>): void;
171
- getComponentRegistry(): ComponentRegistry;
172
- getStore(): RendererStore;
173
- requestCodeHighlightRange(request: CodeHighlightRangeRequest): void;
174
- }
175
-
176
- type LinkSafetyModalProps = {
177
- url: string;
178
- isOpen: boolean;
179
- isChecking?: boolean;
180
- onClose: () => void;
181
- onConfirm: () => void;
182
- onCopy: () => void;
183
- };
184
- declare const DefaultLinkSafetyModal: React.FC<LinkSafetyModalProps>;
185
-
186
- /**
187
- * Render inline nodes to React elements
188
- */
189
- declare function renderInlineNodes(nodes: InlineNode[], components: InlineComponents): React.ReactNode;
190
- /**
191
- * Default inline components
192
- */
193
- declare const defaultInlineComponents: InlineComponents;
194
- /**
195
- * Default block components
196
- */
197
- declare const defaultBlockComponents: BlockComponents;
198
- /**
199
- * Component registry that allows customization
200
- */
201
- declare class ComponentRegistry {
202
- private blockComponents;
203
- private inlineComponents;
204
- private htmlElements;
205
- private tableElements;
206
- private blockComponentMapCache;
207
- private inlineComponentMapCache;
208
- constructor(blockComponents?: Partial<BlockComponents>, inlineComponents?: Partial<InlineComponents>);
209
- /**
210
- * Update block components
211
- */
212
- setBlockComponents(components: Partial<BlockComponents>): void;
213
- /**
214
- * Update inline components
215
- */
216
- setInlineComponents(components: Partial<InlineComponents>): void;
217
- /** Update HTML element mapping for html blocks */
218
- setHtmlElements(map: Partial<HtmlElements>): void;
219
- /** Update table element mapping for table blocks */
220
- setTableElements(map: Partial<TableElements>): void;
221
- /**
222
- * Get block component
223
- */
224
- getBlockComponent(type: string): React.ComponentType<Record<string, unknown>>;
225
- /**
226
- * Get inline components
227
- */
228
- getInlineComponents(): InlineComponents;
229
- getBlockComponentMap(): BlockComponents;
230
- getInlineComponentMap(): InlineComponents;
231
- getTableElements(): TableElements;
232
- /**
233
- * Render a block
234
- */
235
- renderBlock(block: Block): React.ReactElement;
236
- /**
237
- * Get props for a block based on its type
238
- */
239
- private getBlockProps;
240
- /**
241
- * Extract heading level from raw markdown
242
- */
243
- private extractHeadingLevel;
244
- }
245
- declare function mapHtmlToReact(html: string, elements: HtmlElements): React.ReactNode;
246
- declare function renderParagraphMixedSegments(segments: MixedContentSegment[], inlineComponents: InlineComponents, inlineHtmlRenderers: InlineHtmlRendererMap): React.ReactNode[];
247
-
248
- export { type BlockComponents as B, ComponentRegistry as C, DefaultLinkSafetyModal as D, type HtmlElements as H, type InlineHtmlRendererMap as I, type LinkSafetyModalProps as L, type Renderer as R, type TableElements as T, type InlineComponents as a, type InlineHtmlRenderer as b, type RendererConfig as c, defaultInlineComponents as d, defaultBlockComponents as e, renderParagraphMixedSegments as f, type CodeHighlightRangeRequest as g, mapHtmlToReact as m, renderInlineNodes as r };
@@ -1,408 +0,0 @@
1
- "use client";
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/mdx-client.ts
32
- var mdx_client_exports = {};
33
- __export(mdx_client_exports, {
34
- MDXClient: () => MDXClient,
35
- MDXComponentFactory: () => MDXComponentFactory,
36
- getMDXClient: () => getMDXClient,
37
- getMDXComponentFactory: () => getMDXComponentFactory,
38
- registerInlineMdxModule: () => registerInlineMdxModule,
39
- registerMDXComponents: () => registerMDXComponents
40
- });
41
- module.exports = __toCommonJS(mdx_client_exports);
42
- var import_react = __toESM(require("react"), 1);
43
- var ReactJsxRuntime = __toESM(require("react/jsx-runtime"), 1);
44
- var withClassName = (tag, className) => {
45
- return (props) => import_react.default.createElement(tag, { className, ...props });
46
- };
47
- function assignMdxChildKey(child, index) {
48
- if (child == null) return child;
49
- if (Array.isArray(child)) {
50
- return child.map((entry, subIndex) => assignMdxChildKey(entry, `${index}-${subIndex}`));
51
- }
52
- if (import_react.default.isValidElement(child)) {
53
- if (child.key !== null && child.key !== void 0) {
54
- return child;
55
- }
56
- return import_react.default.cloneElement(child, { key: index });
57
- }
58
- return child;
59
- }
60
- var MDXClient = class {
61
- constructor(compileEndpoint = "/api/mdx-compile-v2") {
62
- this.cache = /* @__PURE__ */ new Map();
63
- this.inlineModules = /* @__PURE__ */ new Map();
64
- this.compiledCache = /* @__PURE__ */ new Map();
65
- this.compiledInflight = /* @__PURE__ */ new Map();
66
- this.compileEndpoint = compileEndpoint;
67
- }
68
- /**
69
- * Compile MDX block on server
70
- */
71
- async compile(block) {
72
- if (block.type !== "mdx") {
73
- throw new Error("Block is not MDX type");
74
- }
75
- const cacheKey = block.id;
76
- const cachedPromise = this.cache.get(cacheKey);
77
- if (cachedPromise) {
78
- return cachedPromise;
79
- }
80
- const compilationPromise = this.doCompile(block);
81
- this.cache.set(cacheKey, compilationPromise);
82
- try {
83
- const result = await compilationPromise;
84
- return result;
85
- } catch (error) {
86
- this.cache.delete(cacheKey);
87
- throw error;
88
- }
89
- }
90
- async getCompiledInternal(ref) {
91
- const inline = this.inlineModules.get(ref.id);
92
- if (inline) {
93
- return this.cloneCompiled(inline);
94
- }
95
- const cached = this.compiledCache.get(ref.id);
96
- if (cached) {
97
- return this.cloneCompiled(cached);
98
- }
99
- const inflight = this.compiledInflight.get(ref.id);
100
- if (inflight) {
101
- const resolved = await inflight;
102
- return this.cloneCompiled(resolved);
103
- }
104
- const fetchPromise = this.fetchCompiled(ref);
105
- this.compiledInflight.set(ref.id, fetchPromise);
106
- try {
107
- const data = await fetchPromise;
108
- this.compiledCache.set(ref.id, data);
109
- return this.cloneCompiled(data);
110
- } finally {
111
- this.compiledInflight.delete(ref.id);
112
- }
113
- }
114
- async getCompiled(ref, options) {
115
- if (options?.signal) {
116
- const inline = this.inlineModules.get(ref.id);
117
- if (inline) {
118
- return this.cloneCompiled(inline);
119
- }
120
- const cached = this.compiledCache.get(ref.id);
121
- if (cached) {
122
- return this.cloneCompiled(cached);
123
- }
124
- const data = await this.fetchCompiled(ref, options);
125
- this.compiledCache.set(ref.id, data);
126
- return this.cloneCompiled(data);
127
- }
128
- return this.getCompiledInternal(ref);
129
- }
130
- /**
131
- * Clear compilation cache
132
- */
133
- clearCache() {
134
- this.cache.clear();
135
- this.compiledCache.clear();
136
- this.compiledInflight.clear();
137
- }
138
- registerInlineModule(compiled) {
139
- this.inlineModules.set(compiled.id, {
140
- ...compiled,
141
- dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
142
- });
143
- }
144
- clearInlineModules() {
145
- this.inlineModules.clear();
146
- }
147
- /**
148
- * Actual compilation implementation
149
- */
150
- async doCompile(block) {
151
- const response = await fetch(this.compileEndpoint, {
152
- method: "POST",
153
- headers: {
154
- "Content-Type": "application/json"
155
- },
156
- body: JSON.stringify({
157
- content: block.payload.raw,
158
- blockId: block.id
159
- })
160
- });
161
- if (!response.ok) {
162
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
163
- throw new Error(`MDX compilation failed: ${error.error || response.statusText}`);
164
- }
165
- const data = await response.json();
166
- return {
167
- id: data.id,
168
- code: data.code,
169
- dependencies: data.dependencies || [],
170
- cached: data.cached || false
171
- };
172
- }
173
- async fetchCompiled(ref, options) {
174
- const response = await fetch(`${this.compileEndpoint}?id=${ref.id}`, {
175
- signal: options?.signal
176
- });
177
- if (!response.ok) {
178
- throw new Error(`Failed to get compiled MDX: ${response.statusText}`);
179
- }
180
- const data = await response.json();
181
- return {
182
- id: data.id,
183
- code: data.code,
184
- dependencies: data.dependencies || [],
185
- timestamp: data.timestamp
186
- };
187
- }
188
- cloneCompiled(compiled) {
189
- return {
190
- ...compiled,
191
- dependencies: Array.isArray(compiled.dependencies) ? [...compiled.dependencies] : []
192
- };
193
- }
194
- };
195
- var MDXComponentFactory = class {
196
- constructor(mdxClient) {
197
- this.components = /* @__PURE__ */ new Map();
198
- this.customComponents = /* @__PURE__ */ new Map();
199
- this.mdxClient = mdxClient;
200
- this.baseComponents = this.createBaseComponents();
201
- }
202
- registerInlineModule(module2) {
203
- this.mdxClient.registerInlineModule(module2);
204
- this.components.delete(module2.id);
205
- }
206
- /**
207
- * Create React component from compiled MDX
208
- */
209
- async createComponent(ref) {
210
- const cached = this.components.get(ref.id);
211
- if (cached) {
212
- return cached;
213
- }
214
- const compiled = await this.mdxClient.getCompiled(ref);
215
- const component = this.evaluateCompiledMDX(compiled);
216
- this.components.set(ref.id, component);
217
- return component;
218
- }
219
- /**
220
- * Safely evaluate compiled MDX code
221
- */
222
- evaluateCompiledMDX(compiled) {
223
- try {
224
- const context = this.createEvaluationContext();
225
- const argNames = Object.keys(context);
226
- const argValues = Object.values(context);
227
- const moduleExports = new Function(...argNames, compiled.code)(...argValues);
228
- const MDXComponent = this.resolveEvaluatedModule(moduleExports);
229
- return (props) => {
230
- const registryComponents = this.getComponents();
231
- const incomingComponents = props?.components;
232
- const mergedComponents = incomingComponents ? { ...registryComponents, ...incomingComponents } : registryComponents;
233
- return import_react.default.createElement(MDXComponent, {
234
- ...props,
235
- components: mergedComponents
236
- });
237
- };
238
- } catch (error) {
239
- console.error("Failed to evaluate MDX:", error);
240
- return () => import_react.default.createElement(
241
- "div",
242
- {
243
- className: "mdx-error"
244
- },
245
- `MDX Error: ${error instanceof Error ? error.message : "Unknown error"}`
246
- );
247
- }
248
- }
249
- /**
250
- * Create safe evaluation context for MDX
251
- */
252
- createEvaluationContext() {
253
- const runtime = ReactJsxRuntime;
254
- const createElementWithChildren = (type, props, key) => {
255
- const baseProps = props ?? {};
256
- const finalProps = key === void 0 || key === null ? baseProps : { ...baseProps, key };
257
- if (Array.isArray(finalProps.children)) {
258
- finalProps.children = finalProps.children.map((child, index) => assignMdxChildKey(child, index));
259
- }
260
- return import_react.default.createElement(type, finalProps);
261
- };
262
- const runtimeJsx = typeof runtime.jsx === "function" ? runtime.jsx.bind(runtime) : createElementWithChildren;
263
- const runtimeJsxs = typeof runtime.jsxs === "function" ? runtime.jsxs.bind(runtime) : createElementWithChildren;
264
- const runtimeJsxDEV = typeof runtime.jsxDEV === "function" ? runtime.jsxDEV.bind(runtime) : (type, props, key, ..._rest) => createElementWithChildren(type, props, key);
265
- const jsxRuntime = {
266
- jsx: runtimeJsx,
267
- jsxs: runtimeJsxs,
268
- jsxDEV: runtimeJsxDEV,
269
- Fragment: runtime.Fragment ?? import_react.default.Fragment
270
- };
271
- return {
272
- __mdx_runtime: jsxRuntime,
273
- React: import_react.default,
274
- Fragment: import_react.default.Fragment,
275
- useState: import_react.default.useState,
276
- useEffect: import_react.default.useEffect,
277
- useMemo: import_react.default.useMemo,
278
- useCallback: import_react.default.useCallback,
279
- useRef: import_react.default.useRef,
280
- useContext: import_react.default.useContext,
281
- useReducer: import_react.default.useReducer,
282
- useLayoutEffect: import_react.default.useLayoutEffect,
283
- console: {
284
- log: console.log,
285
- warn: console.warn,
286
- error: console.error
287
- }
288
- };
289
- }
290
- resolveEvaluatedModule(output) {
291
- if (!output) {
292
- throw new Error("Compiled MDX module returned no exports");
293
- }
294
- if (typeof output === "function") {
295
- return output;
296
- }
297
- if (typeof output.default === "function") {
298
- return output.default;
299
- }
300
- if (typeof output.MDXContent === "function") {
301
- return output.MDXContent;
302
- }
303
- throw new Error("Compiled MDX module did not export a component");
304
- }
305
- getComponents() {
306
- if (this.customComponents.size === 0) {
307
- return { ...this.baseComponents };
308
- }
309
- const merged = { ...this.baseComponents };
310
- for (const [key, component] of this.customComponents) {
311
- merged[key] = component;
312
- }
313
- return merged;
314
- }
315
- /**
316
- * Register or replace custom MDX components
317
- */
318
- registerComponents(components, options) {
319
- if (options?.replace) {
320
- this.customComponents.clear();
321
- }
322
- for (const [key, component] of Object.entries(components)) {
323
- if (!component) continue;
324
- this.customComponents.set(key, component);
325
- }
326
- }
327
- /**
328
- * Get base MDX components
329
- */
330
- createBaseComponents() {
331
- return {
332
- // Standard HTML elements
333
- h1: withClassName("h1", "mdx-h1"),
334
- h2: withClassName("h2", "mdx-h2"),
335
- h3: withClassName("h3", "mdx-h3"),
336
- h4: withClassName("h4", "mdx-h4"),
337
- h5: withClassName("h5", "mdx-h5"),
338
- h6: withClassName("h6", "mdx-h6"),
339
- p: withClassName("p", "mdx-p"),
340
- strong: withClassName("strong", "mdx-strong"),
341
- em: withClassName("em", "mdx-em"),
342
- code: withClassName("code", "mdx-code"),
343
- pre: withClassName("pre", "mdx-pre"),
344
- ul: withClassName("ul", "mdx-ul"),
345
- ol: withClassName("ol", "mdx-ol"),
346
- li: withClassName("li", "mdx-li"),
347
- blockquote: withClassName("blockquote", "mdx-blockquote"),
348
- a: (props) => import_react.default.createElement("a", {
349
- className: "mdx-link",
350
- target: props.href?.startsWith("http") ? "_blank" : void 0,
351
- rel: props.href?.startsWith("http") ? "noopener noreferrer" : void 0,
352
- ...props
353
- }),
354
- img: (props) => import_react.default.createElement("img", { className: "mdx-img", ...props }),
355
- table: withClassName("table", "mdx-table"),
356
- thead: withClassName("thead", "mdx-thead"),
357
- tbody: withClassName("tbody", "mdx-tbody"),
358
- tr: withClassName("tr", "mdx-tr"),
359
- th: withClassName("th", "mdx-th"),
360
- td: withClassName("td", "mdx-td")
361
- };
362
- }
363
- /**
364
- * Clear component cache
365
- */
366
- clearCache() {
367
- this.components.clear();
368
- }
369
- clearCustomComponents() {
370
- this.customComponents.clear();
371
- }
372
- };
373
- var globalMDXClient = null;
374
- var globalComponentFactory = null;
375
- function getMDXClient(compileEndpoint) {
376
- if (!globalMDXClient) {
377
- globalMDXClient = new MDXClient(compileEndpoint);
378
- }
379
- return globalMDXClient;
380
- }
381
- function getMDXComponentFactory(compileEndpoint) {
382
- if (!globalComponentFactory) {
383
- const client = getMDXClient(compileEndpoint);
384
- globalComponentFactory = new MDXComponentFactory(client);
385
- }
386
- return globalComponentFactory;
387
- }
388
- function registerMDXComponents(components, options) {
389
- const factory = getMDXComponentFactory();
390
- factory.registerComponents(components, options);
391
- }
392
- function registerInlineMdxModule(compiled) {
393
- const factory = getMDXComponentFactory();
394
- factory.registerInlineModule({
395
- id: compiled.id,
396
- code: compiled.code,
397
- dependencies: compiled.dependencies ?? []
398
- });
399
- }
400
- // Annotate the CommonJS export names for ESM import in node:
401
- 0 && (module.exports = {
402
- MDXClient,
403
- MDXComponentFactory,
404
- getMDXClient,
405
- getMDXComponentFactory,
406
- registerInlineMdxModule,
407
- registerMDXComponents
408
- });