@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,7 @@
1
+ export { C as CodeConfig, E as EmbeddingsConfig, I as InlineConfig, N as NcmConfig, a as NcmProvider, b as NcmProviderProps, u as useNcmConfig } from '../use-ncm-config-D0doMYTH.js';
2
+ export { B as BlockReferenceScope, a as BlockReferenceScopeProps, b as BlockReferenceScopeValue, I as InertReferenceScope, N as NcmReferencesProvider, c as NcmReferencesProviderProps, R as ReferenceCounts, d as ReferenceKind, e as computeReferenceBases, u as useBlockReferenceScope } from '../references-Bs5wJybr.js';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import '@nuucognition/mesh-core';
6
+ import '@nuucognition/ncm';
7
+ import '../renderers-C5f41FCy.js';
@@ -0,0 +1,284 @@
1
+ "use client";
2
+ import { createContext, useContext, useMemo, useRef } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import { isTypedNestedList } from '@nuucognition/ncm';
5
+
6
+ // src/context/ncm-context.tsx
7
+ var NcmContext = createContext(null);
8
+ function useNcmConfig() {
9
+ return useContext(NcmContext) ?? {};
10
+ }
11
+ function NcmProvider({ config, children }) {
12
+ const value = useMemo(() => config ?? {}, [config]);
13
+ return /* @__PURE__ */ jsx(NcmContext.Provider, { value, children });
14
+ }
15
+
16
+ // src/inline/parser.ts
17
+ function splitOnce(input, delimiter) {
18
+ const idx = input.indexOf(delimiter);
19
+ if (idx === -1) {
20
+ return [input, null];
21
+ }
22
+ return [input.slice(0, idx), input.slice(idx + delimiter.length)];
23
+ }
24
+ function parseWikiTarget(rawInside) {
25
+ const inside = rawInside.trim();
26
+ const [targetPlusAnchor, displayRaw] = splitOnce(inside, "|");
27
+ const [targetRaw, anchorRaw] = splitOnce(targetPlusAnchor, "#");
28
+ const target = targetRaw.trim();
29
+ const display = displayRaw !== null ? displayRaw.trim() || null : null;
30
+ const anchor = anchorRaw !== null ? anchorRaw.trim() || null : null;
31
+ return { target, display, anchor };
32
+ }
33
+ var INLINE_REF_KIND_RE = /^\s*(ref|footnote)\s*:\s*([\s\S]*)$/i;
34
+ function tryParseInlineRef(input) {
35
+ let depth = 1;
36
+ let i = 2;
37
+ for (; i < input.length; i++) {
38
+ const ch = input[i];
39
+ if (ch === "[") {
40
+ depth++;
41
+ } else if (ch === "]") {
42
+ depth--;
43
+ if (depth === 0) break;
44
+ }
45
+ }
46
+ if (depth !== 0) return null;
47
+ const inner = input.slice(2, i);
48
+ const length = i + 1;
49
+ const match = INLINE_REF_KIND_RE.exec(inner);
50
+ if (match && match[1]) {
51
+ const kind = match[1].toLowerCase() === "ref" ? "ref" : "footnote";
52
+ return { token: { type: "inline_ref", kind, content: (match[2] ?? "").trim() }, length };
53
+ }
54
+ return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
55
+ }
56
+ function parseInline(content) {
57
+ if (!content) return [];
58
+ const tokens = [];
59
+ let remaining = content;
60
+ while (remaining.length > 0) {
61
+ const codeMatch = remaining.match(/^`([^`]+)`/);
62
+ if (codeMatch && codeMatch[1] !== void 0) {
63
+ tokens.push({ type: "code", content: codeMatch[1] });
64
+ remaining = remaining.slice(codeMatch[0].length);
65
+ continue;
66
+ }
67
+ const latexMatch = remaining.match(/^\$(?!\s)([^$\n]+?)(?<!\s)\$/);
68
+ if (latexMatch && latexMatch[1] !== void 0) {
69
+ tokens.push({ type: "latex", content: latexMatch[1] });
70
+ remaining = remaining.slice(latexMatch[0].length);
71
+ continue;
72
+ }
73
+ if (remaining.startsWith("^[")) {
74
+ const inlineRef = tryParseInlineRef(remaining);
75
+ if (inlineRef) {
76
+ tokens.push(inlineRef.token);
77
+ remaining = remaining.slice(inlineRef.length);
78
+ continue;
79
+ }
80
+ }
81
+ const wikiEmbedMatch = remaining.match(/^!\[\[([^\]]+)\]\]/);
82
+ if (wikiEmbedMatch && wikiEmbedMatch[1] !== void 0) {
83
+ const parsed = parseWikiTarget(wikiEmbedMatch[1]);
84
+ tokens.push({
85
+ type: "wiki_embed",
86
+ target: parsed.target,
87
+ display: parsed.display,
88
+ anchor: parsed.anchor
89
+ });
90
+ remaining = remaining.slice(wikiEmbedMatch[0].length);
91
+ continue;
92
+ }
93
+ const wikiLinkMatch = remaining.match(/^\[\[([^\]]+)\]\]/);
94
+ if (wikiLinkMatch && wikiLinkMatch[1] !== void 0) {
95
+ const parsed = parseWikiTarget(wikiLinkMatch[1]);
96
+ tokens.push({
97
+ type: "wiki_link",
98
+ target: parsed.target,
99
+ display: parsed.display,
100
+ anchor: parsed.anchor
101
+ });
102
+ remaining = remaining.slice(wikiLinkMatch[0].length);
103
+ continue;
104
+ }
105
+ const imageMatch = remaining.match(/^!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
106
+ if (imageMatch && imageMatch[1] !== void 0 && imageMatch[2] !== void 0) {
107
+ tokens.push({
108
+ type: "image",
109
+ alt: imageMatch[1],
110
+ src: imageMatch[2],
111
+ title: imageMatch[3]
112
+ });
113
+ remaining = remaining.slice(imageMatch[0].length);
114
+ continue;
115
+ }
116
+ const linkMatch = remaining.match(/^\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]+)")?\)/);
117
+ if (linkMatch && linkMatch[1] !== void 0 && linkMatch[2] !== void 0) {
118
+ tokens.push({
119
+ type: "link",
120
+ href: linkMatch[2],
121
+ title: linkMatch[3],
122
+ children: parseInline(linkMatch[1])
123
+ });
124
+ remaining = remaining.slice(linkMatch[0].length);
125
+ continue;
126
+ }
127
+ const boldMatch = remaining.match(/^\*\*(.+?)\*\*|^__(.+?)__/);
128
+ if (boldMatch) {
129
+ const innerContent = boldMatch[1] ?? boldMatch[2];
130
+ if (innerContent !== void 0) {
131
+ tokens.push({
132
+ type: "bold",
133
+ children: parseInline(innerContent)
134
+ });
135
+ remaining = remaining.slice(boldMatch[0].length);
136
+ continue;
137
+ }
138
+ }
139
+ const strikeMatch = remaining.match(/^~~(.+?)~~/);
140
+ if (strikeMatch && strikeMatch[1] !== void 0) {
141
+ tokens.push({
142
+ type: "strikethrough",
143
+ children: parseInline(strikeMatch[1])
144
+ });
145
+ remaining = remaining.slice(strikeMatch[0].length);
146
+ continue;
147
+ }
148
+ const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
149
+ if (italicMatch) {
150
+ const innerContent = italicMatch[1] ?? italicMatch[2];
151
+ if (innerContent !== void 0) {
152
+ tokens.push({
153
+ type: "italic",
154
+ children: parseInline(innerContent)
155
+ });
156
+ remaining = remaining.slice(italicMatch[0].length);
157
+ continue;
158
+ }
159
+ }
160
+ const nextSpecial = findNextSpecialChar(remaining);
161
+ if (nextSpecial > 0) {
162
+ tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
163
+ remaining = remaining.slice(nextSpecial);
164
+ } else {
165
+ tokens.push({ type: "text", content: remaining });
166
+ remaining = "";
167
+ }
168
+ }
169
+ return mergeAdjacentText(tokens);
170
+ }
171
+ function findNextSpecialChar(content) {
172
+ const specialChars = ["`", "$", "!", "[", "*", "_", "~", "^"];
173
+ let minIndex = -1;
174
+ for (const char of specialChars) {
175
+ const index = content.indexOf(char);
176
+ if (index > 0 && (minIndex === -1 || index < minIndex)) {
177
+ minIndex = index;
178
+ }
179
+ }
180
+ return minIndex;
181
+ }
182
+ function mergeAdjacentText(tokens) {
183
+ const result = [];
184
+ for (const token of tokens) {
185
+ const last = result[result.length - 1];
186
+ if (token.type === "text" && last?.type === "text") {
187
+ last.content += token.content;
188
+ } else {
189
+ result.push(token);
190
+ }
191
+ }
192
+ return result;
193
+ }
194
+ function collectInlineStrings(block) {
195
+ switch (block.type) {
196
+ case "paragraph":
197
+ case "header":
198
+ case "blockquote":
199
+ return [block.content ?? ""];
200
+ case "list_ordered":
201
+ case "list_unordered":
202
+ return collectListStrings(block.items ?? []);
203
+ case "table": {
204
+ const t = block;
205
+ return [...t.headers ?? [], ...(t.rows ?? []).flat()];
206
+ }
207
+ case "embedding": {
208
+ const caption = block.caption;
209
+ return caption ? [caption] : [];
210
+ }
211
+ default:
212
+ return [];
213
+ }
214
+ }
215
+ function collectListStrings(items) {
216
+ const out = [];
217
+ for (const item of items) {
218
+ if (typeof item === "string") {
219
+ out.push(item);
220
+ } else if (isTypedNestedList(item)) {
221
+ out.push(...collectListStrings(item.items));
222
+ } else if (Array.isArray(item) && item.length > 0) {
223
+ const [first, ...rest] = item;
224
+ if (typeof first === "string") out.push(first);
225
+ out.push(...collectListStrings(rest));
226
+ }
227
+ }
228
+ return out;
229
+ }
230
+ function countInlineRefs(tokens, acc) {
231
+ for (const token of tokens) {
232
+ if (token.type === "inline_ref") {
233
+ acc[token.kind] += 1;
234
+ } else if ("children" in token) {
235
+ countInlineRefs(token.children, acc);
236
+ }
237
+ }
238
+ }
239
+ function countBlock(block) {
240
+ const acc = { ref: 0, footnote: 0 };
241
+ for (const str of collectInlineStrings(block)) {
242
+ if (str) countInlineRefs(parseInline(str), acc);
243
+ }
244
+ return acc;
245
+ }
246
+ function computeReferenceBases(blocks) {
247
+ const bases = /* @__PURE__ */ new Map();
248
+ const acc = { ref: 0, footnote: 0 };
249
+ for (const block of blocks) {
250
+ bases.set(block.id, { ...acc });
251
+ const counts = countBlock(block);
252
+ acc.ref += counts.ref;
253
+ acc.footnote += counts.footnote;
254
+ }
255
+ return bases;
256
+ }
257
+ var ReferenceBasesContext = createContext(null);
258
+ var BlockReferenceScopeContext = createContext(null);
259
+ function NcmReferencesProvider({ blocks, children }) {
260
+ const bases = useMemo(() => computeReferenceBases(blocks), [blocks]);
261
+ return /* @__PURE__ */ jsx(ReferenceBasesContext.Provider, { value: bases, children });
262
+ }
263
+ function BlockReferenceScope({ blockId, children }) {
264
+ const bases = useContext(ReferenceBasesContext);
265
+ const base = (blockId ? bases?.get(blockId) : void 0) ?? { ref: 0, footnote: 0 };
266
+ const counter = useRef({ ref: 0, footnote: 0 });
267
+ counter.current = { ref: 0, footnote: 0 };
268
+ const value = {
269
+ next(kind) {
270
+ counter.current[kind] += 1;
271
+ return base[kind] + counter.current[kind];
272
+ }
273
+ };
274
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
275
+ }
276
+ function useBlockReferenceScope() {
277
+ return useContext(BlockReferenceScopeContext);
278
+ }
279
+ var INERT_SCOPE = { next: () => 0 };
280
+ function InertReferenceScope({ children }) {
281
+ return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
282
+ }
283
+
284
+ export { BlockReferenceScope, InertReferenceScope, NcmProvider, NcmReferencesProvider, computeReferenceBases, useBlockReferenceScope, useNcmConfig };
@@ -0,0 +1,7 @@
1
+ export { u as useNcmConfig } from '../use-ncm-config-D0doMYTH.js';
2
+ export { useBlockRenderer, useCustomCodeRenderer } from './use-block-renderer.js';
3
+ import 'react/jsx-runtime';
4
+ import 'react';
5
+ import '@nuucognition/mesh-core';
6
+ import '@nuucognition/ncm';
7
+ import '../renderers-C5f41FCy.js';