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