@nuucognition/ncm-ui 0.1.0-dev.1

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/dist/blocks/admonition/index.d.ts +13 -0
  4. package/dist/blocks/admonition/index.js +1713 -0
  5. package/dist/blocks/aside/index.d.ts +13 -0
  6. package/dist/blocks/aside/index.js +1713 -0
  7. package/dist/blocks/attribution/index.d.ts +13 -0
  8. package/dist/blocks/attribution/index.js +32 -0
  9. package/dist/blocks/blockquote/index.d.ts +15 -0
  10. package/dist/blocks/blockquote/index.js +609 -0
  11. package/dist/blocks/chart/index.d.ts +14 -0
  12. package/dist/blocks/chart/index.js +29 -0
  13. package/dist/blocks/code/index.d.ts +15 -0
  14. package/dist/blocks/code/index.js +163 -0
  15. package/dist/blocks/container/index.d.ts +17 -0
  16. package/dist/blocks/container/index.js +633 -0
  17. package/dist/blocks/custom-code/index.d.ts +15 -0
  18. package/dist/blocks/custom-code/index.js +31 -0
  19. package/dist/blocks/dataview/index.d.ts +14 -0
  20. package/dist/blocks/dataview/index.js +29 -0
  21. package/dist/blocks/definition/index.d.ts +13 -0
  22. package/dist/blocks/definition/index.js +1713 -0
  23. package/dist/blocks/embed/index.d.ts +12 -0
  24. package/dist/blocks/embed/index.js +46 -0
  25. package/dist/blocks/embedding/index.d.ts +13 -0
  26. package/dist/blocks/embedding/index.js +763 -0
  27. package/dist/blocks/figure/index.d.ts +13 -0
  28. package/dist/blocks/figure/index.js +656 -0
  29. package/dist/blocks/footnote/index.d.ts +13 -0
  30. package/dist/blocks/footnote/index.js +1713 -0
  31. package/dist/blocks/frontmatter/index.d.ts +16 -0
  32. package/dist/blocks/frontmatter/index.js +38 -0
  33. package/dist/blocks/header/index.d.ts +9 -0
  34. package/dist/blocks/header/index.js +610 -0
  35. package/dist/blocks/horizontal-rule/index.d.ts +9 -0
  36. package/dist/blocks/horizontal-rule/index.js +19 -0
  37. package/dist/blocks/html/index.d.ts +31 -0
  38. package/dist/blocks/html/index.js +52 -0
  39. package/dist/blocks/index.d.ts +32 -0
  40. package/dist/blocks/index.js +1736 -0
  41. package/dist/blocks/latex/index.d.ts +9 -0
  42. package/dist/blocks/latex/index.js +107 -0
  43. package/dist/blocks/link/index.d.ts +14 -0
  44. package/dist/blocks/link/index.js +27 -0
  45. package/dist/blocks/list/index.d.ts +9 -0
  46. package/dist/blocks/list/index.js +675 -0
  47. package/dist/blocks/math/index.d.ts +13 -0
  48. package/dist/blocks/math/index.js +88 -0
  49. package/dist/blocks/mermaid/index.d.ts +14 -0
  50. package/dist/blocks/mermaid/index.js +29 -0
  51. package/dist/blocks/page-breaker/index.d.ts +16 -0
  52. package/dist/blocks/page-breaker/index.js +21 -0
  53. package/dist/blocks/paragraph/index.d.ts +9 -0
  54. package/dist/blocks/paragraph/index.js +608 -0
  55. package/dist/blocks/spoiler/index.d.ts +13 -0
  56. package/dist/blocks/spoiler/index.js +1713 -0
  57. package/dist/blocks/table/index.d.ts +9 -0
  58. package/dist/blocks/table/index.js +619 -0
  59. package/dist/blocks/task-list/index.d.ts +13 -0
  60. package/dist/blocks/task-list/index.js +670 -0
  61. package/dist/components/index.d.ts +599 -0
  62. package/dist/components/index.js +1840 -0
  63. package/dist/components/ncm-block.d.ts +28 -0
  64. package/dist/components/ncm-block.js +1712 -0
  65. package/dist/components/ncm-document.d.ts +48 -0
  66. package/dist/components/ncm-document.js +1839 -0
  67. package/dist/context/index.d.ts +7 -0
  68. package/dist/context/index.js +284 -0
  69. package/dist/hooks/index.d.ts +7 -0
  70. package/dist/hooks/index.js +1731 -0
  71. package/dist/hooks/use-block-renderer.d.ts +28 -0
  72. package/dist/hooks/use-block-renderer.js +1731 -0
  73. package/dist/hooks/use-ncm-config.d.ts +6 -0
  74. package/dist/hooks/use-ncm-config.js +11 -0
  75. package/dist/index.d.ts +43 -0
  76. package/dist/index.js +1887 -0
  77. package/dist/inline/index.d.ts +108 -0
  78. package/dist/inline/index.js +598 -0
  79. package/dist/inline-DwUYUmk4.d.ts +75 -0
  80. package/dist/lib/defaults.d.ts +24 -0
  81. package/dist/lib/defaults.js +1713 -0
  82. package/dist/lib/index.d.ts +2 -0
  83. package/dist/lib/index.js +10 -0
  84. package/dist/lib/katex.d.ts +3 -0
  85. package/dist/lib/katex.js +45 -0
  86. package/dist/lib/utils.d.ts +8 -0
  87. package/dist/lib/utils.js +10 -0
  88. package/dist/references-Bs5wJybr.d.ts +63 -0
  89. package/dist/renderers-C5f41FCy.d.ts +99 -0
  90. package/dist/styles/fonts/OpenDyslexic3-Bold.woff +0 -0
  91. package/dist/styles/fonts/OpenDyslexic3-Bold.woff2 +0 -0
  92. package/dist/styles/fonts/OpenDyslexic3-Regular.woff +0 -0
  93. package/dist/styles/fonts/OpenDyslexic3-Regular.woff2 +0 -0
  94. package/dist/styles/nuu.css +364 -0
  95. package/dist/styles/paper.css +332 -0
  96. package/dist/types/index.d.ts +4 -0
  97. package/dist/types/index.js +2 -0
  98. package/dist/use-ncm-config-D0doMYTH.d.ts +114 -0
  99. package/package.json +99 -0
@@ -0,0 +1,1713 @@
1
+ "use client";
2
+ import { createContext, createElement, useContext, useRef, Component, useState, useEffect, useMemo, useCallback, useId } from 'react';
3
+ import { clsx } from 'clsx';
4
+ import { twMerge } from 'tailwind-merge';
5
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
+ import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
7
+ import { serializeInlineContent, isTypedNestedList } from '@nuucognition/ncm';
8
+
9
+ // src/components/block-shell.tsx
10
+ function cn(...inputs) {
11
+ return twMerge(clsx(inputs));
12
+ }
13
+ function defaultTitle(type) {
14
+ return type.charAt(0).toUpperCase() + type.slice(1);
15
+ }
16
+ function AdmonitionBlock({ block, className }) {
17
+ const title = block.title ?? defaultTitle(block.admonitionType);
18
+ const classes = cn("rounded-lg border border-border bg-card p-4", className);
19
+ if (block.collapsible) {
20
+ return /* @__PURE__ */ jsxs(
21
+ BlockShell,
22
+ {
23
+ as: "details",
24
+ block,
25
+ "data-ncm-admonition": "",
26
+ "data-ncm-admonition-type": block.admonitionType,
27
+ open: !block.collapsed,
28
+ className: classes,
29
+ children: [
30
+ /* @__PURE__ */ jsx("summary", { className: "cursor-pointer font-medium", "data-ncm-admonition-title": "", children: title }),
31
+ /* @__PURE__ */ jsx(ChildBlocks, { blocks: block.children, className: "mt-2 space-y-2" })
32
+ ]
33
+ }
34
+ );
35
+ }
36
+ return /* @__PURE__ */ jsxs(
37
+ BlockShell,
38
+ {
39
+ block,
40
+ "data-ncm-admonition": "",
41
+ "data-ncm-admonition-type": block.admonitionType,
42
+ className: classes,
43
+ children: [
44
+ /* @__PURE__ */ jsx("p", { className: "mb-2 font-medium", "data-ncm-admonition-title": "", children: title }),
45
+ /* @__PURE__ */ jsx(ChildBlocks, { blocks: block.children, className: "space-y-2" })
46
+ ]
47
+ }
48
+ );
49
+ }
50
+ function AsideBlock({ block, className }) {
51
+ return /* @__PURE__ */ jsx(
52
+ BlockShell,
53
+ {
54
+ as: "aside",
55
+ block,
56
+ "data-ncm-aside": "",
57
+ className: cn("border-l-2 border-border pl-4 text-muted-foreground", className),
58
+ children: /* @__PURE__ */ jsx(ChildBlocks, { blocks: block.content, className: "space-y-2" })
59
+ }
60
+ );
61
+ }
62
+ function AttributionBlock({ block, className }) {
63
+ return /* @__PURE__ */ jsxs(
64
+ "p",
65
+ {
66
+ "data-ncm-block": block.id,
67
+ "data-ncm-stable": block.stableId,
68
+ "data-ncm-type": block.type,
69
+ "data-block-id": block.id,
70
+ "data-ncm-attribution": "",
71
+ className: cn("text-sm text-muted-foreground", className),
72
+ children: [
73
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2014 " }),
74
+ block.url ? /* @__PURE__ */ jsx("a", { href: block.url, className: "hover:underline", children: /* @__PURE__ */ jsx("cite", { children: block.source }) }) : /* @__PURE__ */ jsx("cite", { children: block.source }),
75
+ block.date ? /* @__PURE__ */ jsxs("span", { children: [
76
+ ", ",
77
+ block.date
78
+ ] }) : null
79
+ ]
80
+ }
81
+ );
82
+ }
83
+
84
+ // src/inline/parser.ts
85
+ function splitOnce(input, delimiter) {
86
+ const idx = input.indexOf(delimiter);
87
+ if (idx === -1) {
88
+ return [input, null];
89
+ }
90
+ return [input.slice(0, idx), input.slice(idx + delimiter.length)];
91
+ }
92
+ function parseWikiTarget(rawInside) {
93
+ const inside = rawInside.trim();
94
+ const [targetPlusAnchor, displayRaw] = splitOnce(inside, "|");
95
+ const [targetRaw, anchorRaw] = splitOnce(targetPlusAnchor, "#");
96
+ const target = targetRaw.trim();
97
+ const display = displayRaw !== null ? displayRaw.trim() || null : null;
98
+ const anchor = anchorRaw !== null ? anchorRaw.trim() || null : null;
99
+ return { target, display, anchor };
100
+ }
101
+ var INLINE_REF_KIND_RE = /^\s*(ref|footnote)\s*:\s*([\s\S]*)$/i;
102
+ function tryParseInlineRef(input) {
103
+ let depth = 1;
104
+ let i = 2;
105
+ for (; i < input.length; i++) {
106
+ const ch = input[i];
107
+ if (ch === "[") {
108
+ depth++;
109
+ } else if (ch === "]") {
110
+ depth--;
111
+ if (depth === 0) break;
112
+ }
113
+ }
114
+ if (depth !== 0) return null;
115
+ const inner = input.slice(2, i);
116
+ const length = i + 1;
117
+ const match = INLINE_REF_KIND_RE.exec(inner);
118
+ if (match && match[1]) {
119
+ const kind = match[1].toLowerCase() === "ref" ? "ref" : "footnote";
120
+ return { token: { type: "inline_ref", kind, content: (match[2] ?? "").trim() }, length };
121
+ }
122
+ return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
123
+ }
124
+ function parseInline(content) {
125
+ if (!content) return [];
126
+ const tokens = [];
127
+ let remaining = content;
128
+ while (remaining.length > 0) {
129
+ const codeMatch = remaining.match(/^`([^`]+)`/);
130
+ if (codeMatch && codeMatch[1] !== void 0) {
131
+ tokens.push({ type: "code", content: codeMatch[1] });
132
+ remaining = remaining.slice(codeMatch[0].length);
133
+ continue;
134
+ }
135
+ const latexMatch = remaining.match(/^\$(?!\s)([^$\n]+?)(?<!\s)\$/);
136
+ if (latexMatch && latexMatch[1] !== void 0) {
137
+ tokens.push({ type: "latex", content: latexMatch[1] });
138
+ remaining = remaining.slice(latexMatch[0].length);
139
+ continue;
140
+ }
141
+ if (remaining.startsWith("^[")) {
142
+ const inlineRef = tryParseInlineRef(remaining);
143
+ if (inlineRef) {
144
+ tokens.push(inlineRef.token);
145
+ remaining = remaining.slice(inlineRef.length);
146
+ continue;
147
+ }
148
+ }
149
+ const wikiEmbedMatch = remaining.match(/^!\[\[([^\]]+)\]\]/);
150
+ if (wikiEmbedMatch && wikiEmbedMatch[1] !== void 0) {
151
+ const parsed = parseWikiTarget(wikiEmbedMatch[1]);
152
+ tokens.push({
153
+ type: "wiki_embed",
154
+ target: parsed.target,
155
+ display: parsed.display,
156
+ anchor: parsed.anchor
157
+ });
158
+ remaining = remaining.slice(wikiEmbedMatch[0].length);
159
+ continue;
160
+ }
161
+ const wikiLinkMatch = remaining.match(/^\[\[([^\]]+)\]\]/);
162
+ if (wikiLinkMatch && wikiLinkMatch[1] !== void 0) {
163
+ const parsed = parseWikiTarget(wikiLinkMatch[1]);
164
+ tokens.push({
165
+ type: "wiki_link",
166
+ target: parsed.target,
167
+ display: parsed.display,
168
+ anchor: parsed.anchor
169
+ });
170
+ remaining = remaining.slice(wikiLinkMatch[0].length);
171
+ continue;
172
+ }
173
+ const imageMatch = remaining.match(/^!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
174
+ if (imageMatch && imageMatch[1] !== void 0 && imageMatch[2] !== void 0) {
175
+ tokens.push({
176
+ type: "image",
177
+ alt: imageMatch[1],
178
+ src: imageMatch[2],
179
+ title: imageMatch[3]
180
+ });
181
+ remaining = remaining.slice(imageMatch[0].length);
182
+ continue;
183
+ }
184
+ const linkMatch = remaining.match(/^\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
185
+ if (linkMatch && linkMatch[1] !== void 0 && linkMatch[2] !== void 0) {
186
+ tokens.push({
187
+ type: "link",
188
+ href: linkMatch[2],
189
+ title: linkMatch[3],
190
+ children: parseInline(linkMatch[1])
191
+ });
192
+ remaining = remaining.slice(linkMatch[0].length);
193
+ continue;
194
+ }
195
+ const boldMatch = remaining.match(/^\*\*(.+?)\*\*|^__(.+?)__/);
196
+ if (boldMatch) {
197
+ const innerContent = boldMatch[1] ?? boldMatch[2];
198
+ if (innerContent !== void 0) {
199
+ tokens.push({
200
+ type: "bold",
201
+ children: parseInline(innerContent)
202
+ });
203
+ remaining = remaining.slice(boldMatch[0].length);
204
+ continue;
205
+ }
206
+ }
207
+ const strikeMatch = remaining.match(/^~~(.+?)~~/);
208
+ if (strikeMatch && strikeMatch[1] !== void 0) {
209
+ tokens.push({
210
+ type: "strikethrough",
211
+ children: parseInline(strikeMatch[1])
212
+ });
213
+ remaining = remaining.slice(strikeMatch[0].length);
214
+ continue;
215
+ }
216
+ const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
217
+ if (italicMatch) {
218
+ const innerContent = italicMatch[1] ?? italicMatch[2];
219
+ if (innerContent !== void 0) {
220
+ tokens.push({
221
+ type: "italic",
222
+ children: parseInline(innerContent)
223
+ });
224
+ remaining = remaining.slice(italicMatch[0].length);
225
+ continue;
226
+ }
227
+ }
228
+ const nextSpecial = findNextSpecialChar(remaining);
229
+ if (nextSpecial > 0) {
230
+ tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
231
+ remaining = remaining.slice(nextSpecial);
232
+ } else {
233
+ tokens.push({ type: "text", content: remaining });
234
+ remaining = "";
235
+ }
236
+ }
237
+ return mergeAdjacentText(tokens);
238
+ }
239
+ function findNextSpecialChar(content) {
240
+ const specialChars = ["`", "$", "!", "[", "*", "_", "~", "^"];
241
+ let minIndex = -1;
242
+ for (const char of specialChars) {
243
+ const index = content.indexOf(char);
244
+ if (index > 0 && (minIndex === -1 || index < minIndex)) {
245
+ minIndex = index;
246
+ }
247
+ }
248
+ return minIndex;
249
+ }
250
+ function mergeAdjacentText(tokens) {
251
+ const result = [];
252
+ for (const token of tokens) {
253
+ const last = result[result.length - 1];
254
+ if (token.type === "text" && last?.type === "text") {
255
+ last.content += token.content;
256
+ } else {
257
+ result.push(token);
258
+ }
259
+ }
260
+ return result;
261
+ }
262
+ var NcmContext = createContext(null);
263
+ function useNcmConfig() {
264
+ return useContext(NcmContext) ?? {};
265
+ }
266
+ function clipBounds(el) {
267
+ for (let node = el.parentElement; node; node = node.parentElement) {
268
+ const s = getComputedStyle(node);
269
+ if (/(auto|scroll|hidden)/.test(s.overflowX) || /(auto|scroll|hidden)/.test(s.overflowY)) {
270
+ const r = node.getBoundingClientRect();
271
+ return { left: r.left, right: r.right, top: r.top, bottom: r.bottom };
272
+ }
273
+ }
274
+ return { left: 0, right: window.innerWidth, top: 0, bottom: window.innerHeight };
275
+ }
276
+ function ReferenceMarker({ kind, number, children }) {
277
+ const config = useNcmConfig();
278
+ const popoverEnabled = config.inline?.referencePopover !== false && children != null;
279
+ const popoverId = useId();
280
+ const isRef = kind === "ref";
281
+ const popoverRef = useRef(null);
282
+ const positionPopover = useCallback(() => {
283
+ const el = popoverRef.current;
284
+ if (!el) return;
285
+ el.style.transform = "";
286
+ el.style.top = "";
287
+ el.style.bottom = "";
288
+ const margin = 8;
289
+ const bounds = clipBounds(el);
290
+ const rect = el.getBoundingClientRect();
291
+ if (rect.bottom > bounds.bottom - margin && rect.height < rect.top - bounds.top) {
292
+ el.style.top = "auto";
293
+ el.style.bottom = "1.6em";
294
+ }
295
+ let dx = 0;
296
+ if (rect.right > bounds.right - margin) dx = bounds.right - margin - rect.right;
297
+ if (rect.left + dx < bounds.left + margin) dx = bounds.left + margin - rect.left;
298
+ if (dx) el.style.transform = `translateX(${Math.round(dx)}px)`;
299
+ }, []);
300
+ const describedBy = popoverEnabled ? popoverId : void 0;
301
+ const label = `${isRef ? "Reference" : "Footnote"} ${number}`;
302
+ const marker = isRef ? /* @__PURE__ */ jsx(
303
+ "span",
304
+ {
305
+ "data-ncm-ref-marker": "",
306
+ tabIndex: 0,
307
+ role: "note",
308
+ "aria-label": label,
309
+ "aria-describedby": describedBy,
310
+ children: `[${number}]`
311
+ }
312
+ ) : /* @__PURE__ */ jsx(
313
+ "sup",
314
+ {
315
+ "data-ncm-ref-marker": "",
316
+ tabIndex: 0,
317
+ role: "note",
318
+ "aria-label": label,
319
+ "aria-describedby": describedBy,
320
+ children: number
321
+ }
322
+ );
323
+ return /* @__PURE__ */ jsxs(
324
+ "span",
325
+ {
326
+ "data-ncm-token": isRef ? "reference" : "footnote",
327
+ "data-ncm-ref-kind": kind,
328
+ "data-ncm-ref-number": number,
329
+ onMouseEnter: popoverEnabled ? positionPopover : void 0,
330
+ onFocus: popoverEnabled ? positionPopover : void 0,
331
+ children: [
332
+ marker,
333
+ popoverEnabled ? /* @__PURE__ */ jsx("span", { id: popoverId, ref: popoverRef, role: "tooltip", "data-ncm-ref-popover": "", children }) : null
334
+ ]
335
+ }
336
+ );
337
+ }
338
+ var ReferenceBasesContext = createContext(null);
339
+ var BlockReferenceScopeContext = createContext(null);
340
+ function BlockReferenceScope({ blockId, children }) {
341
+ const bases = useContext(ReferenceBasesContext);
342
+ const base = (blockId ? bases?.get(blockId) : void 0) ?? { ref: 0, footnote: 0 };
343
+ const counter = useRef({ ref: 0, footnote: 0 });
344
+ counter.current = { ref: 0, footnote: 0 };
345
+ const value = {
346
+ next(kind) {
347
+ counter.current[kind] += 1;
348
+ return base[kind] + counter.current[kind];
349
+ }
350
+ };
351
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
352
+ }
353
+ function useBlockReferenceScope() {
354
+ return useContext(BlockReferenceScopeContext);
355
+ }
356
+ var INERT_SCOPE = { next: () => 0 };
357
+ function InertReferenceScope({ children }) {
358
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
359
+ }
360
+ var katexPromise = null;
361
+ function loadKatex() {
362
+ if (!katexPromise) {
363
+ katexPromise = Promise.all([
364
+ import('katex'),
365
+ import('katex/dist/katex.min.css')
366
+ ]).then(([module]) => module.default).catch(() => null);
367
+ }
368
+ return katexPromise;
369
+ }
370
+ function useKatexHtml(content, displayMode, enabled = true) {
371
+ const [katexModule, setKatexModule] = useState(null);
372
+ useEffect(() => {
373
+ if (!enabled) {
374
+ return;
375
+ }
376
+ let active = true;
377
+ loadKatex().then((loaded) => {
378
+ if (active) {
379
+ setKatexModule(loaded);
380
+ }
381
+ });
382
+ return () => {
383
+ active = false;
384
+ };
385
+ }, [enabled]);
386
+ return useMemo(() => {
387
+ if (!enabled || !katexModule) {
388
+ return null;
389
+ }
390
+ try {
391
+ return katexModule.renderToString(content, {
392
+ throwOnError: false,
393
+ displayMode
394
+ });
395
+ } catch {
396
+ return null;
397
+ }
398
+ }, [content, displayMode, enabled, katexModule]);
399
+ }
400
+ function InlineContent({
401
+ content,
402
+ className,
403
+ disableBionic,
404
+ disableBeeline
405
+ }) {
406
+ const tokens = useMemo(() => parseInline(content), [content]);
407
+ const hasScope = useBlockReferenceScope() != null;
408
+ const rendered = tokens.map((token, index) => /* @__PURE__ */ jsx(
409
+ TokenRenderer,
410
+ {
411
+ token,
412
+ disableBionic,
413
+ disableBeeline
414
+ },
415
+ index
416
+ ));
417
+ const body = className ? /* @__PURE__ */ jsx("span", { "data-ncm-inline": "", className, children: rendered }) : /* @__PURE__ */ jsx(Fragment, { children: rendered });
418
+ return hasScope ? body : /* @__PURE__ */ jsx(BlockReferenceScope, { children: body });
419
+ }
420
+ function TokenRenderer({ token, disableBionic, disableBeeline }) {
421
+ const config = useNcmConfig();
422
+ const refScope = useBlockReferenceScope();
423
+ const bionicOn = !disableBionic && Boolean(config.reading?.bionic);
424
+ const beelineOn = !disableBeeline && Boolean(config.reading?.beeline);
425
+ const latexContent = token.type === "latex" ? token.content : "";
426
+ const latexHtml = useKatexHtml(latexContent, false, token.type === "latex");
427
+ switch (token.type) {
428
+ case "text":
429
+ if (bionicOn || beelineOn) {
430
+ return renderReadingText(token.content, {
431
+ bionic: bionicOn,
432
+ bionicRatio: config.reading?.bionicRatio,
433
+ beeline: beelineOn
434
+ });
435
+ }
436
+ return /* @__PURE__ */ jsx(Fragment, { children: token.content });
437
+ case "bold":
438
+ return /* @__PURE__ */ jsx("strong", { "data-ncm-token": "bold", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
439
+ TokenRenderer,
440
+ {
441
+ token: child,
442
+ disableBionic,
443
+ disableBeeline
444
+ },
445
+ i
446
+ )) });
447
+ case "italic":
448
+ return /* @__PURE__ */ jsx("em", { "data-ncm-token": "italic", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
449
+ TokenRenderer,
450
+ {
451
+ token: child,
452
+ disableBionic,
453
+ disableBeeline
454
+ },
455
+ i
456
+ )) });
457
+ case "code":
458
+ return /* @__PURE__ */ jsx("code", { "data-ncm-token": "code", children: token.content });
459
+ case "link": {
460
+ const handleClick = (e) => {
461
+ config.inline?.onLinkClick?.(token.href, e);
462
+ };
463
+ return /* @__PURE__ */ jsx(
464
+ "a",
465
+ {
466
+ "data-ncm-token": "link",
467
+ href: token.href,
468
+ title: token.title,
469
+ onClick: handleClick,
470
+ children: token.children.map((child, i) => /* @__PURE__ */ jsx(
471
+ TokenRenderer,
472
+ {
473
+ token: child,
474
+ disableBionic,
475
+ disableBeeline
476
+ },
477
+ i
478
+ ))
479
+ }
480
+ );
481
+ }
482
+ case "wiki_link": {
483
+ const result = config.mesh?.resolveLink(token.target) ?? {
484
+ status: "missing",
485
+ target: token.target,
486
+ resolved: null,
487
+ candidates: []
488
+ };
489
+ const href = config.inline?.resolveWikiLinkHref?.(token.target, result) ?? null;
490
+ const label = token.display ?? token.target;
491
+ if (href) {
492
+ const handleClick = (e) => {
493
+ config.inline?.onWikiLinkClick?.(token.target, result, e);
494
+ };
495
+ return /* @__PURE__ */ jsx(
496
+ "a",
497
+ {
498
+ "data-ncm-token": "wiki_link",
499
+ "data-ncm-wikilink-status": result.status,
500
+ href,
501
+ onClick: handleClick,
502
+ children: label
503
+ }
504
+ );
505
+ }
506
+ if (config.inline?.onWikiLinkClick) {
507
+ const handleClick = (e) => {
508
+ config.inline?.onWikiLinkClick?.(token.target, result, e);
509
+ };
510
+ return /* @__PURE__ */ jsx(
511
+ "button",
512
+ {
513
+ type: "button",
514
+ "data-ncm-token": "wiki_link",
515
+ "data-ncm-wikilink-status": result.status,
516
+ onClick: handleClick,
517
+ children: label
518
+ }
519
+ );
520
+ }
521
+ return /* @__PURE__ */ jsx("span", { "data-ncm-token": "wiki_link", "data-ncm-wikilink-status": result.status, children: label });
522
+ }
523
+ case "latex": {
524
+ const CustomRenderer = config.inline?.customLatexRenderer;
525
+ if (CustomRenderer) {
526
+ return /* @__PURE__ */ jsx(CustomRenderer, { content: token.content, display: false });
527
+ }
528
+ if (latexHtml) {
529
+ return /* @__PURE__ */ jsx("span", { "data-ncm-token": "latex", dangerouslySetInnerHTML: { __html: latexHtml } });
530
+ }
531
+ return /* @__PURE__ */ jsx("code", { "data-ncm-token": "latex", children: token.content });
532
+ }
533
+ case "strikethrough":
534
+ return /* @__PURE__ */ jsx("del", { "data-ncm-token": "strikethrough", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
535
+ TokenRenderer,
536
+ {
537
+ token: child,
538
+ disableBionic,
539
+ disableBeeline
540
+ },
541
+ i
542
+ )) });
543
+ case "image": {
544
+ const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
545
+ return /* @__PURE__ */ jsx(
546
+ "img",
547
+ {
548
+ "data-ncm-token": "image",
549
+ src,
550
+ alt: token.alt,
551
+ title: token.title
552
+ }
553
+ );
554
+ }
555
+ case "wiki_embed": {
556
+ const extension = extractExtension(token.target);
557
+ const embedType = embedTypeFromExtension(extension);
558
+ const result = config.mesh?.resolveEmbed(token.target) ?? null;
559
+ const url = config.embeddings?.resolveUrl?.(token.target, embedType) ?? token.target;
560
+ if (result?.status === "missing") {
561
+ return /* @__PURE__ */ jsx(
562
+ "span",
563
+ {
564
+ "data-ncm-token": "wiki_embed",
565
+ "data-ncm-wikiembed-status": "missing",
566
+ children: `![[${token.target}]]`
567
+ }
568
+ );
569
+ }
570
+ if (result?.status === "ambiguous") {
571
+ return /* @__PURE__ */ jsx(
572
+ "span",
573
+ {
574
+ "data-ncm-token": "wiki_embed",
575
+ "data-ncm-wikiembed-status": "ambiguous",
576
+ children: `![[${token.target}]]`
577
+ }
578
+ );
579
+ }
580
+ if (embedType === "image") {
581
+ return /* @__PURE__ */ jsx(
582
+ "img",
583
+ {
584
+ "data-ncm-token": "wiki_embed",
585
+ "data-ncm-wikiembed-type": embedType,
586
+ src: url,
587
+ alt: token.display ?? token.target,
588
+ className: config.embeddings?.imageClassName
589
+ }
590
+ );
591
+ }
592
+ if (embedType === "video") {
593
+ return /* @__PURE__ */ jsx(
594
+ "video",
595
+ {
596
+ "data-ncm-token": "wiki_embed",
597
+ "data-ncm-wikiembed-type": embedType,
598
+ src: url,
599
+ controls: true,
600
+ className: config.embeddings?.videoClassName
601
+ }
602
+ );
603
+ }
604
+ if (embedType === "audio") {
605
+ return /* @__PURE__ */ jsx(
606
+ "audio",
607
+ {
608
+ "data-ncm-token": "wiki_embed",
609
+ "data-ncm-wikiembed-type": embedType,
610
+ src: url,
611
+ controls: true,
612
+ className: config.embeddings?.audioClassName
613
+ }
614
+ );
615
+ }
616
+ return /* @__PURE__ */ jsx(
617
+ "a",
618
+ {
619
+ "data-ncm-token": "wiki_embed",
620
+ "data-ncm-wikiembed-type": embedType,
621
+ href: url,
622
+ children: token.display ?? token.target
623
+ }
624
+ );
625
+ }
626
+ case "inline_ref": {
627
+ const number = refScope?.next(token.kind) ?? 0;
628
+ return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
629
+ }
630
+ default:
631
+ return null;
632
+ }
633
+ }
634
+ function renderReadingText(content, opts) {
635
+ if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
636
+ const { bionic = false, beeline = false } = opts;
637
+ if (!bionic && !beeline) return /* @__PURE__ */ jsx(Fragment, { children: content });
638
+ const ratio = Math.min(1, Math.max(0.05, opts.bionicRatio ?? 0.5));
639
+ const pieces = [];
640
+ const regex = /[\p{L}\p{N}][\p{L}\p{N}\p{M}'’-]*/gu;
641
+ let match;
642
+ let key = 0;
643
+ let cursor = 0;
644
+ while ((match = regex.exec(content)) !== null) {
645
+ if (match.index > cursor) pieces.push(content.slice(cursor, match.index));
646
+ const segment = match[0];
647
+ const wrapperProps = {};
648
+ if (bionic) wrapperProps["data-ncm-bionic"] = "";
649
+ if (beeline) wrapperProps["data-ncm-beeline-word"] = "";
650
+ if (bionic) {
651
+ const headLen = Math.max(1, Math.ceil(segment.length * ratio));
652
+ pieces.push(
653
+ /* @__PURE__ */ jsxs("span", { ...wrapperProps, children: [
654
+ /* @__PURE__ */ jsx("span", { "data-ncm-bionic-bold": "", style: { fontWeight: 600 }, children: segment.slice(0, headLen) }),
655
+ segment.slice(headLen)
656
+ ] }, key++)
657
+ );
658
+ } else {
659
+ pieces.push(
660
+ /* @__PURE__ */ jsx("span", { ...wrapperProps, children: segment }, key++)
661
+ );
662
+ }
663
+ cursor = match.index + segment.length;
664
+ }
665
+ if (cursor < content.length) pieces.push(content.slice(cursor));
666
+ return /* @__PURE__ */ jsx(Fragment, { children: pieces });
667
+ }
668
+ function BlockquoteBlock({ block, className }) {
669
+ const lines = block.content.split("\n").filter((line) => line.trim() !== "");
670
+ return /* @__PURE__ */ jsx(
671
+ "blockquote",
672
+ {
673
+ "data-ncm-block": block.id,
674
+ "data-ncm-stable": block.stableId,
675
+ "data-ncm-type": block.type,
676
+ "data-block-id": block.id,
677
+ "data-ncm-blockquote": "",
678
+ className,
679
+ children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(InlineContent, { content: line }) }, index))
680
+ }
681
+ );
682
+ }
683
+ function ChartBlock({ block, className }) {
684
+ return /* @__PURE__ */ jsx(
685
+ "pre",
686
+ {
687
+ "data-ncm-block": block.id,
688
+ "data-ncm-stable": block.stableId,
689
+ "data-ncm-type": block.type,
690
+ "data-block-id": block.id,
691
+ "data-ncm-chart": "",
692
+ "data-ncm-chart-type": block.chartType ?? "unknown",
693
+ className: cn(
694
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
695
+ className
696
+ ),
697
+ children: /* @__PURE__ */ jsx("code", { children: block.content })
698
+ }
699
+ );
700
+ }
701
+ var highlighterPromise = import('shiki/bundle/web').then(async (shiki) => {
702
+ const highlighter = await shiki.createHighlighter({
703
+ themes: ["github-light", "github-dark"],
704
+ langs: Object.keys(shiki.bundledLanguages)
705
+ });
706
+ return highlighter;
707
+ }).catch(() => null);
708
+ function useIsDark() {
709
+ const [isDark, setIsDark] = useState(false);
710
+ useEffect(() => {
711
+ if (typeof document === "undefined") return;
712
+ const root = document.documentElement;
713
+ const update = () => setIsDark(root.classList.contains("dark"));
714
+ update();
715
+ const observer = new MutationObserver(update);
716
+ observer.observe(root, { attributes: true, attributeFilter: ["class"] });
717
+ return () => observer.disconnect();
718
+ }, []);
719
+ return isDark;
720
+ }
721
+ function DefaultShikiRenderer({
722
+ code,
723
+ language
724
+ }) {
725
+ const isDark = useIsDark();
726
+ const [highlighter, setHighlighter] = useState(null);
727
+ const shikiTheme = isDark ? "github-dark" : "github-light";
728
+ useEffect(() => {
729
+ let active = true;
730
+ highlighterPromise.then((h) => {
731
+ if (active) setHighlighter(h);
732
+ });
733
+ return () => {
734
+ active = false;
735
+ };
736
+ }, []);
737
+ const tokens = useMemo(() => {
738
+ if (!highlighter) return null;
739
+ const loaded = highlighter.getLoadedLanguages();
740
+ const lang = language && loaded.includes(language) ? language : "text";
741
+ try {
742
+ return highlighter.codeToTokens(code, { lang, theme: shikiTheme }).tokens;
743
+ } catch {
744
+ return null;
745
+ }
746
+ }, [code, language, highlighter, shikiTheme]);
747
+ if (!tokens) {
748
+ return /* @__PURE__ */ jsx(Fragment, { children: code });
749
+ }
750
+ return /* @__PURE__ */ jsx(Fragment, { children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsx("span", { className: "block whitespace-pre", children: line.length === 0 ? " " : line.map((token, tokenIndex) => /* @__PURE__ */ jsx("span", { style: { color: token.color || "inherit" }, children: token.content }, tokenIndex)) }, lineIndex)) });
751
+ }
752
+ function CopyButton({ content }) {
753
+ const [copied, setCopied] = useState(false);
754
+ const handleCopy = useCallback(async () => {
755
+ try {
756
+ await navigator.clipboard.writeText(content);
757
+ setCopied(true);
758
+ setTimeout(() => setCopied(false), 2e3);
759
+ } catch {
760
+ const textarea = document.createElement("textarea");
761
+ textarea.value = content;
762
+ document.body.appendChild(textarea);
763
+ textarea.select();
764
+ document.execCommand("copy");
765
+ document.body.removeChild(textarea);
766
+ setCopied(true);
767
+ setTimeout(() => setCopied(false), 2e3);
768
+ }
769
+ }, [content]);
770
+ return /* @__PURE__ */ jsx(
771
+ "button",
772
+ {
773
+ type: "button",
774
+ onClick: handleCopy,
775
+ "aria-label": copied ? "Copied!" : "Copy code",
776
+ "data-ncm-copy-button": "",
777
+ className: "absolute right-2 top-2 rounded-md bg-background/80 px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-background hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring",
778
+ children: copied ? "Copied!" : "Copy"
779
+ }
780
+ );
781
+ }
782
+ function LineNumbers({ count }) {
783
+ return /* @__PURE__ */ jsx(
784
+ "div",
785
+ {
786
+ "aria-hidden": "true",
787
+ "data-ncm-line-numbers": "",
788
+ className: "select-none pr-4 text-right text-muted-foreground/60",
789
+ children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx("div", { children: i + 1 }, i + 1))
790
+ }
791
+ );
792
+ }
793
+ function CodeBlock({ block, className }) {
794
+ const config = useNcmConfig();
795
+ const { code: codeConfig } = config;
796
+ const lineCount = block.content.split("\n").length;
797
+ const languageLabel = block.language ? /* @__PURE__ */ jsx(
798
+ "div",
799
+ {
800
+ "data-ncm-code-language": "",
801
+ className: "absolute right-2 bottom-2 text-xs text-muted-foreground/60",
802
+ children: block.language
803
+ }
804
+ ) : null;
805
+ if (codeConfig?.renderer) {
806
+ const CustomRenderer = codeConfig.renderer;
807
+ return /* @__PURE__ */ jsxs(
808
+ "div",
809
+ {
810
+ role: "region",
811
+ "aria-label": block.language ? `Code block: ${block.language}` : "Code block",
812
+ "data-ncm-block": block.id,
813
+ "data-ncm-stable": block.stableId,
814
+ "data-ncm-type": block.type,
815
+ "data-block-id": block.id,
816
+ "data-ncm-language": block.language,
817
+ className: cn("relative", className),
818
+ children: [
819
+ codeConfig.copyButton !== false && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
820
+ /* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
821
+ languageLabel
822
+ ]
823
+ }
824
+ );
825
+ }
826
+ return /* @__PURE__ */ jsxs(
827
+ "div",
828
+ {
829
+ role: "region",
830
+ "aria-label": block.language ? `Code block: ${block.language}` : "Code block",
831
+ "data-ncm-block": block.id,
832
+ "data-ncm-stable": block.stableId,
833
+ "data-ncm-type": block.type,
834
+ "data-block-id": block.id,
835
+ "data-ncm-language": block.language,
836
+ className: cn("relative", className),
837
+ children: [
838
+ codeConfig?.copyButton !== false && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
839
+ /* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
840
+ codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
841
+ /* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
842
+ ] }) }),
843
+ languageLabel
844
+ ]
845
+ }
846
+ );
847
+ }
848
+ function ContainerBlock({ block, className }) {
849
+ return /* @__PURE__ */ jsxs(
850
+ BlockShell,
851
+ {
852
+ block,
853
+ "data-ncm-container": "",
854
+ "data-ncm-directive": block.directive,
855
+ className: cn("rounded-lg border border-border bg-card p-4", className),
856
+ children: [
857
+ block.directive && /* @__PURE__ */ jsx("div", { className: "mb-2", children: /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-md bg-muted px-1.5 py-0.5 text-xs font-medium uppercase tracking-wide text-muted-foreground", children: block.directive }) }),
858
+ /* @__PURE__ */ jsx(InlineContent, { content: block.innerContent })
859
+ ]
860
+ }
861
+ );
862
+ }
863
+ function DataviewBlock({ block, className }) {
864
+ return /* @__PURE__ */ jsx(
865
+ "pre",
866
+ {
867
+ "data-ncm-block": block.id,
868
+ "data-ncm-stable": block.stableId,
869
+ "data-ncm-type": block.type,
870
+ "data-block-id": block.id,
871
+ "data-ncm-dataview": "",
872
+ "data-ncm-query-type": block.queryType,
873
+ className: cn(
874
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
875
+ className
876
+ ),
877
+ children: /* @__PURE__ */ jsx("code", { children: block.query })
878
+ }
879
+ );
880
+ }
881
+ function DefinitionBlock({ block, className }) {
882
+ return /* @__PURE__ */ jsxs(
883
+ BlockShell,
884
+ {
885
+ as: "dl",
886
+ block,
887
+ "data-ncm-definition": "",
888
+ className: cn("space-y-1", className),
889
+ children: [
890
+ /* @__PURE__ */ jsx("dt", { className: "font-medium", children: /* @__PURE__ */ jsx(InlineContent, { content: serializeInlineContent(block.term) }) }),
891
+ /* @__PURE__ */ jsx(ChildBlocks, { as: "dd", blocks: block.definition, className: "ml-4 space-y-2" })
892
+ ]
893
+ }
894
+ );
895
+ }
896
+ function toEmbeddingConfigType(embedType) {
897
+ switch (embedType) {
898
+ case "image":
899
+ return "image";
900
+ case "document":
901
+ return "pdf";
902
+ case "file":
903
+ default:
904
+ return "generic_file";
905
+ }
906
+ }
907
+ function dataAttrs(block) {
908
+ return {
909
+ "data-ncm-block": block.id,
910
+ "data-ncm-stable": block.stableId,
911
+ "data-ncm-type": block.type,
912
+ "data-block-id": block.id,
913
+ "data-ncm-embed": "",
914
+ "data-ncm-embed-type": block.embedType
915
+ };
916
+ }
917
+ function EmbedBlock({ block, className }) {
918
+ const config = useNcmConfig();
919
+ const configEmbedType = toEmbeddingConfigType(block.embedType);
920
+ const resolvedUrl = config.embeddings?.resolveUrl?.(block.src, configEmbedType) ?? block.src;
921
+ if (block.embedType === "image") {
922
+ return /* @__PURE__ */ jsx("figure", { ...dataAttrs(block), className: cn(config.embeddings?.imageClassName, className), children: /* @__PURE__ */ jsx("img", { src: resolvedUrl, alt: block.alt, title: block.title ?? void 0 }) });
923
+ }
924
+ return /* @__PURE__ */ jsx("figure", { ...dataAttrs(block), className, children: /* @__PURE__ */ jsx("a", { href: resolvedUrl, title: block.title ?? void 0, children: block.alt || block.src }) });
925
+ }
926
+ var embedFrameStyle = {
927
+ display: "block",
928
+ width: "100%",
929
+ maxWidth: "100%",
930
+ height: "min(80vh, 900px)",
931
+ minHeight: "min(360px, 80vh)"
932
+ };
933
+ var embedMediaStyle = {
934
+ display: "block",
935
+ maxWidth: "100%",
936
+ height: "auto"
937
+ };
938
+ function EmbeddingBlock({ block, className }) {
939
+ const config = useNcmConfig();
940
+ const resolvedUrl = config.embeddings?.resolveUrl?.(block.target, block.embed_type) ?? block.target;
941
+ const CustomRenderer = config.embeddings?.renderers?.[block.embed_type];
942
+ if (CustomRenderer) {
943
+ return /* @__PURE__ */ jsx(CustomRenderer, { block, className, resolvedUrl });
944
+ }
945
+ switch (block.embed_type) {
946
+ case "image":
947
+ return /* @__PURE__ */ jsx(
948
+ ImageEmbed,
949
+ {
950
+ block,
951
+ resolvedUrl,
952
+ className: cn(config.embeddings?.imageClassName, className)
953
+ }
954
+ );
955
+ case "video":
956
+ return /* @__PURE__ */ jsx(
957
+ VideoEmbed,
958
+ {
959
+ block,
960
+ resolvedUrl,
961
+ className: cn(config.embeddings?.videoClassName, className)
962
+ }
963
+ );
964
+ case "audio":
965
+ return /* @__PURE__ */ jsx(
966
+ AudioEmbed,
967
+ {
968
+ block,
969
+ resolvedUrl,
970
+ className: cn(config.embeddings?.audioClassName, className)
971
+ }
972
+ );
973
+ case "pdf":
974
+ return /* @__PURE__ */ jsx(PdfEmbed, { block, resolvedUrl, className });
975
+ case "ncm_embed":
976
+ return /* @__PURE__ */ jsx(NcmEmbed, { block, resolvedUrl, className });
977
+ case "iframe":
978
+ return /* @__PURE__ */ jsx(IframeEmbed, { block, resolvedUrl, className });
979
+ case "generic_file":
980
+ default:
981
+ return /* @__PURE__ */ jsx(GenericFileEmbed, { block, resolvedUrl, className });
982
+ }
983
+ }
984
+ function dataAttrs2(block, embedType) {
985
+ return {
986
+ "data-ncm-block": block.id,
987
+ "data-ncm-stable": block.stableId,
988
+ "data-ncm-type": block.type,
989
+ "data-block-id": block.id,
990
+ "data-ncm-embedding": "",
991
+ "data-ncm-embed-type": embedType
992
+ };
993
+ }
994
+ function ImageEmbed({ block, resolvedUrl, className }) {
995
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "image"), className, children: [
996
+ /* @__PURE__ */ jsx("img", { src: resolvedUrl, alt: block.caption ?? "" }),
997
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
998
+ ] });
999
+ }
1000
+ function VideoEmbed({ block, resolvedUrl, className }) {
1001
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "video"), className, children: [
1002
+ /* @__PURE__ */ jsx("video", { src: resolvedUrl, controls: true }),
1003
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1004
+ ] });
1005
+ }
1006
+ function AudioEmbed({ block, resolvedUrl, className }) {
1007
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "audio"), className, children: [
1008
+ /* @__PURE__ */ jsx("audio", { src: resolvedUrl, controls: true, className: "w-full" }),
1009
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1010
+ ] });
1011
+ }
1012
+ function PdfEmbed({ block, resolvedUrl, className }) {
1013
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "pdf"), className: cn("w-full max-w-full", className), children: [
1014
+ /* @__PURE__ */ jsx(
1015
+ "iframe",
1016
+ {
1017
+ src: resolvedUrl,
1018
+ title: block.caption ?? "PDF document",
1019
+ className: "rounded-lg border border-border",
1020
+ style: embedFrameStyle
1021
+ }
1022
+ ),
1023
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1024
+ ] });
1025
+ }
1026
+ function IframeEmbed({ block, resolvedUrl, className }) {
1027
+ const [useFrame, setUseFrame] = useState(false);
1028
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "iframe"), className: cn("w-full max-w-full", className), children: [
1029
+ useFrame ? /* @__PURE__ */ jsx(
1030
+ "iframe",
1031
+ {
1032
+ src: resolvedUrl,
1033
+ title: block.caption ?? block.alt ?? block.target,
1034
+ className: "rounded-lg border border-border",
1035
+ style: embedFrameStyle
1036
+ }
1037
+ ) : /* @__PURE__ */ jsx(
1038
+ "img",
1039
+ {
1040
+ src: resolvedUrl,
1041
+ alt: block.alt || block.caption || block.target,
1042
+ style: embedMediaStyle,
1043
+ onError: () => setUseFrame(true)
1044
+ }
1045
+ ),
1046
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1047
+ ] });
1048
+ }
1049
+ function NcmEmbed({ block, resolvedUrl, className }) {
1050
+ return /* @__PURE__ */ jsxs(
1051
+ "div",
1052
+ {
1053
+ ...dataAttrs2(block, "ncm_embed"),
1054
+ className: cn("rounded-lg border border-dashed border-border bg-muted p-4", className),
1055
+ children: [
1056
+ /* @__PURE__ */ jsxs("div", { className: "text-sm text-muted-foreground", children: [
1057
+ "Embedded: ",
1058
+ /* @__PURE__ */ jsx("code", { className: "rounded bg-background px-1", children: block.target }),
1059
+ resolvedUrl !== block.target && /* @__PURE__ */ jsxs(Fragment, { children: [
1060
+ " ",
1061
+ /* @__PURE__ */ jsx("a", { href: resolvedUrl, className: "underline underline-offset-4", children: "open" })
1062
+ ] })
1063
+ ] }),
1064
+ block.caption && /* @__PURE__ */ jsx("div", { className: "mt-2 text-sm text-muted-foreground", children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1065
+ ]
1066
+ }
1067
+ );
1068
+ }
1069
+ function GenericFileEmbed({ block, resolvedUrl, className }) {
1070
+ return /* @__PURE__ */ jsxs("figure", { ...dataAttrs2(block, "generic_file"), className, children: [
1071
+ /* @__PURE__ */ jsxs(
1072
+ "a",
1073
+ {
1074
+ href: resolvedUrl,
1075
+ download: true,
1076
+ className: "flex items-center gap-2 rounded-lg border border-border bg-muted p-4 hover:bg-background",
1077
+ children: [
1078
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: block.target }),
1079
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
1080
+ "(",
1081
+ block.file_format.toUpperCase(),
1082
+ ")"
1083
+ ] })
1084
+ ]
1085
+ }
1086
+ ),
1087
+ block.caption && /* @__PURE__ */ jsx("figcaption", { children: /* @__PURE__ */ jsx(InlineContent, { content: block.caption }) })
1088
+ ] });
1089
+ }
1090
+ function FigureBlock({ block, className }) {
1091
+ const { embed, caption, number } = block;
1092
+ return /* @__PURE__ */ jsxs(
1093
+ BlockShell,
1094
+ {
1095
+ as: "figure",
1096
+ block,
1097
+ "data-ncm-figure": "",
1098
+ className: cn("space-y-2", className),
1099
+ children: [
1100
+ embed.embedType === "image" ? /* @__PURE__ */ jsx("img", { src: embed.src, alt: embed.alt, title: embed.title ?? void 0 }) : /* @__PURE__ */ jsx(
1101
+ "a",
1102
+ {
1103
+ href: embed.src,
1104
+ title: embed.title ?? void 0,
1105
+ "data-ncm-embed-type": embed.embedType,
1106
+ children: embed.alt || embed.src
1107
+ }
1108
+ ),
1109
+ /* @__PURE__ */ jsxs(
1110
+ "figcaption",
1111
+ {
1112
+ className: "text-sm text-muted-foreground",
1113
+ "data-ncm-figure-number": number,
1114
+ children: [
1115
+ typeof number === "number" ? /* @__PURE__ */ jsxs("span", { "data-ncm-figure-label": "", children: [
1116
+ "Figure ",
1117
+ number,
1118
+ ". "
1119
+ ] }) : null,
1120
+ /* @__PURE__ */ jsx(InlineContent, { content: serializeInlineContent(caption.content) })
1121
+ ]
1122
+ }
1123
+ )
1124
+ ]
1125
+ }
1126
+ );
1127
+ }
1128
+ function FootnoteBlock({ block, className }) {
1129
+ return /* @__PURE__ */ jsxs(
1130
+ BlockShell,
1131
+ {
1132
+ id: block.stableId,
1133
+ block,
1134
+ "data-ncm-footnote": "",
1135
+ "data-ncm-footnote-label": block.label,
1136
+ className: cn("flex gap-2 text-sm text-muted-foreground", className),
1137
+ children: [
1138
+ /* @__PURE__ */ jsxs("span", { "data-ncm-footnote-marker": "", className: "font-medium", children: [
1139
+ block.label,
1140
+ "."
1141
+ ] }),
1142
+ /* @__PURE__ */ jsx(ChildBlocks, { blocks: block.content, className: "space-y-2" })
1143
+ ]
1144
+ }
1145
+ );
1146
+ }
1147
+ function formatValue(value) {
1148
+ if (Array.isArray(value)) return value.map((v) => String(v)).join(", ");
1149
+ if (value === null || value === void 0) return "";
1150
+ if (typeof value === "object") return JSON.stringify(value);
1151
+ return String(value);
1152
+ }
1153
+ function FrontmatterBlock({ block, className }) {
1154
+ const entries = Object.entries(block.data ?? {});
1155
+ return /* @__PURE__ */ jsx(
1156
+ "dl",
1157
+ {
1158
+ "data-ncm-block": block.id,
1159
+ "data-ncm-stable": block.stableId,
1160
+ "data-ncm-type": block.type,
1161
+ "data-block-id": block.id,
1162
+ "data-ncm-frontmatter": "",
1163
+ className: cn(
1164
+ "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 rounded-lg border border-border bg-muted/30 p-4 text-sm",
1165
+ className
1166
+ ),
1167
+ children: entries.map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "contents", children: [
1168
+ /* @__PURE__ */ jsx("dt", { className: "font-medium text-muted-foreground", children: key }),
1169
+ /* @__PURE__ */ jsx("dd", { className: "text-foreground", children: formatValue(value) })
1170
+ ] }, key))
1171
+ }
1172
+ );
1173
+ }
1174
+ function HeaderBlock({ block, className }) {
1175
+ const Tag = `h${block.level}`;
1176
+ return /* @__PURE__ */ jsx(
1177
+ Tag,
1178
+ {
1179
+ id: block.stableId ?? block.id,
1180
+ "data-ncm-block": block.id,
1181
+ "data-ncm-stable": block.stableId,
1182
+ "data-ncm-type": block.type,
1183
+ "data-block-id": block.id,
1184
+ "data-ncm-level": block.level,
1185
+ className,
1186
+ children: /* @__PURE__ */ jsx(InlineContent, { content: block.content, disableBionic: true, disableBeeline: true })
1187
+ }
1188
+ );
1189
+ }
1190
+ function HorizontalRuleBlock({ block, className }) {
1191
+ return /* @__PURE__ */ jsx(
1192
+ "hr",
1193
+ {
1194
+ "data-ncm-block": block.id,
1195
+ "data-ncm-stable": block.stableId,
1196
+ "data-ncm-type": block.type,
1197
+ "data-block-id": block.id,
1198
+ "data-ncm-horizontal-rule": "",
1199
+ className
1200
+ }
1201
+ );
1202
+ }
1203
+ function HtmlBlock({ block, className }) {
1204
+ return /* @__PURE__ */ jsx(
1205
+ "pre",
1206
+ {
1207
+ "data-ncm-block": block.id,
1208
+ "data-ncm-stable": block.stableId,
1209
+ "data-ncm-type": block.type,
1210
+ "data-block-id": block.id,
1211
+ "data-ncm-html": "",
1212
+ className: cn(
1213
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1214
+ className
1215
+ ),
1216
+ children: /* @__PURE__ */ jsx("code", { children: block.content })
1217
+ }
1218
+ );
1219
+ }
1220
+ function LatexDisplayBlock({ block, className }) {
1221
+ const config = useNcmConfig();
1222
+ const CustomRenderer = config.inline?.customLatexRenderer;
1223
+ const html = useKatexHtml(block.content, true, !CustomRenderer);
1224
+ if (CustomRenderer) {
1225
+ return /* @__PURE__ */ jsx(
1226
+ "div",
1227
+ {
1228
+ role: "region",
1229
+ "aria-label": "Mathematical expression",
1230
+ "data-ncm-block": block.id,
1231
+ "data-ncm-stable": block.stableId,
1232
+ "data-ncm-type": block.type,
1233
+ "data-block-id": block.id,
1234
+ "data-ncm-latex-display": "",
1235
+ className,
1236
+ children: /* @__PURE__ */ jsx(CustomRenderer, { content: block.content, display: true })
1237
+ }
1238
+ );
1239
+ }
1240
+ if (html) {
1241
+ return /* @__PURE__ */ jsx(
1242
+ "div",
1243
+ {
1244
+ role: "region",
1245
+ "aria-label": "Mathematical expression",
1246
+ "data-ncm-block": block.id,
1247
+ "data-ncm-stable": block.stableId,
1248
+ "data-ncm-type": block.type,
1249
+ "data-block-id": block.id,
1250
+ "data-ncm-latex-display": "",
1251
+ className: cn("overflow-x-auto", className),
1252
+ dangerouslySetInnerHTML: { __html: html }
1253
+ }
1254
+ );
1255
+ }
1256
+ return /* @__PURE__ */ jsx(
1257
+ "pre",
1258
+ {
1259
+ role: "region",
1260
+ "aria-label": "Mathematical expression (source)",
1261
+ "data-ncm-block": block.id,
1262
+ "data-ncm-stable": block.stableId,
1263
+ "data-ncm-type": block.type,
1264
+ "data-block-id": block.id,
1265
+ "data-ncm-latex-display": "",
1266
+ className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
1267
+ children: /* @__PURE__ */ jsx("code", { children: block.content })
1268
+ }
1269
+ );
1270
+ }
1271
+ function LinkBlock({ block, className }) {
1272
+ return /* @__PURE__ */ jsx(
1273
+ "a",
1274
+ {
1275
+ "data-ncm-block": block.id,
1276
+ "data-ncm-stable": block.stableId,
1277
+ "data-ncm-type": block.type,
1278
+ "data-block-id": block.id,
1279
+ "data-ncm-link": "",
1280
+ href: block.url,
1281
+ title: block.title ?? void 0,
1282
+ className: cn("block text-primary hover:underline", className),
1283
+ children: block.text || block.url
1284
+ }
1285
+ );
1286
+ }
1287
+ function ListBlock({ block, className }) {
1288
+ const isOrdered = block.type === "list_ordered";
1289
+ const Tag = isOrdered ? "ol" : "ul";
1290
+ return /* @__PURE__ */ jsx(
1291
+ Tag,
1292
+ {
1293
+ role: "list",
1294
+ "data-ncm-block": block.id,
1295
+ "data-ncm-stable": block.stableId,
1296
+ "data-ncm-type": block.type,
1297
+ "data-block-id": block.id,
1298
+ "data-ncm-list": "",
1299
+ "data-ncm-list-type": isOrdered ? "ordered" : "unordered",
1300
+ className,
1301
+ children: /* @__PURE__ */ jsx(ListItems, { items: block.items, itemIds: block.itemIds, ordered: isOrdered })
1302
+ }
1303
+ );
1304
+ }
1305
+ function nestedItemIdKey(id) {
1306
+ if (!id) {
1307
+ return void 0;
1308
+ }
1309
+ if (typeof id === "string") {
1310
+ return id;
1311
+ }
1312
+ if (Array.isArray(id)) {
1313
+ return id.map(nestedItemIdKey).filter(Boolean).join(".");
1314
+ }
1315
+ return `${id.kind}:${id.items.map(nestedItemIdKey).filter(Boolean).join(".")}`;
1316
+ }
1317
+ function ListItems({ items, itemIds, ordered }) {
1318
+ return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
1319
+ const key = nestedItemIdKey(itemIds?.[index]) ?? `item-${index}`;
1320
+ if (typeof item === "string") {
1321
+ return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(InlineContent, { content: item }) }, key);
1322
+ }
1323
+ if (isTypedNestedList(item)) {
1324
+ return /* @__PURE__ */ jsx(NestedTypedList, { list: item }, key);
1325
+ }
1326
+ if (Array.isArray(item) && item.length > 0) {
1327
+ const [first, ...rest] = item;
1328
+ const content = typeof first === "string" ? first : "";
1329
+ const nestedContent = processNestedItems(rest, ordered);
1330
+ return /* @__PURE__ */ jsxs("li", { "data-ncm-list-item": "", children: [
1331
+ /* @__PURE__ */ jsx(InlineContent, { content }),
1332
+ nestedContent
1333
+ ] }, key);
1334
+ }
1335
+ return null;
1336
+ }) });
1337
+ }
1338
+ function processNestedItems(items, parentOrdered) {
1339
+ if (items.length === 0) return null;
1340
+ const groups = [];
1341
+ for (const item of items) {
1342
+ if (isTypedNestedList(item)) {
1343
+ const isOrdered = item.kind === "ordered";
1344
+ const lastGroup = groups[groups.length - 1];
1345
+ if (lastGroup && lastGroup.ordered === isOrdered) {
1346
+ lastGroup.items.push(...item.items);
1347
+ } else {
1348
+ groups.push({ ordered: isOrdered, items: [...item.items] });
1349
+ }
1350
+ } else {
1351
+ const lastGroup = groups[groups.length - 1];
1352
+ if (lastGroup && lastGroup.ordered === parentOrdered) {
1353
+ lastGroup.items.push(item);
1354
+ } else {
1355
+ groups.push({ ordered: parentOrdered, items: [item] });
1356
+ }
1357
+ }
1358
+ }
1359
+ return groups.map((group, index) => {
1360
+ const Tag = group.ordered ? "ol" : "ul";
1361
+ return /* @__PURE__ */ jsx(Tag, { "data-ncm-list-nested": "", children: /* @__PURE__ */ jsx(ListItems, { items: group.items, ordered: group.ordered }) }, index);
1362
+ });
1363
+ }
1364
+ function NestedTypedList({ list }) {
1365
+ const Tag = list.kind === "ordered" ? "ol" : "ul";
1366
+ return /* @__PURE__ */ jsx(Tag, { "data-ncm-list-nested": "", children: /* @__PURE__ */ jsx(ListItems, { items: list.items, ordered: list.kind === "ordered" }) });
1367
+ }
1368
+ function MathBlock({ block, className }) {
1369
+ const html = useKatexHtml(block.content, true);
1370
+ if (html) {
1371
+ return /* @__PURE__ */ jsx(
1372
+ "div",
1373
+ {
1374
+ role: "region",
1375
+ "aria-label": "Mathematical expression",
1376
+ "data-ncm-block": block.id,
1377
+ "data-ncm-stable": block.stableId,
1378
+ "data-ncm-type": block.type,
1379
+ "data-block-id": block.id,
1380
+ "data-ncm-math": "",
1381
+ className: cn("overflow-x-auto", className),
1382
+ dangerouslySetInnerHTML: { __html: html }
1383
+ }
1384
+ );
1385
+ }
1386
+ return /* @__PURE__ */ jsx(
1387
+ "pre",
1388
+ {
1389
+ role: "region",
1390
+ "aria-label": "Mathematical expression (source)",
1391
+ "data-ncm-block": block.id,
1392
+ "data-ncm-stable": block.stableId,
1393
+ "data-ncm-type": block.type,
1394
+ "data-block-id": block.id,
1395
+ "data-ncm-math": "",
1396
+ className: cn(
1397
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1398
+ className
1399
+ ),
1400
+ children: /* @__PURE__ */ jsx("code", { children: block.content })
1401
+ }
1402
+ );
1403
+ }
1404
+ function MermaidBlock({ block, className }) {
1405
+ return /* @__PURE__ */ jsx(
1406
+ "pre",
1407
+ {
1408
+ "data-ncm-block": block.id,
1409
+ "data-ncm-stable": block.stableId,
1410
+ "data-ncm-type": block.type,
1411
+ "data-block-id": block.id,
1412
+ "data-ncm-mermaid": "",
1413
+ "data-ncm-diagram-type": block.diagramType,
1414
+ className: cn(
1415
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1416
+ className
1417
+ ),
1418
+ children: /* @__PURE__ */ jsx("code", { children: block.content })
1419
+ }
1420
+ );
1421
+ }
1422
+ function PageBreakerBlock({ block, className }) {
1423
+ return /* @__PURE__ */ jsx(
1424
+ "div",
1425
+ {
1426
+ "data-ncm-block": block.id,
1427
+ "data-ncm-stable": block.stableId,
1428
+ "data-ncm-type": block.type,
1429
+ "data-block-id": block.id,
1430
+ "data-ncm-page": block.page,
1431
+ "aria-hidden": "true",
1432
+ className,
1433
+ style: { height: 0, margin: 0, padding: 0, border: 0 }
1434
+ }
1435
+ );
1436
+ }
1437
+ function ParagraphBlock({ block, className }) {
1438
+ return /* @__PURE__ */ jsx(
1439
+ "p",
1440
+ {
1441
+ "data-ncm-block": block.id,
1442
+ "data-ncm-stable": block.stableId,
1443
+ "data-ncm-type": block.type,
1444
+ "data-block-id": block.id,
1445
+ "data-ncm-paragraph": "",
1446
+ className,
1447
+ children: /* @__PURE__ */ jsx(InlineContent, { content: block.content })
1448
+ }
1449
+ );
1450
+ }
1451
+ function TableBlock({ block, className }) {
1452
+ return /* @__PURE__ */ jsx(
1453
+ "div",
1454
+ {
1455
+ "data-ncm-block": block.id,
1456
+ "data-ncm-stable": block.stableId,
1457
+ "data-ncm-type": block.type,
1458
+ "data-block-id": block.id,
1459
+ "data-ncm-table": "",
1460
+ className: cn("w-full overflow-x-auto", className),
1461
+ children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
1462
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { "data-ncm-table-row": "", children: block.headers.map((header, index) => /* @__PURE__ */ jsx("th", { "data-ncm-table-header": "", children: /* @__PURE__ */ jsx(InlineContent, { content: header }) }, index)) }) }),
1463
+ /* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
1464
+ const rowKey = block.rowIds?.[rowIndex] ?? `${block.id}.${rowIndex + 1}`;
1465
+ return /* @__PURE__ */ jsx("tr", { "data-ncm-table-row": "", children: row.map((cell, cellIndex) => /* @__PURE__ */ jsx("td", { "data-ncm-table-cell": "", children: /* @__PURE__ */ jsx(InlineContent, { content: cell }) }, `${rowKey}.${cellIndex + 1}`)) }, rowKey);
1466
+ }) })
1467
+ ] })
1468
+ }
1469
+ );
1470
+ }
1471
+ function TaskItems({ items }) {
1472
+ return /* @__PURE__ */ jsx(Fragment, { children: items.map((item) => {
1473
+ const status = item.checked ? "Completed" : "Incomplete";
1474
+ return /* @__PURE__ */ jsxs(
1475
+ "li",
1476
+ {
1477
+ "data-ncm-task-item": "",
1478
+ "data-block-id": item.id,
1479
+ "data-ncm-checked": item.checked ? "true" : "false",
1480
+ className: "flex flex-col",
1481
+ children: [
1482
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
1483
+ /* @__PURE__ */ jsx(
1484
+ "input",
1485
+ {
1486
+ type: "checkbox",
1487
+ checked: item.checked,
1488
+ disabled: true,
1489
+ readOnly: true,
1490
+ "aria-label": `${status} task`,
1491
+ className: "size-4 shrink-0"
1492
+ }
1493
+ ),
1494
+ /* @__PURE__ */ jsxs("span", { children: [
1495
+ /* @__PURE__ */ jsxs("span", { "data-ncm-task-status": "", className: "sr-only", children: [
1496
+ status,
1497
+ ":",
1498
+ " "
1499
+ ] }),
1500
+ /* @__PURE__ */ jsx(InlineContent, { content: serializeInlineContent(item.content) })
1501
+ ] })
1502
+ ] }),
1503
+ item.children ? /* @__PURE__ */ jsx("ul", { role: "list", "data-ncm-list-nested": "", className: "ml-6 list-none", children: /* @__PURE__ */ jsx(TaskItems, { items: item.children.items }) }) : null
1504
+ ]
1505
+ },
1506
+ item.stableId ?? item.id
1507
+ );
1508
+ }) });
1509
+ }
1510
+ function TaskListBlock({ block, className }) {
1511
+ return /* @__PURE__ */ jsx(
1512
+ BlockShell,
1513
+ {
1514
+ as: "ul",
1515
+ block,
1516
+ role: "list",
1517
+ "data-ncm-task-list": "",
1518
+ className: cn("list-none space-y-1", className),
1519
+ children: /* @__PURE__ */ jsx(TaskItems, { items: block.items })
1520
+ }
1521
+ );
1522
+ }
1523
+
1524
+ // src/lib/defaults.ts
1525
+ function fallbackSource(block) {
1526
+ const maybeSource = block;
1527
+ if (typeof maybeSource.raw === "string" && maybeSource.raw.length > 0) {
1528
+ return maybeSource.raw;
1529
+ }
1530
+ if (typeof maybeSource.content === "string" && maybeSource.content.length > 0) {
1531
+ return maybeSource.content;
1532
+ }
1533
+ return JSON.stringify(block, null, 2);
1534
+ }
1535
+ function FallbackBlock({ block, className }) {
1536
+ return createElement(
1537
+ "pre",
1538
+ {
1539
+ "data-ncm-block": block.id,
1540
+ "data-ncm-stable": block.stableId,
1541
+ "data-ncm-type": block.type,
1542
+ "data-block-id": block.id,
1543
+ "data-ncm-fallback": "",
1544
+ className: cn(
1545
+ "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1546
+ className
1547
+ )
1548
+ },
1549
+ createElement("code", null, fallbackSource(block))
1550
+ );
1551
+ }
1552
+ var defaultRenderers = {
1553
+ // Standard blocks
1554
+ paragraph: ParagraphBlock,
1555
+ header: HeaderBlock,
1556
+ blockquote: BlockquoteBlock,
1557
+ code: CodeBlock,
1558
+ container: ContainerBlock,
1559
+ frontmatter: FrontmatterBlock,
1560
+ html: HtmlBlock,
1561
+ list_ordered: ListBlock,
1562
+ list_unordered: ListBlock,
1563
+ table: TableBlock,
1564
+ embed: EmbedBlock,
1565
+ embedding: EmbeddingBlock,
1566
+ latex_display: LatexDisplayBlock,
1567
+ horizontal_rule: HorizontalRuleBlock,
1568
+ page_breaker: PageBreakerBlock,
1569
+ // Promoted blocks
1570
+ link: LinkBlock,
1571
+ figure: FigureBlock,
1572
+ // Extension blocks
1573
+ admonition: AdmonitionBlock,
1574
+ footnote: FootnoteBlock,
1575
+ task_list: TaskListBlock,
1576
+ definition: DefinitionBlock,
1577
+ spoiler: SpoilerBlock,
1578
+ aside: AsideBlock,
1579
+ attribution: AttributionBlock,
1580
+ // Promoted code blocks
1581
+ mermaid: MermaidBlock,
1582
+ dataview: DataviewBlock,
1583
+ math: MathBlock,
1584
+ chart: ChartBlock,
1585
+ // custom_code is handled separately by language (see NcmBlock dispatch)
1586
+ custom_code: {},
1587
+ fallback: FallbackBlock
1588
+ };
1589
+ function CustomCodeBlock({ block, className }) {
1590
+ return /* @__PURE__ */ jsxs(
1591
+ "div",
1592
+ {
1593
+ role: "region",
1594
+ "aria-label": `Custom code block: ${block.language}`,
1595
+ "data-ncm-block": block.id,
1596
+ "data-ncm-stable": block.stableId,
1597
+ "data-ncm-type": block.type,
1598
+ "data-block-id": block.id,
1599
+ "data-ncm-custom-code": "",
1600
+ "data-ncm-language": block.language,
1601
+ className: cn("overflow-x-auto", className),
1602
+ children: [
1603
+ /* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
1604
+ /* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
1605
+ ]
1606
+ }
1607
+ );
1608
+ }
1609
+ var NcmBlockErrorBoundary = class extends Component {
1610
+ state = {
1611
+ error: null
1612
+ };
1613
+ static getDerivedStateFromError(error) {
1614
+ return { error };
1615
+ }
1616
+ componentDidCatch(error, info) {
1617
+ console.warn(
1618
+ `[ncm-ui] Renderer for block '${this.props.block.type}' failed; rendering fallback.`,
1619
+ { block: this.props.block, error, info }
1620
+ );
1621
+ }
1622
+ render() {
1623
+ if (this.state.error) {
1624
+ return /* @__PURE__ */ jsx(FallbackBlock, { block: this.props.block, className: this.props.className });
1625
+ }
1626
+ return this.props.children;
1627
+ }
1628
+ };
1629
+ function warnMissingRenderer(block) {
1630
+ console.warn(
1631
+ `[ncm-ui] No renderer registered for block type '${block.type}'; rendering fallback.`,
1632
+ { block }
1633
+ );
1634
+ }
1635
+ function NcmBlock({ block, className, renderers }) {
1636
+ const contextRenderers = useNcmConfig().renderers;
1637
+ const mergedRenderers = { ...defaultRenderers, ...contextRenderers, ...renderers };
1638
+ let content = null;
1639
+ if (block.type === "custom_code") {
1640
+ const customCodeBlock = block;
1641
+ const customCodeRenderers = {
1642
+ ...defaultRenderers.custom_code,
1643
+ ...contextRenderers?.custom_code,
1644
+ ...renderers?.custom_code
1645
+ };
1646
+ const LanguageRenderer = customCodeRenderers[customCodeBlock.language];
1647
+ content = LanguageRenderer ? /* @__PURE__ */ jsx(LanguageRenderer, { block: customCodeBlock, className }) : (
1648
+ // Fallback: use default CustomCodeBlock renderer
1649
+ /* @__PURE__ */ jsx(CustomCodeBlock, { block: customCodeBlock, className })
1650
+ );
1651
+ } else {
1652
+ const blockType = block.type;
1653
+ const Renderer = mergedRenderers[blockType];
1654
+ if (Renderer) {
1655
+ content = /* @__PURE__ */ jsx(Renderer, { block, className });
1656
+ } else if (mergedRenderers.fallback) {
1657
+ warnMissingRenderer(block);
1658
+ content = /* @__PURE__ */ jsx(mergedRenderers.fallback, { block, className });
1659
+ }
1660
+ }
1661
+ return /* @__PURE__ */ jsx(BlockReferenceScope, { blockId: block.id, children: /* @__PURE__ */ jsx(NcmBlockErrorBoundary, { block, className, children: content }) });
1662
+ }
1663
+ function blockKey(block) {
1664
+ return block.stableId ? `${block.id}:${block.stableId}` : block.id;
1665
+ }
1666
+ function blockDataAttributes(block) {
1667
+ return {
1668
+ "data-ncm-block": block.id,
1669
+ "data-ncm-stable": block.stableId,
1670
+ "data-ncm-type": block.type,
1671
+ "data-block-id": block.id
1672
+ };
1673
+ }
1674
+ function BlockShell({
1675
+ as = "div",
1676
+ block,
1677
+ children,
1678
+ ...props
1679
+ }) {
1680
+ return createElement(as, {
1681
+ ...blockDataAttributes(block),
1682
+ ...props
1683
+ }, children);
1684
+ }
1685
+ function ChildBlocks({
1686
+ as = "div",
1687
+ blocks,
1688
+ ...props
1689
+ }) {
1690
+ return createElement(
1691
+ as,
1692
+ props,
1693
+ blocks.map((block) => /* @__PURE__ */ jsx(NcmBlock, { block }, blockKey(block)))
1694
+ );
1695
+ }
1696
+ function SpoilerBlock({ block, className }) {
1697
+ return /* @__PURE__ */ jsxs(
1698
+ BlockShell,
1699
+ {
1700
+ as: "details",
1701
+ block,
1702
+ "data-ncm-spoiler": "",
1703
+ open: block.open,
1704
+ className: cn("rounded-lg border border-border bg-card p-4", className),
1705
+ children: [
1706
+ /* @__PURE__ */ jsx("summary", { className: "cursor-pointer font-medium", children: block.summary }),
1707
+ /* @__PURE__ */ jsx(ChildBlocks, { blocks: block.children, className: "mt-2 space-y-2" })
1708
+ ]
1709
+ }
1710
+ );
1711
+ }
1712
+
1713
+ export { SpoilerBlock };