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