@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,13 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { FigureBlock as FigureBlock$1 } from '@nuucognition/ncm';
3
+ import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
4
+ import 'react';
5
+
6
+ type FigureBlockProps = BlockRendererProps<FigureBlock$1>;
7
+ /**
8
+ * Figure renderer — an embed plus caption, promoted from `embed + paragraph`
9
+ * (no blank line). Images render inline; other embed types render as a link.
10
+ */
11
+ declare function FigureBlock({ block, className }: FigureBlockProps): react_jsx_runtime.JSX.Element;
12
+
13
+ export { FigureBlock, type FigureBlockProps };
@@ -0,0 +1,656 @@
1
+ "use client";
2
+ import { serializeInlineContent } from '@nuucognition/ncm';
3
+ import { createContext, createElement, useMemo, useContext, useRef, useState, useEffect, useId, useCallback } from 'react';
4
+ import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
5
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
+ import { clsx } from 'clsx';
7
+ import { twMerge } from 'tailwind-merge';
8
+
9
+ // src/blocks/figure/figure.tsx
10
+
11
+ // src/inline/parser.ts
12
+ function splitOnce(input, delimiter) {
13
+ const idx = input.indexOf(delimiter);
14
+ if (idx === -1) {
15
+ return [input, null];
16
+ }
17
+ return [input.slice(0, idx), input.slice(idx + delimiter.length)];
18
+ }
19
+ function parseWikiTarget(rawInside) {
20
+ const inside = rawInside.trim();
21
+ const [targetPlusAnchor, displayRaw] = splitOnce(inside, "|");
22
+ const [targetRaw, anchorRaw] = splitOnce(targetPlusAnchor, "#");
23
+ const target = targetRaw.trim();
24
+ const display = displayRaw !== null ? displayRaw.trim() || null : null;
25
+ const anchor = anchorRaw !== null ? anchorRaw.trim() || null : null;
26
+ return { target, display, anchor };
27
+ }
28
+ var INLINE_REF_KIND_RE = /^\s*(ref|footnote)\s*:\s*([\s\S]*)$/i;
29
+ function tryParseInlineRef(input) {
30
+ let depth = 1;
31
+ let i = 2;
32
+ for (; i < input.length; i++) {
33
+ const ch = input[i];
34
+ if (ch === "[") {
35
+ depth++;
36
+ } else if (ch === "]") {
37
+ depth--;
38
+ if (depth === 0) break;
39
+ }
40
+ }
41
+ if (depth !== 0) return null;
42
+ const inner = input.slice(2, i);
43
+ const length = i + 1;
44
+ const match = INLINE_REF_KIND_RE.exec(inner);
45
+ if (match && match[1]) {
46
+ const kind = match[1].toLowerCase() === "ref" ? "ref" : "footnote";
47
+ return { token: { type: "inline_ref", kind, content: (match[2] ?? "").trim() }, length };
48
+ }
49
+ return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
50
+ }
51
+ function parseInline(content) {
52
+ if (!content) return [];
53
+ const tokens = [];
54
+ let remaining = content;
55
+ while (remaining.length > 0) {
56
+ const codeMatch = remaining.match(/^`([^`]+)`/);
57
+ if (codeMatch && codeMatch[1] !== void 0) {
58
+ tokens.push({ type: "code", content: codeMatch[1] });
59
+ remaining = remaining.slice(codeMatch[0].length);
60
+ continue;
61
+ }
62
+ const latexMatch = remaining.match(/^\$(?!\s)([^$\n]+?)(?<!\s)\$/);
63
+ if (latexMatch && latexMatch[1] !== void 0) {
64
+ tokens.push({ type: "latex", content: latexMatch[1] });
65
+ remaining = remaining.slice(latexMatch[0].length);
66
+ continue;
67
+ }
68
+ if (remaining.startsWith("^[")) {
69
+ const inlineRef = tryParseInlineRef(remaining);
70
+ if (inlineRef) {
71
+ tokens.push(inlineRef.token);
72
+ remaining = remaining.slice(inlineRef.length);
73
+ continue;
74
+ }
75
+ }
76
+ const wikiEmbedMatch = remaining.match(/^!\[\[([^\]]+)\]\]/);
77
+ if (wikiEmbedMatch && wikiEmbedMatch[1] !== void 0) {
78
+ const parsed = parseWikiTarget(wikiEmbedMatch[1]);
79
+ tokens.push({
80
+ type: "wiki_embed",
81
+ target: parsed.target,
82
+ display: parsed.display,
83
+ anchor: parsed.anchor
84
+ });
85
+ remaining = remaining.slice(wikiEmbedMatch[0].length);
86
+ continue;
87
+ }
88
+ const wikiLinkMatch = remaining.match(/^\[\[([^\]]+)\]\]/);
89
+ if (wikiLinkMatch && wikiLinkMatch[1] !== void 0) {
90
+ const parsed = parseWikiTarget(wikiLinkMatch[1]);
91
+ tokens.push({
92
+ type: "wiki_link",
93
+ target: parsed.target,
94
+ display: parsed.display,
95
+ anchor: parsed.anchor
96
+ });
97
+ remaining = remaining.slice(wikiLinkMatch[0].length);
98
+ continue;
99
+ }
100
+ const imageMatch = remaining.match(/^!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
101
+ if (imageMatch && imageMatch[1] !== void 0 && imageMatch[2] !== void 0) {
102
+ tokens.push({
103
+ type: "image",
104
+ alt: imageMatch[1],
105
+ src: imageMatch[2],
106
+ title: imageMatch[3]
107
+ });
108
+ remaining = remaining.slice(imageMatch[0].length);
109
+ continue;
110
+ }
111
+ const linkMatch = remaining.match(/^\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
112
+ if (linkMatch && linkMatch[1] !== void 0 && linkMatch[2] !== void 0) {
113
+ tokens.push({
114
+ type: "link",
115
+ href: linkMatch[2],
116
+ title: linkMatch[3],
117
+ children: parseInline(linkMatch[1])
118
+ });
119
+ remaining = remaining.slice(linkMatch[0].length);
120
+ continue;
121
+ }
122
+ const boldMatch = remaining.match(/^\*\*(.+?)\*\*|^__(.+?)__/);
123
+ if (boldMatch) {
124
+ const innerContent = boldMatch[1] ?? boldMatch[2];
125
+ if (innerContent !== void 0) {
126
+ tokens.push({
127
+ type: "bold",
128
+ children: parseInline(innerContent)
129
+ });
130
+ remaining = remaining.slice(boldMatch[0].length);
131
+ continue;
132
+ }
133
+ }
134
+ const strikeMatch = remaining.match(/^~~(.+?)~~/);
135
+ if (strikeMatch && strikeMatch[1] !== void 0) {
136
+ tokens.push({
137
+ type: "strikethrough",
138
+ children: parseInline(strikeMatch[1])
139
+ });
140
+ remaining = remaining.slice(strikeMatch[0].length);
141
+ continue;
142
+ }
143
+ const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
144
+ if (italicMatch) {
145
+ const innerContent = italicMatch[1] ?? italicMatch[2];
146
+ if (innerContent !== void 0) {
147
+ tokens.push({
148
+ type: "italic",
149
+ children: parseInline(innerContent)
150
+ });
151
+ remaining = remaining.slice(italicMatch[0].length);
152
+ continue;
153
+ }
154
+ }
155
+ const nextSpecial = findNextSpecialChar(remaining);
156
+ if (nextSpecial > 0) {
157
+ tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
158
+ remaining = remaining.slice(nextSpecial);
159
+ } else {
160
+ tokens.push({ type: "text", content: remaining });
161
+ remaining = "";
162
+ }
163
+ }
164
+ return mergeAdjacentText(tokens);
165
+ }
166
+ function findNextSpecialChar(content) {
167
+ const specialChars = ["`", "$", "!", "[", "*", "_", "~", "^"];
168
+ let minIndex = -1;
169
+ for (const char of specialChars) {
170
+ const index = content.indexOf(char);
171
+ if (index > 0 && (minIndex === -1 || index < minIndex)) {
172
+ minIndex = index;
173
+ }
174
+ }
175
+ return minIndex;
176
+ }
177
+ function mergeAdjacentText(tokens) {
178
+ const result = [];
179
+ for (const token of tokens) {
180
+ const last = result[result.length - 1];
181
+ if (token.type === "text" && last?.type === "text") {
182
+ last.content += token.content;
183
+ } else {
184
+ result.push(token);
185
+ }
186
+ }
187
+ return result;
188
+ }
189
+ var NcmContext = createContext(null);
190
+ function useNcmConfig() {
191
+ return useContext(NcmContext) ?? {};
192
+ }
193
+ function clipBounds(el) {
194
+ for (let node = el.parentElement; node; node = node.parentElement) {
195
+ const s = getComputedStyle(node);
196
+ if (/(auto|scroll|hidden)/.test(s.overflowX) || /(auto|scroll|hidden)/.test(s.overflowY)) {
197
+ const r = node.getBoundingClientRect();
198
+ return { left: r.left, right: r.right, top: r.top, bottom: r.bottom };
199
+ }
200
+ }
201
+ return { left: 0, right: window.innerWidth, top: 0, bottom: window.innerHeight };
202
+ }
203
+ function ReferenceMarker({ kind, number, children }) {
204
+ const config = useNcmConfig();
205
+ const popoverEnabled = config.inline?.referencePopover !== false && children != null;
206
+ const popoverId = useId();
207
+ const isRef = kind === "ref";
208
+ const popoverRef = useRef(null);
209
+ const positionPopover = useCallback(() => {
210
+ const el = popoverRef.current;
211
+ if (!el) return;
212
+ el.style.transform = "";
213
+ el.style.top = "";
214
+ el.style.bottom = "";
215
+ const margin = 8;
216
+ const bounds = clipBounds(el);
217
+ const rect = el.getBoundingClientRect();
218
+ if (rect.bottom > bounds.bottom - margin && rect.height < rect.top - bounds.top) {
219
+ el.style.top = "auto";
220
+ el.style.bottom = "1.6em";
221
+ }
222
+ let dx = 0;
223
+ if (rect.right > bounds.right - margin) dx = bounds.right - margin - rect.right;
224
+ if (rect.left + dx < bounds.left + margin) dx = bounds.left + margin - rect.left;
225
+ if (dx) el.style.transform = `translateX(${Math.round(dx)}px)`;
226
+ }, []);
227
+ const describedBy = popoverEnabled ? popoverId : void 0;
228
+ const label = `${isRef ? "Reference" : "Footnote"} ${number}`;
229
+ const marker = isRef ? /* @__PURE__ */ jsx(
230
+ "span",
231
+ {
232
+ "data-ncm-ref-marker": "",
233
+ tabIndex: 0,
234
+ role: "note",
235
+ "aria-label": label,
236
+ "aria-describedby": describedBy,
237
+ children: `[${number}]`
238
+ }
239
+ ) : /* @__PURE__ */ jsx(
240
+ "sup",
241
+ {
242
+ "data-ncm-ref-marker": "",
243
+ tabIndex: 0,
244
+ role: "note",
245
+ "aria-label": label,
246
+ "aria-describedby": describedBy,
247
+ children: number
248
+ }
249
+ );
250
+ return /* @__PURE__ */ jsxs(
251
+ "span",
252
+ {
253
+ "data-ncm-token": isRef ? "reference" : "footnote",
254
+ "data-ncm-ref-kind": kind,
255
+ "data-ncm-ref-number": number,
256
+ onMouseEnter: popoverEnabled ? positionPopover : void 0,
257
+ onFocus: popoverEnabled ? positionPopover : void 0,
258
+ children: [
259
+ marker,
260
+ popoverEnabled ? /* @__PURE__ */ jsx("span", { id: popoverId, ref: popoverRef, role: "tooltip", "data-ncm-ref-popover": "", children }) : null
261
+ ]
262
+ }
263
+ );
264
+ }
265
+ var ReferenceBasesContext = createContext(null);
266
+ var BlockReferenceScopeContext = createContext(null);
267
+ function BlockReferenceScope({ blockId, children }) {
268
+ const bases = useContext(ReferenceBasesContext);
269
+ const base = (blockId ? bases?.get(blockId) : void 0) ?? { ref: 0, footnote: 0 };
270
+ const counter = useRef({ ref: 0, footnote: 0 });
271
+ counter.current = { ref: 0, footnote: 0 };
272
+ const value = {
273
+ next(kind) {
274
+ counter.current[kind] += 1;
275
+ return base[kind] + counter.current[kind];
276
+ }
277
+ };
278
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
279
+ }
280
+ function useBlockReferenceScope() {
281
+ return useContext(BlockReferenceScopeContext);
282
+ }
283
+ var INERT_SCOPE = { next: () => 0 };
284
+ function InertReferenceScope({ children }) {
285
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
286
+ }
287
+ var katexPromise = null;
288
+ function loadKatex() {
289
+ if (!katexPromise) {
290
+ katexPromise = Promise.all([
291
+ import('katex'),
292
+ import('katex/dist/katex.min.css')
293
+ ]).then(([module]) => module.default).catch(() => null);
294
+ }
295
+ return katexPromise;
296
+ }
297
+ function useKatexHtml(content, displayMode, enabled = true) {
298
+ const [katexModule, setKatexModule] = useState(null);
299
+ useEffect(() => {
300
+ if (!enabled) {
301
+ return;
302
+ }
303
+ let active = true;
304
+ loadKatex().then((loaded) => {
305
+ if (active) {
306
+ setKatexModule(loaded);
307
+ }
308
+ });
309
+ return () => {
310
+ active = false;
311
+ };
312
+ }, [enabled]);
313
+ return useMemo(() => {
314
+ if (!enabled || !katexModule) {
315
+ return null;
316
+ }
317
+ try {
318
+ return katexModule.renderToString(content, {
319
+ throwOnError: false,
320
+ displayMode
321
+ });
322
+ } catch {
323
+ return null;
324
+ }
325
+ }, [content, displayMode, enabled, katexModule]);
326
+ }
327
+ function InlineContent({
328
+ content,
329
+ className,
330
+ disableBionic,
331
+ disableBeeline
332
+ }) {
333
+ const tokens = useMemo(() => parseInline(content), [content]);
334
+ const hasScope = useBlockReferenceScope() != null;
335
+ const rendered = tokens.map((token, index) => /* @__PURE__ */ jsx(
336
+ TokenRenderer,
337
+ {
338
+ token,
339
+ disableBionic,
340
+ disableBeeline
341
+ },
342
+ index
343
+ ));
344
+ const body = className ? /* @__PURE__ */ jsx("span", { "data-ncm-inline": "", className, children: rendered }) : /* @__PURE__ */ jsx(Fragment, { children: rendered });
345
+ return hasScope ? body : /* @__PURE__ */ jsx(BlockReferenceScope, { children: body });
346
+ }
347
+ function TokenRenderer({ token, disableBionic, disableBeeline }) {
348
+ const config = useNcmConfig();
349
+ const refScope = useBlockReferenceScope();
350
+ const bionicOn = !disableBionic && Boolean(config.reading?.bionic);
351
+ const beelineOn = !disableBeeline && Boolean(config.reading?.beeline);
352
+ const latexContent = token.type === "latex" ? token.content : "";
353
+ const latexHtml = useKatexHtml(latexContent, false, token.type === "latex");
354
+ switch (token.type) {
355
+ case "text":
356
+ if (bionicOn || beelineOn) {
357
+ return renderReadingText(token.content, {
358
+ bionic: bionicOn,
359
+ bionicRatio: config.reading?.bionicRatio,
360
+ beeline: beelineOn
361
+ });
362
+ }
363
+ return /* @__PURE__ */ jsx(Fragment, { children: token.content });
364
+ case "bold":
365
+ return /* @__PURE__ */ jsx("strong", { "data-ncm-token": "bold", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
366
+ TokenRenderer,
367
+ {
368
+ token: child,
369
+ disableBionic,
370
+ disableBeeline
371
+ },
372
+ i
373
+ )) });
374
+ case "italic":
375
+ return /* @__PURE__ */ jsx("em", { "data-ncm-token": "italic", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
376
+ TokenRenderer,
377
+ {
378
+ token: child,
379
+ disableBionic,
380
+ disableBeeline
381
+ },
382
+ i
383
+ )) });
384
+ case "code":
385
+ return /* @__PURE__ */ jsx("code", { "data-ncm-token": "code", children: token.content });
386
+ case "link": {
387
+ const handleClick = (e) => {
388
+ config.inline?.onLinkClick?.(token.href, e);
389
+ };
390
+ return /* @__PURE__ */ jsx(
391
+ "a",
392
+ {
393
+ "data-ncm-token": "link",
394
+ href: token.href,
395
+ title: token.title,
396
+ onClick: handleClick,
397
+ children: token.children.map((child, i) => /* @__PURE__ */ jsx(
398
+ TokenRenderer,
399
+ {
400
+ token: child,
401
+ disableBionic,
402
+ disableBeeline
403
+ },
404
+ i
405
+ ))
406
+ }
407
+ );
408
+ }
409
+ case "wiki_link": {
410
+ const result = config.mesh?.resolveLink(token.target) ?? {
411
+ status: "missing",
412
+ target: token.target,
413
+ resolved: null,
414
+ candidates: []
415
+ };
416
+ const href = config.inline?.resolveWikiLinkHref?.(token.target, result) ?? null;
417
+ const label = token.display ?? token.target;
418
+ if (href) {
419
+ const handleClick = (e) => {
420
+ config.inline?.onWikiLinkClick?.(token.target, result, e);
421
+ };
422
+ return /* @__PURE__ */ jsx(
423
+ "a",
424
+ {
425
+ "data-ncm-token": "wiki_link",
426
+ "data-ncm-wikilink-status": result.status,
427
+ href,
428
+ onClick: handleClick,
429
+ children: label
430
+ }
431
+ );
432
+ }
433
+ if (config.inline?.onWikiLinkClick) {
434
+ const handleClick = (e) => {
435
+ config.inline?.onWikiLinkClick?.(token.target, result, e);
436
+ };
437
+ return /* @__PURE__ */ jsx(
438
+ "button",
439
+ {
440
+ type: "button",
441
+ "data-ncm-token": "wiki_link",
442
+ "data-ncm-wikilink-status": result.status,
443
+ onClick: handleClick,
444
+ children: label
445
+ }
446
+ );
447
+ }
448
+ return /* @__PURE__ */ jsx("span", { "data-ncm-token": "wiki_link", "data-ncm-wikilink-status": result.status, children: label });
449
+ }
450
+ case "latex": {
451
+ const CustomRenderer = config.inline?.customLatexRenderer;
452
+ if (CustomRenderer) {
453
+ return /* @__PURE__ */ jsx(CustomRenderer, { content: token.content, display: false });
454
+ }
455
+ if (latexHtml) {
456
+ return /* @__PURE__ */ jsx("span", { "data-ncm-token": "latex", dangerouslySetInnerHTML: { __html: latexHtml } });
457
+ }
458
+ return /* @__PURE__ */ jsx("code", { "data-ncm-token": "latex", children: token.content });
459
+ }
460
+ case "strikethrough":
461
+ return /* @__PURE__ */ jsx("del", { "data-ncm-token": "strikethrough", children: token.children.map((child, i) => /* @__PURE__ */ jsx(
462
+ TokenRenderer,
463
+ {
464
+ token: child,
465
+ disableBionic,
466
+ disableBeeline
467
+ },
468
+ i
469
+ )) });
470
+ case "image": {
471
+ const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
472
+ return /* @__PURE__ */ jsx(
473
+ "img",
474
+ {
475
+ "data-ncm-token": "image",
476
+ src,
477
+ alt: token.alt,
478
+ title: token.title
479
+ }
480
+ );
481
+ }
482
+ case "wiki_embed": {
483
+ const extension = extractExtension(token.target);
484
+ const embedType = embedTypeFromExtension(extension);
485
+ const result = config.mesh?.resolveEmbed(token.target) ?? null;
486
+ const url = config.embeddings?.resolveUrl?.(token.target, embedType) ?? token.target;
487
+ if (result?.status === "missing") {
488
+ return /* @__PURE__ */ jsx(
489
+ "span",
490
+ {
491
+ "data-ncm-token": "wiki_embed",
492
+ "data-ncm-wikiembed-status": "missing",
493
+ children: `![[${token.target}]]`
494
+ }
495
+ );
496
+ }
497
+ if (result?.status === "ambiguous") {
498
+ return /* @__PURE__ */ jsx(
499
+ "span",
500
+ {
501
+ "data-ncm-token": "wiki_embed",
502
+ "data-ncm-wikiembed-status": "ambiguous",
503
+ children: `![[${token.target}]]`
504
+ }
505
+ );
506
+ }
507
+ if (embedType === "image") {
508
+ return /* @__PURE__ */ jsx(
509
+ "img",
510
+ {
511
+ "data-ncm-token": "wiki_embed",
512
+ "data-ncm-wikiembed-type": embedType,
513
+ src: url,
514
+ alt: token.display ?? token.target,
515
+ className: config.embeddings?.imageClassName
516
+ }
517
+ );
518
+ }
519
+ if (embedType === "video") {
520
+ return /* @__PURE__ */ jsx(
521
+ "video",
522
+ {
523
+ "data-ncm-token": "wiki_embed",
524
+ "data-ncm-wikiembed-type": embedType,
525
+ src: url,
526
+ controls: true,
527
+ className: config.embeddings?.videoClassName
528
+ }
529
+ );
530
+ }
531
+ if (embedType === "audio") {
532
+ return /* @__PURE__ */ jsx(
533
+ "audio",
534
+ {
535
+ "data-ncm-token": "wiki_embed",
536
+ "data-ncm-wikiembed-type": embedType,
537
+ src: url,
538
+ controls: true,
539
+ className: config.embeddings?.audioClassName
540
+ }
541
+ );
542
+ }
543
+ return /* @__PURE__ */ jsx(
544
+ "a",
545
+ {
546
+ "data-ncm-token": "wiki_embed",
547
+ "data-ncm-wikiembed-type": embedType,
548
+ href: url,
549
+ children: token.display ?? token.target
550
+ }
551
+ );
552
+ }
553
+ case "inline_ref": {
554
+ const number = refScope?.next(token.kind) ?? 0;
555
+ 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 });
556
+ }
557
+ default:
558
+ return null;
559
+ }
560
+ }
561
+ function renderReadingText(content, opts) {
562
+ if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
563
+ const { bionic = false, beeline = false } = opts;
564
+ if (!bionic && !beeline) return /* @__PURE__ */ jsx(Fragment, { children: content });
565
+ const ratio = Math.min(1, Math.max(0.05, opts.bionicRatio ?? 0.5));
566
+ const pieces = [];
567
+ const regex = /[\p{L}\p{N}][\p{L}\p{N}\p{M}'’-]*/gu;
568
+ let match;
569
+ let key = 0;
570
+ let cursor = 0;
571
+ while ((match = regex.exec(content)) !== null) {
572
+ if (match.index > cursor) pieces.push(content.slice(cursor, match.index));
573
+ const segment = match[0];
574
+ const wrapperProps = {};
575
+ if (bionic) wrapperProps["data-ncm-bionic"] = "";
576
+ if (beeline) wrapperProps["data-ncm-beeline-word"] = "";
577
+ if (bionic) {
578
+ const headLen = Math.max(1, Math.ceil(segment.length * ratio));
579
+ pieces.push(
580
+ /* @__PURE__ */ jsxs("span", { ...wrapperProps, children: [
581
+ /* @__PURE__ */ jsx("span", { "data-ncm-bionic-bold": "", style: { fontWeight: 600 }, children: segment.slice(0, headLen) }),
582
+ segment.slice(headLen)
583
+ ] }, key++)
584
+ );
585
+ } else {
586
+ pieces.push(
587
+ /* @__PURE__ */ jsx("span", { ...wrapperProps, children: segment }, key++)
588
+ );
589
+ }
590
+ cursor = match.index + segment.length;
591
+ }
592
+ if (cursor < content.length) pieces.push(content.slice(cursor));
593
+ return /* @__PURE__ */ jsx(Fragment, { children: pieces });
594
+ }
595
+ function cn(...inputs) {
596
+ return twMerge(clsx(inputs));
597
+ }
598
+ function blockDataAttributes(block) {
599
+ return {
600
+ "data-ncm-block": block.id,
601
+ "data-ncm-stable": block.stableId,
602
+ "data-ncm-type": block.type,
603
+ "data-block-id": block.id
604
+ };
605
+ }
606
+ function BlockShell({
607
+ as = "div",
608
+ block,
609
+ children,
610
+ ...props
611
+ }) {
612
+ return createElement(as, {
613
+ ...blockDataAttributes(block),
614
+ ...props
615
+ }, children);
616
+ }
617
+ function FigureBlock({ block, className }) {
618
+ const { embed, caption, number } = block;
619
+ return /* @__PURE__ */ jsxs(
620
+ BlockShell,
621
+ {
622
+ as: "figure",
623
+ block,
624
+ "data-ncm-figure": "",
625
+ className: cn("space-y-2", className),
626
+ children: [
627
+ embed.embedType === "image" ? /* @__PURE__ */ jsx("img", { src: embed.src, alt: embed.alt, title: embed.title ?? void 0 }) : /* @__PURE__ */ jsx(
628
+ "a",
629
+ {
630
+ href: embed.src,
631
+ title: embed.title ?? void 0,
632
+ "data-ncm-embed-type": embed.embedType,
633
+ children: embed.alt || embed.src
634
+ }
635
+ ),
636
+ /* @__PURE__ */ jsxs(
637
+ "figcaption",
638
+ {
639
+ className: "text-sm text-muted-foreground",
640
+ "data-ncm-figure-number": number,
641
+ children: [
642
+ typeof number === "number" ? /* @__PURE__ */ jsxs("span", { "data-ncm-figure-label": "", children: [
643
+ "Figure ",
644
+ number,
645
+ ". "
646
+ ] }) : null,
647
+ /* @__PURE__ */ jsx(InlineContent, { content: serializeInlineContent(caption.content) })
648
+ ]
649
+ }
650
+ )
651
+ ]
652
+ }
653
+ );
654
+ }
655
+
656
+ export { FigureBlock };
@@ -0,0 +1,13 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { FootnoteBlock as FootnoteBlock$1 } from '@nuucognition/ncm';
3
+ import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
4
+ import 'react';
5
+
6
+ type FootnoteBlockProps = BlockRendererProps<FootnoteBlock$1>;
7
+ /**
8
+ * Footnote-definition renderer. Anchored by its `fn-{label}` stable id so inline
9
+ * footnote references can link to it. Content renders through `NcmBlock`.
10
+ */
11
+ declare function FootnoteBlock({ block, className }: FootnoteBlockProps): react_jsx_runtime.JSX.Element;
12
+
13
+ export { FootnoteBlock, type FootnoteBlockProps };