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