@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,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { twMerge } from 'tailwind-merge';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/lib/utils.ts
|
|
7
|
+
function cn(...inputs) {
|
|
8
|
+
return twMerge(clsx(inputs));
|
|
9
|
+
}
|
|
10
|
+
function ChartBlock({ block, className }) {
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
"pre",
|
|
13
|
+
{
|
|
14
|
+
"data-ncm-block": block.id,
|
|
15
|
+
"data-ncm-stable": block.stableId,
|
|
16
|
+
"data-ncm-type": block.type,
|
|
17
|
+
"data-block-id": block.id,
|
|
18
|
+
"data-ncm-chart": "",
|
|
19
|
+
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
20
|
+
className: cn(
|
|
21
|
+
"overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
22
|
+
className
|
|
23
|
+
),
|
|
24
|
+
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { ChartBlock };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { CodeBlock as CodeBlock$1 } from '@nuucognition/ncm';
|
|
3
|
+
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type CodeBlockProps = BlockRendererProps<CodeBlock$1>;
|
|
7
|
+
/**
|
|
8
|
+
* Code block renderer with built-in Shiki syntax highlighting.
|
|
9
|
+
*
|
|
10
|
+
* Highlights code by default using Shiki's web bundle (github-light/github-dark).
|
|
11
|
+
* Consumers can override with a custom renderer via NcmProvider config.code.renderer.
|
|
12
|
+
*/
|
|
13
|
+
declare function CodeBlock({ block, className }: CodeBlockProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
export { CodeBlock, type CodeBlockProps };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useState, useCallback, useEffect, useMemo } from 'react';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
|
|
7
|
+
// src/blocks/code/code.tsx
|
|
8
|
+
var NcmContext = createContext(null);
|
|
9
|
+
function useNcmConfig() {
|
|
10
|
+
return useContext(NcmContext) ?? {};
|
|
11
|
+
}
|
|
12
|
+
function cn(...inputs) {
|
|
13
|
+
return twMerge(clsx(inputs));
|
|
14
|
+
}
|
|
15
|
+
var highlighterPromise = import('shiki/bundle/web').then(async (shiki) => {
|
|
16
|
+
const highlighter = await shiki.createHighlighter({
|
|
17
|
+
themes: ["github-light", "github-dark"],
|
|
18
|
+
langs: Object.keys(shiki.bundledLanguages)
|
|
19
|
+
});
|
|
20
|
+
return highlighter;
|
|
21
|
+
}).catch(() => null);
|
|
22
|
+
function useIsDark() {
|
|
23
|
+
const [isDark, setIsDark] = useState(false);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (typeof document === "undefined") return;
|
|
26
|
+
const root = document.documentElement;
|
|
27
|
+
const update = () => setIsDark(root.classList.contains("dark"));
|
|
28
|
+
update();
|
|
29
|
+
const observer = new MutationObserver(update);
|
|
30
|
+
observer.observe(root, { attributes: true, attributeFilter: ["class"] });
|
|
31
|
+
return () => observer.disconnect();
|
|
32
|
+
}, []);
|
|
33
|
+
return isDark;
|
|
34
|
+
}
|
|
35
|
+
function DefaultShikiRenderer({
|
|
36
|
+
code,
|
|
37
|
+
language
|
|
38
|
+
}) {
|
|
39
|
+
const isDark = useIsDark();
|
|
40
|
+
const [highlighter, setHighlighter] = useState(null);
|
|
41
|
+
const shikiTheme = isDark ? "github-dark" : "github-light";
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
let active = true;
|
|
44
|
+
highlighterPromise.then((h) => {
|
|
45
|
+
if (active) setHighlighter(h);
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
active = false;
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
const tokens = useMemo(() => {
|
|
52
|
+
if (!highlighter) return null;
|
|
53
|
+
const loaded = highlighter.getLoadedLanguages();
|
|
54
|
+
const lang = language && loaded.includes(language) ? language : "text";
|
|
55
|
+
try {
|
|
56
|
+
return highlighter.codeToTokens(code, { lang, theme: shikiTheme }).tokens;
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}, [code, language, highlighter, shikiTheme]);
|
|
61
|
+
if (!tokens) {
|
|
62
|
+
return /* @__PURE__ */ jsx(Fragment, { children: code });
|
|
63
|
+
}
|
|
64
|
+
return /* @__PURE__ */ jsx(Fragment, { children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsx("span", { className: "block whitespace-pre", children: line.length === 0 ? " " : line.map((token, tokenIndex) => /* @__PURE__ */ jsx("span", { style: { color: token.color || "inherit" }, children: token.content }, tokenIndex)) }, lineIndex)) });
|
|
65
|
+
}
|
|
66
|
+
function CopyButton({ content }) {
|
|
67
|
+
const [copied, setCopied] = useState(false);
|
|
68
|
+
const handleCopy = useCallback(async () => {
|
|
69
|
+
try {
|
|
70
|
+
await navigator.clipboard.writeText(content);
|
|
71
|
+
setCopied(true);
|
|
72
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
73
|
+
} catch {
|
|
74
|
+
const textarea = document.createElement("textarea");
|
|
75
|
+
textarea.value = content;
|
|
76
|
+
document.body.appendChild(textarea);
|
|
77
|
+
textarea.select();
|
|
78
|
+
document.execCommand("copy");
|
|
79
|
+
document.body.removeChild(textarea);
|
|
80
|
+
setCopied(true);
|
|
81
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
82
|
+
}
|
|
83
|
+
}, [content]);
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
"button",
|
|
86
|
+
{
|
|
87
|
+
type: "button",
|
|
88
|
+
onClick: handleCopy,
|
|
89
|
+
"aria-label": copied ? "Copied!" : "Copy code",
|
|
90
|
+
"data-ncm-copy-button": "",
|
|
91
|
+
className: "absolute right-2 top-2 rounded-md bg-background/80 px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-background hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring",
|
|
92
|
+
children: copied ? "Copied!" : "Copy"
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
function LineNumbers({ count }) {
|
|
97
|
+
return /* @__PURE__ */ jsx(
|
|
98
|
+
"div",
|
|
99
|
+
{
|
|
100
|
+
"aria-hidden": "true",
|
|
101
|
+
"data-ncm-line-numbers": "",
|
|
102
|
+
className: "select-none pr-4 text-right text-muted-foreground/60",
|
|
103
|
+
children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx("div", { children: i + 1 }, i + 1))
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function CodeBlock({ block, className }) {
|
|
108
|
+
const config = useNcmConfig();
|
|
109
|
+
const { code: codeConfig } = config;
|
|
110
|
+
const lineCount = block.content.split("\n").length;
|
|
111
|
+
const languageLabel = block.language ? /* @__PURE__ */ jsx(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
"data-ncm-code-language": "",
|
|
115
|
+
className: "absolute right-2 bottom-2 text-xs text-muted-foreground/60",
|
|
116
|
+
children: block.language
|
|
117
|
+
}
|
|
118
|
+
) : null;
|
|
119
|
+
if (codeConfig?.renderer) {
|
|
120
|
+
const CustomRenderer = codeConfig.renderer;
|
|
121
|
+
return /* @__PURE__ */ jsxs(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
role: "region",
|
|
125
|
+
"aria-label": block.language ? `Code block: ${block.language}` : "Code block",
|
|
126
|
+
"data-ncm-block": block.id,
|
|
127
|
+
"data-ncm-stable": block.stableId,
|
|
128
|
+
"data-ncm-type": block.type,
|
|
129
|
+
"data-block-id": block.id,
|
|
130
|
+
"data-ncm-language": block.language,
|
|
131
|
+
className: cn("relative", className),
|
|
132
|
+
children: [
|
|
133
|
+
codeConfig.copyButton !== false && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
134
|
+
/* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
|
|
135
|
+
languageLabel
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return /* @__PURE__ */ jsxs(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
role: "region",
|
|
144
|
+
"aria-label": block.language ? `Code block: ${block.language}` : "Code block",
|
|
145
|
+
"data-ncm-block": block.id,
|
|
146
|
+
"data-ncm-stable": block.stableId,
|
|
147
|
+
"data-ncm-type": block.type,
|
|
148
|
+
"data-block-id": block.id,
|
|
149
|
+
"data-ncm-language": block.language,
|
|
150
|
+
className: cn("relative", className),
|
|
151
|
+
children: [
|
|
152
|
+
codeConfig?.copyButton !== false && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
153
|
+
/* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
|
|
154
|
+
codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
|
|
155
|
+
/* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
|
|
156
|
+
] }) }),
|
|
157
|
+
languageLabel
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ContainerBlock as ContainerBlock$1 } from '@nuucognition/ncm';
|
|
3
|
+
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type ContainerBlockProps = BlockRendererProps<ContainerBlock$1>;
|
|
7
|
+
/**
|
|
8
|
+
* Generic container renderer — a `:::directive` fence that no promoter claimed.
|
|
9
|
+
*
|
|
10
|
+
* Renders the directive as a styled label (not raw `:::` syntax) above its
|
|
11
|
+
* verbatim inner content. Consumers that add directive-specific promoters
|
|
12
|
+
* (admonition, figure, tabs…) replace this by promoting upstream or overriding
|
|
13
|
+
* the `container` renderer key.
|
|
14
|
+
*/
|
|
15
|
+
declare function ContainerBlock({ block, className }: ContainerBlockProps): react_jsx_runtime.JSX.Element;
|
|
16
|
+
|
|
17
|
+
export { ContainerBlock, type ContainerBlockProps };
|