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