@nuucognition/ncm-ui 0.1.1-beta.0 → 0.1.1-beta.2

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 (39) hide show
  1. package/dist/blocks/admonition/index.js +118 -46
  2. package/dist/blocks/aside/index.js +118 -46
  3. package/dist/blocks/blockquote/index.d.ts +7 -5
  4. package/dist/blocks/blockquote/index.js +1218 -36
  5. package/dist/blocks/chart/index.js +2 -1
  6. package/dist/blocks/container/index.js +72 -31
  7. package/dist/blocks/custom-code/index.js +1 -1
  8. package/dist/blocks/dataview/index.js +2 -1
  9. package/dist/blocks/definition/index.js +117 -45
  10. package/dist/blocks/embedding/index.js +72 -31
  11. package/dist/blocks/figure/index.js +72 -31
  12. package/dist/blocks/footnote/index.js +118 -46
  13. package/dist/blocks/header/index.js +72 -31
  14. package/dist/blocks/html/index.js +2 -1
  15. package/dist/blocks/index.js +118 -46
  16. package/dist/blocks/latex/index.js +2 -2
  17. package/dist/blocks/list/index.js +72 -31
  18. package/dist/blocks/math/index.js +3 -2
  19. package/dist/blocks/mermaid/index.js +2 -1
  20. package/dist/blocks/paragraph/index.js +72 -31
  21. package/dist/blocks/spoiler/index.js +118 -46
  22. package/dist/blocks/table/index.js +73 -32
  23. package/dist/blocks/task-list/index.js +72 -31
  24. package/dist/components/index.js +157 -65
  25. package/dist/components/ncm-block.js +118 -46
  26. package/dist/components/ncm-document.js +157 -65
  27. package/dist/context/index.d.ts +1 -1
  28. package/dist/context/index.js +119 -44
  29. package/dist/hooks/index.js +118 -46
  30. package/dist/hooks/use-block-renderer.js +118 -46
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +164 -58
  33. package/dist/inline/index.d.ts +2 -3
  34. package/dist/inline/index.js +72 -31
  35. package/dist/lib/defaults.js +118 -46
  36. package/dist/references-BM-lvGrq.d.ts +99 -0
  37. package/dist/styles/nuu.css +39 -16
  38. package/package.json +3 -4
  39. package/dist/references-BYW5pnj_.d.ts +0 -63
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { createContext, useState, createElement, useMemo, useContext, useCallback, useEffect, useRef, Component, useId } from 'react';
2
+ import { createContext, useMemo, useState, createElement, useContext, useCallback, useEffect, useRef, Component, useId } from 'react';
3
3
  import { clsx } from 'clsx';
4
4
  import { twMerge } from 'tailwind-merge';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
+ import { serializeInlineContent, sanitizeHtml, isTypedNestedList, parseNcm } from '@nuucognition/ncm';
6
7
  import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
7
- import { serializeInlineContent, sanitizeHtml, isTypedNestedList } from '@nuucognition/ncm';
8
8
 
9
9
  // src/components/block-shell.tsx
10
10
  function cn(...inputs) {
@@ -84,6 +84,52 @@ function tryParseInlineRef(input) {
84
84
  }
85
85
  return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
86
86
  }
87
+ function runLength(input, index, char) {
88
+ let end = index;
89
+ while (end < input.length && input[end] === char) end++;
90
+ return end - index;
91
+ }
92
+ function tryParseEmphasis(input) {
93
+ const char = input[0];
94
+ if (char !== "*" && char !== "_") return null;
95
+ const open = Math.min(3, runLength(input, 0, char));
96
+ const need = open;
97
+ let i = open;
98
+ while (i < input.length) {
99
+ const ch = input[i];
100
+ if (ch === "`") {
101
+ const close = input.indexOf("`", i + 1);
102
+ if (close === -1) break;
103
+ i = close + 1;
104
+ continue;
105
+ }
106
+ if (ch !== char) {
107
+ i++;
108
+ continue;
109
+ }
110
+ const run = runLength(input, i, char);
111
+ const closes = need === 1 ? run % 2 === 1 : run >= need;
112
+ if (!closes) {
113
+ i += run;
114
+ continue;
115
+ }
116
+ const extra = run - need;
117
+ const inner = input.slice(open, i + extra);
118
+ if (inner.length === 0) return null;
119
+ const length = i + run;
120
+ const children = parseInline(inner);
121
+ let token;
122
+ if (need === 3) {
123
+ token = { type: "bold", children: [{ type: "italic", children }] };
124
+ } else if (need === 2) {
125
+ token = { type: "bold", children };
126
+ } else {
127
+ token = { type: "italic", children };
128
+ }
129
+ return { token, length };
130
+ }
131
+ return null;
132
+ }
87
133
  function parseInline(content) {
88
134
  if (!content) return [];
89
135
  const tokens = [];
@@ -155,17 +201,11 @@ function parseInline(content) {
155
201
  remaining = remaining.slice(linkMatch[0].length);
156
202
  continue;
157
203
  }
158
- const boldMatch = remaining.match(/^\*\*(.+?)\*\*|^__(.+?)__/);
159
- if (boldMatch) {
160
- const innerContent = boldMatch[1] ?? boldMatch[2];
161
- if (innerContent !== void 0) {
162
- tokens.push({
163
- type: "bold",
164
- children: parseInline(innerContent)
165
- });
166
- remaining = remaining.slice(boldMatch[0].length);
167
- continue;
168
- }
204
+ const emphasis = tryParseEmphasis(remaining);
205
+ if (emphasis) {
206
+ tokens.push(emphasis.token);
207
+ remaining = remaining.slice(emphasis.length);
208
+ continue;
169
209
  }
170
210
  const strikeMatch = remaining.match(/^~~(.+?)~~/);
171
211
  if (strikeMatch && strikeMatch[1] !== void 0) {
@@ -176,18 +216,6 @@ function parseInline(content) {
176
216
  remaining = remaining.slice(strikeMatch[0].length);
177
217
  continue;
178
218
  }
179
- const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
180
- if (italicMatch) {
181
- const innerContent = italicMatch[1] ?? italicMatch[2];
182
- if (innerContent !== void 0) {
183
- tokens.push({
184
- type: "italic",
185
- children: parseInline(innerContent)
186
- });
187
- remaining = remaining.slice(italicMatch[0].length);
188
- continue;
189
- }
190
- }
191
219
  const nextSpecial = findNextSpecialChar(remaining);
192
220
  if (nextSpecial > 0) {
193
221
  tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
@@ -298,17 +326,30 @@ function ReferenceMarker({ kind, number, children }) {
298
326
  }
299
327
  );
300
328
  }
301
- var ReferenceBasesContext = createContext(null);
329
+ function normalizeReferenceContent(content) {
330
+ return content.replace(/\s+/g, " ").trim().toLowerCase();
331
+ }
332
+ var ReferenceNumberingContext = createContext(null);
302
333
  var BlockReferenceScopeContext = createContext(null);
303
- function BlockReferenceScope({ blockId, children }) {
304
- const bases = useContext(ReferenceBasesContext);
305
- const base = (blockId ? bases?.get(blockId) : void 0) ?? { ref: 0, footnote: 0 };
334
+ function BlockReferenceScope({ children }) {
335
+ const numbering = useContext(ReferenceNumberingContext);
336
+ const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
306
337
  const counter = useRef({ ref: 0, footnote: 0 });
307
- counter.current = { ref: 0, footnote: 0 };
308
338
  const value = {
339
+ numberFor(kind, content) {
340
+ const key = normalizeReferenceContent(content);
341
+ const fromDocument = numbering?.[kind].get(key);
342
+ if (fromDocument !== void 0) return fromDocument;
343
+ const map = local.current[kind];
344
+ const existing = map.get(key);
345
+ if (existing !== void 0) return existing;
346
+ counter.current[kind] += 1;
347
+ map.set(key, counter.current[kind]);
348
+ return counter.current[kind];
349
+ },
309
350
  next(kind) {
310
351
  counter.current[kind] += 1;
311
- return base[kind] + counter.current[kind];
352
+ return counter.current[kind];
312
353
  }
313
354
  };
314
355
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
@@ -316,7 +357,7 @@ function BlockReferenceScope({ blockId, children }) {
316
357
  function useBlockReferenceScope() {
317
358
  return useContext(BlockReferenceScopeContext);
318
359
  }
319
- var INERT_SCOPE = { next: () => 0 };
360
+ var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
320
361
  function InertReferenceScope({ children }) {
321
362
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
322
363
  }
@@ -607,7 +648,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
607
648
  );
608
649
  }
609
650
  case "inline_ref": {
610
- const number = refScope?.next(token.kind) ?? 0;
651
+ const number = refScope?.numberFor(token.kind, token.content) ?? 0;
611
652
  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 });
612
653
  }
613
654
  default:
@@ -673,8 +714,32 @@ function renderReadingText(content, opts) {
673
714
  if (cursor < content.length) pieces.push(content.slice(cursor));
674
715
  return /* @__PURE__ */ jsx(Fragment, { children: pieces });
675
716
  }
717
+ function quoteBlocks(block) {
718
+ try {
719
+ const doc = parseNcm(block.content, {
720
+ preset: "ncm-full",
721
+ allowMissingFrontmatter: true,
722
+ // Attribution off, as the NUU Editor's bridge keeps it: the promoter's
723
+ // trigger is any last quote line starting with `-`, so a nested quote
724
+ // ending in a list item would lose that item to a `— Author` line.
725
+ blockOptions: { extensions: { attribution: false } }
726
+ });
727
+ const blocks = doc.blocks ?? [];
728
+ if (blocks.length === 0 || blocks.some((child) => child.type === "frontmatter")) {
729
+ return null;
730
+ }
731
+ return blocks.map((child, index) => ({ ...child, id: `${block.id}.${index + 1}`, stableId: void 0 }));
732
+ } catch {
733
+ return null;
734
+ }
735
+ }
736
+ function QuotedLines({ content }) {
737
+ const lines = content.split("\n");
738
+ return /* @__PURE__ */ jsx(Fragment, { children: lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index)) });
739
+ }
676
740
  function BlockquoteBlock({ block, className }) {
677
- const lines = block.content.split("\n");
741
+ const multiline = block.content.includes("\n");
742
+ const blocks = useMemo(() => multiline ? quoteBlocks(block) : null, [block, multiline]);
678
743
  return /* @__PURE__ */ jsx(
679
744
  "blockquote",
680
745
  {
@@ -684,7 +749,9 @@ function BlockquoteBlock({ block, className }) {
684
749
  "data-block-id": block.id,
685
750
  "data-ncm-blockquote": "",
686
751
  className,
687
- children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index))
752
+ children: !multiline ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : blocks === null ? /* @__PURE__ */ jsx(QuotedLines, { content: block.content }) : blocks.map(
753
+ (child) => child.type === "paragraph" ? /* @__PURE__ */ jsx(QuotedLines, { content: child.content ?? "" }, blockKey(child)) : /* @__PURE__ */ jsx(NcmBlock, { block: child }, blockKey(child))
754
+ )
688
755
  }
689
756
  );
690
757
  }
@@ -699,7 +766,8 @@ function ChartBlock({ block, className }) {
699
766
  "data-ncm-chart": "",
700
767
  "data-ncm-chart-type": block.chartType ?? "unknown",
701
768
  className: cn(
702
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
769
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
770
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
703
771
  className
704
772
  ),
705
773
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -879,7 +947,8 @@ function DataviewBlock({ block, className }) {
879
947
  "data-ncm-dataview": "",
880
948
  "data-ncm-query-type": block.queryType,
881
949
  className: cn(
882
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
950
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
951
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
883
952
  className
884
953
  ),
885
954
  children: /* @__PURE__ */ jsx("code", { children: block.query })
@@ -1218,7 +1287,8 @@ function HtmlBlock({ block, className }) {
1218
1287
  "data-block-id": block.id,
1219
1288
  "data-ncm-html": "",
1220
1289
  className: cn(
1221
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1290
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
1291
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1222
1292
  className
1223
1293
  ),
1224
1294
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -1279,7 +1349,7 @@ function LatexDisplayBlock({ block, className }) {
1279
1349
  "data-ncm-type": block.type,
1280
1350
  "data-block-id": block.id,
1281
1351
  "data-ncm-latex-display": "",
1282
- className: cn("overflow-x-auto", className),
1352
+ className: cn("overflow-x-auto overflow-y-hidden", className),
1283
1353
  dangerouslySetInnerHTML: { __html: html }
1284
1354
  }
1285
1355
  );
@@ -1294,7 +1364,7 @@ function LatexDisplayBlock({ block, className }) {
1294
1364
  "data-ncm-type": block.type,
1295
1365
  "data-block-id": block.id,
1296
1366
  "data-ncm-latex-display": "",
1297
- className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
1367
+ className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
1298
1368
  children: /* @__PURE__ */ jsx("code", { children: block.content })
1299
1369
  }
1300
1370
  );
@@ -1414,7 +1484,7 @@ function MathBlock({ block, className }) {
1414
1484
  "data-ncm-type": block.type,
1415
1485
  "data-block-id": block.id,
1416
1486
  "data-ncm-math": "",
1417
- className: cn("overflow-x-auto", className),
1487
+ className: cn("overflow-x-auto overflow-y-hidden", className),
1418
1488
  dangerouslySetInnerHTML: { __html: html }
1419
1489
  }
1420
1490
  );
@@ -1430,7 +1500,8 @@ function MathBlock({ block, className }) {
1430
1500
  "data-block-id": block.id,
1431
1501
  "data-ncm-math": "",
1432
1502
  className: cn(
1433
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1503
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
1504
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1434
1505
  className
1435
1506
  ),
1436
1507
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -1448,7 +1519,8 @@ function MermaidBlock({ block, className }) {
1448
1519
  "data-ncm-mermaid": "",
1449
1520
  "data-ncm-diagram-type": block.diagramType,
1450
1521
  className: cn(
1451
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1522
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
1523
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1452
1524
  className
1453
1525
  ),
1454
1526
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -1509,7 +1581,7 @@ function TableBlock({ block, className }) {
1509
1581
  "data-ncm-type": block.type,
1510
1582
  "data-block-id": block.id,
1511
1583
  "data-ncm-table": "",
1512
- className: cn("w-full overflow-x-auto", className),
1584
+ className: cn("w-full overflow-x-auto overflow-y-hidden", className),
1513
1585
  children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
1514
1586
  /* @__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)) }) }),
1515
1587
  /* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
@@ -1595,7 +1667,7 @@ function FallbackBlock({ block, className }) {
1595
1667
  "data-block-id": block.id,
1596
1668
  "data-ncm-fallback": "",
1597
1669
  className: cn(
1598
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1670
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
1599
1671
  className
1600
1672
  )
1601
1673
  },
@@ -1651,7 +1723,7 @@ function CustomCodeBlock({ block, className }) {
1651
1723
  "data-block-id": block.id,
1652
1724
  "data-ncm-custom-code": "",
1653
1725
  "data-ncm-language": block.language,
1654
- className: cn("overflow-x-auto", className),
1726
+ className: cn("overflow-x-auto overflow-y-hidden", className),
1655
1727
  children: [
1656
1728
  /* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
1657
1729
  /* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
@@ -83,7 +83,7 @@ function LatexDisplayBlock({ block, className }) {
83
83
  "data-ncm-type": block.type,
84
84
  "data-block-id": block.id,
85
85
  "data-ncm-latex-display": "",
86
- className: cn("overflow-x-auto", className),
86
+ className: cn("overflow-x-auto overflow-y-hidden", className),
87
87
  dangerouslySetInnerHTML: { __html: html }
88
88
  }
89
89
  );
@@ -98,7 +98,7 @@ function LatexDisplayBlock({ block, className }) {
98
98
  "data-ncm-type": block.type,
99
99
  "data-block-id": block.id,
100
100
  "data-ncm-latex-display": "",
101
- className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
101
+ className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
102
102
  children: /* @__PURE__ */ jsx("code", { children: block.content })
103
103
  }
104
104
  );
@@ -46,6 +46,52 @@ function tryParseInlineRef(input) {
46
46
  }
47
47
  return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
48
48
  }
49
+ function runLength(input, index, char) {
50
+ let end = index;
51
+ while (end < input.length && input[end] === char) end++;
52
+ return end - index;
53
+ }
54
+ function tryParseEmphasis(input) {
55
+ const char = input[0];
56
+ if (char !== "*" && char !== "_") return null;
57
+ const open = Math.min(3, runLength(input, 0, char));
58
+ const need = open;
59
+ let i = open;
60
+ while (i < input.length) {
61
+ const ch = input[i];
62
+ if (ch === "`") {
63
+ const close = input.indexOf("`", i + 1);
64
+ if (close === -1) break;
65
+ i = close + 1;
66
+ continue;
67
+ }
68
+ if (ch !== char) {
69
+ i++;
70
+ continue;
71
+ }
72
+ const run = runLength(input, i, char);
73
+ const closes = need === 1 ? run % 2 === 1 : run >= need;
74
+ if (!closes) {
75
+ i += run;
76
+ continue;
77
+ }
78
+ const extra = run - need;
79
+ const inner = input.slice(open, i + extra);
80
+ if (inner.length === 0) return null;
81
+ const length = i + run;
82
+ const children = parseInline(inner);
83
+ let token;
84
+ if (need === 3) {
85
+ token = { type: "bold", children: [{ type: "italic", children }] };
86
+ } else if (need === 2) {
87
+ token = { type: "bold", children };
88
+ } else {
89
+ token = { type: "italic", children };
90
+ }
91
+ return { token, length };
92
+ }
93
+ return null;
94
+ }
49
95
  function parseInline(content) {
50
96
  if (!content) return [];
51
97
  const tokens = [];
@@ -117,17 +163,11 @@ function parseInline(content) {
117
163
  remaining = remaining.slice(linkMatch[0].length);
118
164
  continue;
119
165
  }
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
- }
166
+ const emphasis = tryParseEmphasis(remaining);
167
+ if (emphasis) {
168
+ tokens.push(emphasis.token);
169
+ remaining = remaining.slice(emphasis.length);
170
+ continue;
131
171
  }
132
172
  const strikeMatch = remaining.match(/^~~(.+?)~~/);
133
173
  if (strikeMatch && strikeMatch[1] !== void 0) {
@@ -138,18 +178,6 @@ function parseInline(content) {
138
178
  remaining = remaining.slice(strikeMatch[0].length);
139
179
  continue;
140
180
  }
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
181
  const nextSpecial = findNextSpecialChar(remaining);
154
182
  if (nextSpecial > 0) {
155
183
  tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
@@ -260,17 +288,30 @@ function ReferenceMarker({ kind, number, children }) {
260
288
  }
261
289
  );
262
290
  }
263
- var ReferenceBasesContext = createContext(null);
291
+ function normalizeReferenceContent(content) {
292
+ return content.replace(/\s+/g, " ").trim().toLowerCase();
293
+ }
294
+ var ReferenceNumberingContext = createContext(null);
264
295
  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 };
296
+ function BlockReferenceScope({ children }) {
297
+ const numbering = useContext(ReferenceNumberingContext);
298
+ const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
268
299
  const counter = useRef({ ref: 0, footnote: 0 });
269
- counter.current = { ref: 0, footnote: 0 };
270
300
  const value = {
301
+ numberFor(kind, content) {
302
+ const key = normalizeReferenceContent(content);
303
+ const fromDocument = numbering?.[kind].get(key);
304
+ if (fromDocument !== void 0) return fromDocument;
305
+ const map = local.current[kind];
306
+ const existing = map.get(key);
307
+ if (existing !== void 0) return existing;
308
+ counter.current[kind] += 1;
309
+ map.set(key, counter.current[kind]);
310
+ return counter.current[kind];
311
+ },
271
312
  next(kind) {
272
313
  counter.current[kind] += 1;
273
- return base[kind] + counter.current[kind];
314
+ return counter.current[kind];
274
315
  }
275
316
  };
276
317
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
@@ -278,7 +319,7 @@ function BlockReferenceScope({ blockId, children }) {
278
319
  function useBlockReferenceScope() {
279
320
  return useContext(BlockReferenceScopeContext);
280
321
  }
281
- var INERT_SCOPE = { next: () => 0 };
322
+ var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
282
323
  function InertReferenceScope({ children }) {
283
324
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
284
325
  }
@@ -569,7 +610,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
569
610
  );
570
611
  }
571
612
  case "inline_ref": {
572
- const number = refScope?.next(token.kind) ?? 0;
613
+ const number = refScope?.numberFor(token.kind, token.content) ?? 0;
573
614
  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 });
574
615
  }
575
616
  default:
@@ -61,7 +61,7 @@ function MathBlock({ block, className }) {
61
61
  "data-ncm-type": block.type,
62
62
  "data-block-id": block.id,
63
63
  "data-ncm-math": "",
64
- className: cn("overflow-x-auto", className),
64
+ className: cn("overflow-x-auto overflow-y-hidden", className),
65
65
  dangerouslySetInnerHTML: { __html: html }
66
66
  }
67
67
  );
@@ -77,7 +77,8 @@ function MathBlock({ block, className }) {
77
77
  "data-block-id": block.id,
78
78
  "data-ncm-math": "",
79
79
  className: cn(
80
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
80
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
81
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
81
82
  className
82
83
  ),
83
84
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -18,7 +18,8 @@ function MermaidBlock({ block, className }) {
18
18
  "data-ncm-mermaid": "",
19
19
  "data-ncm-diagram-type": block.diagramType,
20
20
  className: cn(
21
- "overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
21
+ // `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
22
+ "overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
22
23
  className
23
24
  ),
24
25
  children: /* @__PURE__ */ jsx("code", { children: block.content })
@@ -46,6 +46,52 @@ function tryParseInlineRef(input) {
46
46
  }
47
47
  return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
48
48
  }
49
+ function runLength(input, index, char) {
50
+ let end = index;
51
+ while (end < input.length && input[end] === char) end++;
52
+ return end - index;
53
+ }
54
+ function tryParseEmphasis(input) {
55
+ const char = input[0];
56
+ if (char !== "*" && char !== "_") return null;
57
+ const open = Math.min(3, runLength(input, 0, char));
58
+ const need = open;
59
+ let i = open;
60
+ while (i < input.length) {
61
+ const ch = input[i];
62
+ if (ch === "`") {
63
+ const close = input.indexOf("`", i + 1);
64
+ if (close === -1) break;
65
+ i = close + 1;
66
+ continue;
67
+ }
68
+ if (ch !== char) {
69
+ i++;
70
+ continue;
71
+ }
72
+ const run = runLength(input, i, char);
73
+ const closes = need === 1 ? run % 2 === 1 : run >= need;
74
+ if (!closes) {
75
+ i += run;
76
+ continue;
77
+ }
78
+ const extra = run - need;
79
+ const inner = input.slice(open, i + extra);
80
+ if (inner.length === 0) return null;
81
+ const length = i + run;
82
+ const children = parseInline(inner);
83
+ let token;
84
+ if (need === 3) {
85
+ token = { type: "bold", children: [{ type: "italic", children }] };
86
+ } else if (need === 2) {
87
+ token = { type: "bold", children };
88
+ } else {
89
+ token = { type: "italic", children };
90
+ }
91
+ return { token, length };
92
+ }
93
+ return null;
94
+ }
49
95
  function parseInline(content) {
50
96
  if (!content) return [];
51
97
  const tokens = [];
@@ -117,17 +163,11 @@ function parseInline(content) {
117
163
  remaining = remaining.slice(linkMatch[0].length);
118
164
  continue;
119
165
  }
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
- }
166
+ const emphasis = tryParseEmphasis(remaining);
167
+ if (emphasis) {
168
+ tokens.push(emphasis.token);
169
+ remaining = remaining.slice(emphasis.length);
170
+ continue;
131
171
  }
132
172
  const strikeMatch = remaining.match(/^~~(.+?)~~/);
133
173
  if (strikeMatch && strikeMatch[1] !== void 0) {
@@ -138,18 +178,6 @@ function parseInline(content) {
138
178
  remaining = remaining.slice(strikeMatch[0].length);
139
179
  continue;
140
180
  }
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
181
  const nextSpecial = findNextSpecialChar(remaining);
154
182
  if (nextSpecial > 0) {
155
183
  tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
@@ -260,17 +288,30 @@ function ReferenceMarker({ kind, number, children }) {
260
288
  }
261
289
  );
262
290
  }
263
- var ReferenceBasesContext = createContext(null);
291
+ function normalizeReferenceContent(content) {
292
+ return content.replace(/\s+/g, " ").trim().toLowerCase();
293
+ }
294
+ var ReferenceNumberingContext = createContext(null);
264
295
  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 };
296
+ function BlockReferenceScope({ children }) {
297
+ const numbering = useContext(ReferenceNumberingContext);
298
+ const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
268
299
  const counter = useRef({ ref: 0, footnote: 0 });
269
- counter.current = { ref: 0, footnote: 0 };
270
300
  const value = {
301
+ numberFor(kind, content) {
302
+ const key = normalizeReferenceContent(content);
303
+ const fromDocument = numbering?.[kind].get(key);
304
+ if (fromDocument !== void 0) return fromDocument;
305
+ const map = local.current[kind];
306
+ const existing = map.get(key);
307
+ if (existing !== void 0) return existing;
308
+ counter.current[kind] += 1;
309
+ map.set(key, counter.current[kind]);
310
+ return counter.current[kind];
311
+ },
271
312
  next(kind) {
272
313
  counter.current[kind] += 1;
273
- return base[kind] + counter.current[kind];
314
+ return counter.current[kind];
274
315
  }
275
316
  };
276
317
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
@@ -278,7 +319,7 @@ function BlockReferenceScope({ blockId, children }) {
278
319
  function useBlockReferenceScope() {
279
320
  return useContext(BlockReferenceScopeContext);
280
321
  }
281
- var INERT_SCOPE = { next: () => 0 };
322
+ var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
282
323
  function InertReferenceScope({ children }) {
283
324
  return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
284
325
  }
@@ -569,7 +610,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
569
610
  );
570
611
  }
571
612
  case "inline_ref": {
572
- const number = refScope?.next(token.kind) ?? 0;
613
+ const number = refScope?.numberFor(token.kind, token.content) ?? 0;
573
614
  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 });
574
615
  }
575
616
  default: