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