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