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