devnonla-ui 0.9.1 → 0.11.0

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/README.md CHANGED
@@ -55,7 +55,7 @@ Aliases: `xs` → small, `middle` / `medium` → default.
55
55
 
56
56
  All color lives in **`--nonla-*` knobs** (`src/styles.css`). Components never hardcode palette hex.
57
57
 
58
- Dark is the default (`:root` and `.dark`). `.light` is the daylight palette. `<App>` calls `initColorMode()` once and restores `localStorage` key `nonla-color-mode`, falling back to dark. Switch with `setColorMode("light" | "dark")` or `<ThemeToggle>`. To start in daylight before paint, put `class="light"` on `<html>`.
58
+ Dark is the default (`:root` and `.dark`). `.light` is the daylight palette. `<App>` calls `initColorMode()` once and restores `localStorage` key `nonla-color-mode`, falling back to dark. Switch with `setColorMode("light" | "dark")` or `<ThemeToggle>`. `setColorPreference("light" | "dark" | "system")` and `<ThemeSwitcher>` also store `system`, which follows the OS and still paints `light` or `dark`. To start in daylight before paint, put `class="light"` on `<html>`.
59
59
 
60
60
  **Other apps** — import the CSS, then override knobs. Do not fork Button/Tag/….
61
61
 
@@ -194,14 +194,68 @@ Primitives (`ChatWelcome`, `ChatUserMessage`, `ChatAgentMessage`, `ChatThinking`
194
194
 
195
195
  # Markdown
196
196
 
197
- `MarkdownEditor` edits markdown in preview, source, or diff. Pass `original` to enable the diff view. `diffLayout` is side by side by default. `readOnly` shows a finished document and hides the mode switcher.
197
+ `MarkdownViewer` renders markdown for reading: headings, lists, tables, code, and mermaid. Agent replies use the same view.
198
+
199
+ `MarkdownEditor` edits markdown in preview, source, or diff. Pass `original` to enable the diff view. `diffLayout` is side by side by default. `readOnly` locks the editor and hides the mode switcher.
198
200
 
199
201
  ```tsx
200
- import { MarkdownEditor } from "devnonla-ui";
202
+ import { MarkdownEditor, MarkdownViewer } from "devnonla-ui";
201
203
 
204
+ <MarkdownViewer value={article} />
202
205
  <MarkdownEditor value={text} original={previous} onChange={setText} />
203
206
  ```
204
207
 
208
+ ## Live React in markdown
209
+
210
+ A `live-react` fence exports a default component and renders it above its source. It is off unless you opt in.
211
+
212
+ - **Markdown from users or agents:** pass `sandboxSrc`. The fence runs in an iframe with `sandbox="allow-scripts"` and no `allow-same-origin`, so it cannot reach the page's cookies, storage, or DOM. `sandboxSrc` is a page you host on its own origin that calls `mountReactCodeRunner`; its `modules` are the only imports markdown gets.
213
+ - **Markdown you wrote:** pass `trustedModules`. The fence runs in your page with full access. Never use it for content someone else can write.
214
+
215
+ ```tsx
216
+ // sandbox page
217
+ import * as ui from "devnonla-ui";
218
+ import { mountReactCodeRunner } from "devnonla-ui";
219
+
220
+ mountReactCodeRunner(document.getElementById("root")!, { "devnonla-ui": ui });
221
+
222
+ // app
223
+ <MarkdownViewer value={article} sandboxSrc="https://sandbox.example.com/runner.html" />
224
+ ```
225
+
226
+ Outside markdown, use the pieces directly. `ReactCodeSandbox` takes `code` and `src` and renders the same framed result with a Code tab. `ReactCode` is the in-page version for source you wrote. `ReactCodeFrame` is the header and tab box, if you want to wrap your own result.
227
+
228
+ ```tsx
229
+ <ReactCodeSandbox code={source} src="https://sandbox.example.com/runner.html" />
230
+ ```
231
+
232
+ Serve the runner page with `Content-Security-Policy: connect-src 'none'` and `Access-Control-Allow-Origin: *` on its assets, since a sandboxed frame loads them cross-origin.
233
+
234
+ # Typography
235
+
236
+ `Text`, `Title`, `Paragraph`, and `Link` share one decoration set: `type` (`secondary` | `success` | `warning` | `danger`), `disabled`, `mark`, `code`, `keyboard`, `underline`, `delete`, `strong`, and `italic`. `Title` `level` is 1–5. `Typography` groups the same pieces.
237
+
238
+ ```tsx
239
+ import { Link, Paragraph, Text, Title } from "devnonla-ui";
240
+
241
+ <Title level={2}>Agents</Title>
242
+ <Paragraph>Run them on your machine.</Paragraph>
243
+ <Text type="secondary">Updated today</Text>
244
+ <Link href="https://nonlaagents.com">nonlaagents.com</Link>
245
+ ```
246
+
247
+ # Logo
248
+
249
+ `Logo` is the mark and the wordmark “Nonla Agents”. `variant` is `icon`, `text`, or `full` (default). `face` is `pixel` (default) or `jakarta`. `size` is the icon height in px (default 32). `color` recolors the mark and the wordmark; the eyes and the smile stay.
250
+
251
+ ```tsx
252
+ import { Logo } from "devnonla-ui";
253
+
254
+ <Logo />
255
+ <Logo variant="icon" size={24} />
256
+ <Logo face="jakarta" color="#181818" />
257
+ ```
258
+
205
259
  # Icons
206
260
 
207
261
  `SolarIcon` renders vendored Solar icons (`@iconify-json/solar`) as inline SVG, so they follow `currentColor`. Default style is `linear`. A legacy Fluent Color id such as `settings-24` still resolves to the Solar equivalent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@fontsource-variable/inter": "^5.3.0",
41
+ "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
41
42
  "@iconify-json/solar": "^1.2.13",
42
43
  "@radix-ui/react-checkbox": "^1.3.3",
43
44
  "@radix-ui/react-context-menu": "^2.3.7",
@@ -54,6 +55,7 @@
54
55
  "react-day-picker": "^10.0.1",
55
56
  "react-markdown": "^10.1.0",
56
57
  "remark-gfm": "^4.0.1",
58
+ "sucrase": "^3.35.1",
57
59
  "tailwind-merge": "^3.5.0"
58
60
  },
59
61
  "devDependencies": {
@@ -0,0 +1,205 @@
1
+ import { createContext, type ReactNode, useContext, useId } from "react";
2
+ import { cn } from "../lib/cn";
3
+
4
+ /** `still` holds the pose. `idle` looks around. Defaults to `still`. */
5
+ export type AgentAvatarMotion = "still" | "idle";
6
+
7
+ /** Fixed facing. The head turns that way and the eyes follow. */
8
+ export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
9
+
10
+ export const AGENT_AVATAR_PARTS = {
11
+ shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
12
+ color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
13
+ } as const;
14
+
15
+ type Part<K extends keyof typeof AGENT_AVATAR_PARTS> = (typeof AGENT_AVATAR_PARTS)[K][number];
16
+
17
+ /** A character is one shape plus the two eyes. */
18
+ export type AgentAvatarConfig = {
19
+ shape: Part<"shape">;
20
+ color: string;
21
+ };
22
+
23
+ export type AgentAvatarProps = {
24
+ /** Shape and color. Omitted parts use circle and `#6E56F0`. */
25
+ config?: Partial<AgentAvatarConfig>;
26
+ /** Square size in px. Defaults to 64. */
27
+ size?: number;
28
+ motion?: AgentAvatarMotion;
29
+ /** Which way the face is turned. Defaults to straight ahead. */
30
+ look?: AgentAvatarLook;
31
+ className?: string;
32
+ /** Accessible name. Defaults to "Agent". */
33
+ label?: string;
34
+ };
35
+
36
+ function hash(seed: string) {
37
+ let h = 2166136261;
38
+ for (let i = 0; i < seed.length; i++) {
39
+ h ^= seed.charCodeAt(i);
40
+ h = Math.imul(h, 16777619);
41
+ }
42
+ return h >>> 0;
43
+ }
44
+
45
+ const DEFAULT_CONFIG: AgentAvatarConfig = {
46
+ shape: AGENT_AVATAR_PARTS.shape[0],
47
+ color: AGENT_AVATAR_PARTS.color[0],
48
+ };
49
+
50
+ function resolveConfig(config?: Partial<AgentAvatarConfig>): AgentAvatarConfig {
51
+ return {
52
+ shape: config?.shape ?? DEFAULT_CONFIG.shape,
53
+ color: config?.color ?? DEFAULT_CONFIG.color,
54
+ };
55
+ }
56
+
57
+ function stagger(seed: string) {
58
+ return (hash(seed) % 8) * 0.2;
59
+ }
60
+
61
+ const EYE = "#111";
62
+ const EYE_ON_DARK = "#fff";
63
+
64
+ function eyeInk(color: string) {
65
+ const hex = color.replace("#", "");
66
+ if (hex.length < 6) return EYE;
67
+ const r = Number.parseInt(hex.slice(0, 2), 16);
68
+ const g = Number.parseInt(hex.slice(2, 4), 16);
69
+ const b = Number.parseInt(hex.slice(4, 6), 16);
70
+ const luma = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
71
+ return luma < 0.28 ? EYE_ON_DARK : EYE;
72
+ }
73
+
74
+ /** Head shift, then how much further the eyes travel, in viewBox units. */
75
+ const LOOK: Record<AgentAvatarLook, { head: [number, number]; eyes: [number, number] }> = {
76
+ forward: { head: [0, 0], eyes: [0, 0] },
77
+ left: { head: [-3.2, 0.6], eyes: [-6.4, 0.4] },
78
+ right: { head: [3.2, 0.6], eyes: [6.4, 0.4] },
79
+ up: { head: [0, -2.6], eyes: [0, -4.4] },
80
+ down: { head: [0, 2.8], eyes: [0, 4.6] },
81
+ "up-left": { head: [-2.3, -1.9], eyes: [-4.5, -3.1] },
82
+ "up-right": { head: [2.3, -1.9], eyes: [4.5, -3.1] },
83
+ "down-left": { head: [-2.3, 2], eyes: [-4.5, 3.3] },
84
+ "down-right": { head: [2.3, 2], eyes: [4.5, 3.3] },
85
+ };
86
+
87
+ function mixHex(color: string, toward: "#fff" | "#000", amount: number) {
88
+ const hex = color.replace("#", "");
89
+ const channel = (start: number) => Number.parseInt(hex.slice(start, start + 2), 16);
90
+ const target = toward === "#fff" ? 255 : 0;
91
+ const mix = (value: number) => Math.round(value + (target - value) * amount)
92
+ .toString(16)
93
+ .padStart(2, "0");
94
+ return `#${mix(channel(0))}${mix(channel(2))}${mix(channel(4))}`;
95
+ }
96
+
97
+ const PaintContext = createContext("#111");
98
+ const ShadowContext = createContext<string | undefined>(undefined);
99
+ const InkContext = createContext(EYE);
100
+
101
+ function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number; h?: number }) {
102
+ const gap = w * 1.5;
103
+ const top = cy - h / 2;
104
+ const fill = useContext(InkContext);
105
+ return (
106
+ <g className="nonla-avatar-gaze">
107
+ <g className="nonla-avatar-eyes">
108
+ <rect x={cx - gap / 2 - w} y={top} width={w} height={h} rx={w / 2} fill={fill} />
109
+ <rect x={cx + gap / 2} y={top} width={w} height={h} rx={w / 2} fill={fill} />
110
+ </g>
111
+ </g>
112
+ );
113
+ }
114
+
115
+ function Shape({ shape, color }: AgentAvatarConfig) {
116
+ const paint = useContext(PaintContext);
117
+ const shadow = useContext(ShadowContext);
118
+ const soft = { fill: paint, stroke: paint, strokeLinejoin: "round" as const };
119
+ const face = (mark: ReactNode, eyes: ReactNode, shiftY = 0) => (
120
+ <g transform={shiftY ? `translate(0 ${shiftY})` : undefined}>
121
+ <g filter={shadow}>{mark}</g>
122
+ {eyes}
123
+ </g>
124
+ );
125
+ const body: Record<AgentAvatarConfig["shape"], ReactNode> = {
126
+ circle: face(<circle cx="32" cy="32" r="22" fill={paint} />, <Eyes cx={32} cy={30} />),
127
+ square: face(<rect x="9" y="9" width="46" height="46" rx="16" fill={paint} />, <Eyes cx={32} cy={30} />),
128
+ triangle: face(<path d="M32 16 L50 50 H14 Z" strokeWidth="14" {...soft} />, <Eyes cx={32} cy={38} />, -1),
129
+ diamond: face(<path d="M32 10 L54 32 L32 54 L10 32 Z" strokeWidth="16" {...soft} />, <Eyes cx={32} cy={30} />),
130
+ hex: face(<path d="M32 12 L49 22 L49 42 L32 52 L15 42 L15 22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
131
+ gem: face(<path d="M22 12 H42 L52 22 V42 L42 52 H22 L12 42 V22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
132
+ pill: face(<rect x="6" y="18" width="52" height="28" rx="14" fill={paint} />, <Eyes cx={32} cy={30} />),
133
+ arch: face(<path d="M14 50V32C14 18 50 18 50 32V50C50 56 14 56 14 50Z" fill={paint} />, <Eyes cx={32} cy={36} />, -6),
134
+ cloud: face(
135
+ <g fill={paint}>
136
+ <circle cx="20" cy="38" r="12" />
137
+ <circle cx="44" cy="38" r="12" />
138
+ <circle cx="32" cy="28" r="14" />
139
+ <rect x="16" y="34" width="32" height="14" />
140
+ </g>,
141
+ <Eyes cx={32} cy={36} />,
142
+ ),
143
+ blob: face(<ellipse cx="32" cy="34" rx="24" ry="18" fill={paint} />, <Eyes cx={32} cy={32} />, -2),
144
+ drop: face(
145
+ <path d="M27 23C19 30 15 37 15 46C15 55 22.5 60 32 60C41.5 60 49 55 49 46C49 37 45 30 37 23Q32 16 27 23Z" strokeWidth="5" {...soft} />,
146
+ <Eyes cx={32} cy={42} />,
147
+ -8,
148
+ ),
149
+ shield: face(
150
+ <path d="M18 18H46C52 18 54 24 54 32V36C54 48 46 56 32 58C18 56 10 48 10 36V32C10 24 12 18 18 18Z" fill={paint} />,
151
+ <Eyes cx={32} cy={34} />,
152
+ -6,
153
+ ),
154
+ };
155
+ return <InkContext.Provider value={eyeInk(color)}>{body[shape]}</InkContext.Provider>;
156
+ }
157
+
158
+ export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
159
+ const resolved = resolveConfig(config);
160
+ const delay = stagger(`${resolved.shape}${resolved.color}`);
161
+ const facing = LOOK[look];
162
+ const [hx, hy] = facing.head;
163
+ const [ex, ey] = facing.eyes;
164
+ const uid = useId().replace(/:/g, "");
165
+ const light = `nonla-av-${uid}`;
166
+ const shadow = `nonla-av-s-${uid}`;
167
+
168
+ return (
169
+ <span
170
+ role="img"
171
+ aria-label={label}
172
+ data-motion={motion}
173
+ data-look={look}
174
+ className={cn("nonla-avatar", className)}
175
+ style={{
176
+ width: size,
177
+ height: size,
178
+ ["--nonla-avatar-delay" as string]: `${delay}s`,
179
+ ["--nonla-avatar-hx" as string]: `${(hx / 64) * 100}%`,
180
+ ["--nonla-avatar-hy" as string]: `${(hy / 64) * 100}%`,
181
+ ["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
182
+ ["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
183
+ }}
184
+ >
185
+ <span className="nonla-avatar-bob" aria-hidden>
186
+ <svg viewBox="0 0 64 64" width="100%" height="100%">
187
+ <defs>
188
+ <linearGradient id={light} gradientUnits="userSpaceOnUse" x1="32" y1="4" x2="32" y2="60">
189
+ <stop offset="0" stopColor={mixHex(resolved.color, "#fff", 0.16)} />
190
+ <stop offset="1" stopColor={resolved.color} />
191
+ </linearGradient>
192
+ <filter id={shadow} x="-20%" y="-20%" width="140%" height="150%">
193
+ <feDropShadow dx="0" dy="0.8" stdDeviation="0.6" floodColor="#000" floodOpacity="0.18" />
194
+ </filter>
195
+ </defs>
196
+ <PaintContext.Provider value={`url(#${light})`}>
197
+ <ShadowContext.Provider value={`url(#${shadow})`}>
198
+ <Shape {...resolved} />
199
+ </ShadowContext.Provider>
200
+ </PaintContext.Provider>
201
+ </svg>
202
+ </span>
203
+ </span>
204
+ );
205
+ }
package/src/chat/index.ts CHANGED
@@ -18,8 +18,8 @@ export type { ChatErrorProps } from "./message-ui/ChatError";
18
18
  export { ChatError } from "./message-ui/ChatError";
19
19
  export type { ChatInputProps } from "./message-ui/ChatInput";
20
20
  export { ChatInput } from "./message-ui/ChatInput";
21
- export type { ChatMarkdownProps, ChatMarkdownStreamState } from "./message-ui/ChatMarkdown";
22
- export { ChatMarkdown, chatBodyClass, chatMarkdownClass, chatMarkdownComponents, createChatMarkdownComponents } from "./message-ui/ChatMarkdown";
21
+ export type { ChatMarkdownProps } from "./message-ui/ChatMarkdown";
22
+ export { ChatMarkdown } from "./message-ui/ChatMarkdown";
23
23
  export { ChatSpinner } from "./message-ui/ChatSpinner";
24
24
  export type { ChatThinkingProps } from "./message-ui/ChatThinking";
25
25
  export { ChatThinking } from "./message-ui/ChatThinking";
@@ -27,8 +27,6 @@ export type { ChatUserMessageProps } from "./message-ui/ChatUserMessage";
27
27
  export { ChatUserMessage } from "./message-ui/ChatUserMessage";
28
28
  export type { ChatWelcomeProps } from "./message-ui/ChatWelcome";
29
29
  export { ChatWelcome } from "./message-ui/ChatWelcome";
30
- export type { MermaidBlockProps } from "./message-ui/MermaidBlock";
31
- export { MermaidBlock } from "./message-ui/MermaidBlock";
32
30
  export type { BackgroundTasksBarProps } from "./tool-ui/BackgroundTasksBar";
33
31
  export { BackgroundTasksBar } from "./tool-ui/BackgroundTasksBar";
34
32
  export { BackgroundTaskToolUI } from "./tool-ui/BackgroundTaskToolUI";
@@ -14,16 +14,12 @@ export type ChatAgentMessageProps = {
14
14
  };
15
15
 
16
16
  export function ChatAgentMessage({ content, children, thinking, thinkingDuration, thinkingStreaming, className }: ChatAgentMessageProps) {
17
- const body = children ?? (content ? <p className="m-0 whitespace-pre-wrap wrap-break-word">{content}</p> : null);
17
+ const body = children ?? (content ? <p className="m-0 whitespace-pre-wrap wrap-break-word text-(length:--chat-body-size) leading-(--chat-body-leading) text-(--nonla-ink)">{content}</p> : null);
18
18
 
19
19
  return (
20
20
  <div className={cn("nonla-chat-agent mt-1", className)}>
21
21
  {thinking ? <ChatThinking thinking={thinking} duration={thinkingDuration ?? 0} streaming={thinkingStreaming} /> : null}
22
- {body ? (
23
- <div className="min-w-0 px-4 pb-0.5">
24
- <div className="nonla-chat-body text-(length:--chat-body-size) leading-(--chat-body-leading) text-(--nonla-ink)">{body}</div>
25
- </div>
26
- ) : null}
22
+ {body ? <div className="min-w-0 px-4 pb-0.5">{body}</div> : null}
27
23
  </div>
28
24
  );
29
25
  }
@@ -1,129 +1,11 @@
1
- import { useRef } from "react";
2
- import ReactMarkdown, { type Components } from "react-markdown";
3
- import remarkGfm from "remark-gfm";
4
- import { Checkbox } from "../../checkbox/Checkbox";
5
- import { CodeBlock } from "../../codeblock/CodeBlock";
6
- import { cn } from "../../lib/cn";
7
- import { ChatMarkdownTable } from "./ChatMarkdownTable";
8
- import { MermaidBlock } from "./MermaidBlock";
9
- import { isPendingMermaidBlock } from "./mermaidFence";
10
-
11
- /** Message body — sizes come from --chat-* tokens. */
12
- export const chatBodyClass = "font-normal text-foreground text-(length:--chat-body-size) leading-(--chat-body-leading)";
13
-
14
- /** Shared Tailwind prose classes for chat markdown. */
15
- export const chatMarkdownClass = cn(
16
- chatBodyClass,
17
- "min-w-0 wrap-anywhere",
18
- "[&_p]:m-0 [&_p]:mb-(--chat-p-mb) [&_p:last-child]:mb-0",
19
- "[&_:is(h1,h2,h3,h4,h5,h6)]:mt-(--chat-h-mt) [&_:is(h1,h2,h3,h4,h5,h6)]:mb-(--chat-h-mb) [&_:is(h1,h2,h3,h4,h5,h6)]:text-(length:--chat-body-size) [&_:is(h1,h2,h3,h4,h5,h6)]:font-semibold [&_:is(h1,h2,h3,h4,h5,h6)]:leading-(--chat-body-leading)",
20
- "[&_:is(h1,h2,h3,h4,h5,h6):first-child]:mt-0",
21
- "[&_strong]:font-semibold [&_em]:italic",
22
- "[&_blockquote]:m-0 [&_blockquote]:mb-(--chat-p-mb) [&_blockquote]:border-0 [&_blockquote]:p-0 [&_blockquote]:not-italic [&_blockquote]:text-inherit [&_blockquote:last-child]:mb-0",
23
- "[&_ul]:mt-2 [&_ul]:mb-(--chat-p-mb)",
24
- "[&_ul:not(.contains-task-list)]:list-disc [&_ul:not(.contains-task-list)]:pl-6.5",
25
- "[&_ul.contains-task-list]:list-none [&_ul.contains-task-list]:pl-6.5",
26
- "[&_li.task-list-item]:relative",
27
- "[&_li.task-list-item>.nonla-md-task-check]:absolute [&_li.task-list-item>.nonla-md-task-check]:top-0 [&_li.task-list-item>.nonla-md-task-check]:-left-5.5",
28
- "[&_ol]:mt-2 [&_ol]:mb-(--chat-p-mb) [&_ol]:list-decimal [&_ol]:pl-6.5",
29
- "[&_li]:my-1.5 [&_li]:leading-(--chat-body-leading)",
30
- "[&_a]:text-link [&_a]:no-underline [&_a]:hover:underline [&_a]:hover:underline-offset-[3px]",
31
- );
32
-
33
- export type ChatMarkdownStreamState = {
34
- content: string;
35
- streaming: boolean;
36
- };
1
+ import { MarkdownViewer } from "../../markdown-editor/MarkdownViewer";
37
2
 
38
3
  export type ChatMarkdownProps = {
39
4
  content: string;
40
5
  streaming?: boolean;
41
- className?: string;
42
6
  };
43
7
 
44
- /**
45
- * Build markdown components. Pass getState so pending-mermaid can update via ref
46
- * without recreating the components object (avoids remounting finished charts).
47
- */
48
- export function createChatMarkdownComponents(getState?: () => ChatMarkdownStreamState): Components {
49
- return {
50
- code({ className, children }) {
51
- const match = /language-(\w+)/.exec(className || "");
52
- const lang = match?.[1] ?? "";
53
- const codeText = String(children).replace(/\n$/, "");
54
- const isBlock = codeText.includes("\n") || !!match;
55
-
56
- if (isBlock) {
57
- const isMermaid = lang.toLowerCase() === "mermaid";
58
- if (isMermaid) {
59
- const state = getState?.();
60
- const pending = state ? isPendingMermaidBlock(state.content, codeText, state.streaming) : false;
61
- if (!pending) return <MermaidBlock>{codeText}</MermaidBlock>;
62
- }
63
-
64
- return <CodeBlock code={codeText} language={lang || undefined} className="my-3 last:mb-0" />;
65
- }
66
-
67
- return <span className="rounded-sm bg-foreground/12 font-mono px-px">{children}</span>;
68
- },
69
- hr() {
70
- return null;
71
- },
72
- table({ children }) {
73
- return <ChatMarkdownTable>{children}</ChatMarkdownTable>;
74
- },
75
- th({ children }) {
76
- return (
77
- <th>
78
- <div className="inline-block max-w-75 wrap-break-word">{children}</div>
79
- </th>
80
- );
81
- },
82
- td({ children }) {
83
- return (
84
- <td>
85
- <div className="inline-block max-w-75 wrap-break-word">{children}</div>
86
- </td>
87
- );
88
- },
89
- a({ href, children, ...props }) {
90
- return (
91
- <a href={href} target="_blank" rel="noopener noreferrer" {...props}>
92
- {children}
93
- </a>
94
- );
95
- },
96
- input({ type, checked }) {
97
- if (type !== "checkbox") return <input type={type} checked={checked} readOnly />;
98
- return (
99
- <span className="nonla-md-task-check pointer-events-none inline-flex h-(--chat-body-leading) items-center">
100
- <Checkbox
101
- checked={Boolean(checked)}
102
- tabIndex={-1}
103
- className="data-[state=checked]:border-white data-[state=checked]:bg-white data-[state=checked]:text-(--nonla-bg) data-[state=indeterminate]:border-white data-[state=indeterminate]:bg-white data-[state=indeterminate]:text-(--nonla-bg)"
104
- />
105
- </span>
106
- );
107
- },
108
- };
109
- }
110
-
111
- export const chatMarkdownComponents: Components = createChatMarkdownComponents();
112
-
113
- export function ChatMarkdown({ content, streaming = false, className }: ChatMarkdownProps) {
114
- const streamStateRef = useRef<ChatMarkdownStreamState>({ content, streaming });
115
- streamStateRef.current = { content, streaming };
116
-
117
- const componentsRef = useRef<Components | null>(null);
118
- if (!componentsRef.current) {
119
- componentsRef.current = createChatMarkdownComponents(() => streamStateRef.current);
120
- }
121
-
122
- return (
123
- <div className={cn(chatMarkdownClass, className)}>
124
- <ReactMarkdown remarkPlugins={[remarkGfm]} components={componentsRef.current}>
125
- {content}
126
- </ReactMarkdown>
127
- </div>
128
- );
8
+ /** Agent markdown. Uses MarkdownViewer as-is, with no extra prose styles. */
9
+ export function ChatMarkdown({ content, streaming = false }: ChatMarkdownProps) {
10
+ return <MarkdownViewer value={content} streaming={streaming} />;
129
11
  }
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
+ import { AgentAvatar } from "../../avatar/AgentAvatar";
2
3
  import { Button } from "../../button/Button";
3
4
  import { cn } from "../../lib/cn";
4
5
 
@@ -16,12 +17,7 @@ export type ChatWelcomeProps = {
16
17
  const DEFAULT_STARTERS = ["What can you help me with?", "Brainstorm a few ideas with me", "Walk me through how you work"] as const;
17
18
 
18
19
  function DefaultAvatar({ name }: { name: string }) {
19
- const initial = (name.trim()[0] ?? "?").toUpperCase();
20
- return (
21
- <div className="flex size-16 items-center justify-center rounded-full bg-brand/20 text-xl font-semibold text-brand-700" aria-hidden>
22
- {initial}
23
- </div>
24
- );
20
+ return <AgentAvatar size={72} label={name} />;
25
21
  }
26
22
 
27
23
  export function ChatWelcome({ name, description, avatar, starters = [...DEFAULT_STARTERS], onStarter, disabled, className }: ChatWelcomeProps) {
@@ -29,23 +25,7 @@ export function ChatWelcome({ name, description, avatar, starters = [...DEFAULT_
29
25
 
30
26
  return (
31
27
  <div className={cn("nonla-chat-welcome flex flex-col items-center justify-center min-h-full w-full px-6 py-10 text-center", className)}>
32
- <div className="relative mb-5">
33
- <div
34
- aria-hidden
35
- className="pointer-events-none absolute left-1/2 top-1/2 size-28 -translate-x-1/2 -translate-y-1/2 rounded-full"
36
- style={{
37
- background: "radial-gradient(circle, color-mix(in oklab, var(--brand) 28%, transparent) 0%, transparent 70%)",
38
- }}
39
- />
40
- <div
41
- className="relative rounded-full p-0.5"
42
- style={{
43
- background: "linear-gradient(145deg, color-mix(in oklab, var(--brand-600) 55%, transparent), transparent 60%)",
44
- }}
45
- >
46
- <div className="rounded-full bg-popover p-0.5">{avatar ?? <DefaultAvatar name={name} />}</div>
47
- </div>
48
- </div>
28
+ <div className="mb-5">{avatar ?? <DefaultAvatar name={name} />}</div>
49
29
 
50
30
  <h2 className="m-0 text-[22px] font-semibold tracking-tight text-foreground leading-snug">Hi, I&apos;m {name}</h2>
51
31
 
@@ -156,7 +156,7 @@ export function CallAgentToolUI({ msg, assistantLabel = "Assistant", assistantCo
156
156
  <p className="m-0 text-[14px] leading-[1.55] text-destructive">{parsed?.error ?? "Agent call failed"}</p>
157
157
  ) : parsed ? (
158
158
  <ExpandableBody>
159
- <ChatMarkdown content={parsed.response ?? "(no response)"} className="[&_p]:m-0 [&_p]:mb-0 [&_p+p]:mt-2" />
159
+ <ChatMarkdown content={parsed.response ?? "(no response)"} />
160
160
  </ExpandableBody>
161
161
  ) : (
162
162
  <ExpandableBody>
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ export type InputRef = HTMLInputElement;
15
15
 
16
16
  export type { AlertProps, AlertType } from "./alert/Alert";
17
17
  export { Alert } from "./alert/Alert";
18
+ export type { AgentAvatarConfig, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
19
+ export { AGENT_AVATAR_PARTS, AgentAvatar } from "./avatar/AgentAvatar";
18
20
  export type { CalendarProps } from "./calendar/Calendar";
19
21
  export { Calendar } from "./calendar/Calendar";
20
22
  export type { CardFooterProps, CardItemProps, CardProps } from "./card/Card";
@@ -39,13 +41,11 @@ export type {
39
41
  ChatErrorProps,
40
42
  ChatInputProps,
41
43
  ChatMarkdownProps,
42
- ChatMarkdownStreamState,
43
44
  ChatThinkingProps,
44
45
  ChatToolCallProps,
45
46
  ChatToolMessage,
46
47
  ChatUserMessageProps,
47
48
  ChatWelcomeProps,
48
- MermaidBlockProps,
49
49
  ToolUIProps,
50
50
  } from "./chat";
51
51
  export {
@@ -65,16 +65,11 @@ export {
65
65
  ChatToolCall,
66
66
  ChatUserMessage,
67
67
  ChatWelcome,
68
- chatBodyClass,
69
- chatMarkdownClass,
70
- chatMarkdownComponents,
71
- createChatMarkdownComponents,
72
68
  formatBgElapsed,
73
69
  formatToolName,
74
70
  GetCurrentTimeToolUI,
75
71
  isCallAgentToolName,
76
72
  isToolRunning,
77
- MermaidBlock,
78
73
  matchesToolHook,
79
74
  matchesToolName,
80
75
  matchesToolUIName,
@@ -164,8 +159,21 @@ export { placementToRadix } from "./lib/placement";
164
159
  export type { CanonicalSize, ControlSize, ControlSizeTokens } from "./lib/sizes";
165
160
  export { CONTROL_SIZES, controlHeightVar, controlRadiusVar, controlStatusClass, getSizeTokens, normalizeSize, useControlSize } from "./lib/sizes";
166
161
  export { glassOverlayClass, glassSurfaceClass, meadowSurfaceClass } from "./lib/surface";
162
+ export type { LogoFace, LogoProps, LogoVariant } from "./logo/Logo";
163
+ export { Logo } from "./logo/Logo";
167
164
  export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
168
165
  export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
166
+ export type { MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
167
+ export { MarkdownViewer } from "./markdown-editor/MarkdownViewer";
168
+ export type { MermaidBlockProps } from "./markdown-editor/MermaidBlock";
169
+ export { MermaidBlock } from "./markdown-editor/MermaidBlock";
170
+ export type { ReactCodeProps } from "./markdown-editor/ReactCode";
171
+ export { ReactCode } from "./markdown-editor/ReactCode";
172
+ export type { ReactCodeFrameProps } from "./markdown-editor/ReactCodeFrame";
173
+ export { ReactCodeFrame } from "./markdown-editor/ReactCodeFrame";
174
+ export { mountReactCodeRunner } from "./markdown-editor/ReactCodeRunner";
175
+ export type { ReactCodeSandboxProps } from "./markdown-editor/ReactCodeSandbox";
176
+ export { ReactCodeSandbox } from "./markdown-editor/ReactCodeSandbox";
169
177
  export type { MenuItemProps, MenuRootProps, MenuTriggerProps } from "./menu/Menu";
170
178
  export { Menu, MenuAction, MenuDivider, MenuItem, MenuTrigger } from "./menu/Menu";
171
179
  export type { MessageConfig, MessageType } from "./message/message";
@@ -207,11 +215,15 @@ export type {
207
215
  export { Table } from "./table/Table";
208
216
  export type { TagProps, TagVariant } from "./tag/Tag";
209
217
  export { Tag } from "./tag/Tag";
210
- export type { NonlaColorMode, NonlaThemeColorName, NonlaThemeColors, NonlaThemeConfig, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
211
- export { applyNonlaTheme, getColorMode, getDesignToken, initColorMode, NONLA_COLOR_MODE_KEY, NONLA_THEME_KEYS, NONLA_THEME_KNOBS, setColorMode } from "./theme";
218
+ export type { NonlaColorMode, NonlaColorPreference, NonlaThemeColorName, NonlaThemeColors, NonlaThemeConfig, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
219
+ export { applyNonlaTheme, getColorMode, getColorPreference, getDesignToken, initColorMode, NONLA_COLOR_MODE_KEY, NONLA_THEME_KEYS, NONLA_THEME_KNOBS, setColorMode, setColorPreference } from "./theme";
220
+ export type { ThemeSwitcherProps } from "./theme-switcher/ThemeSwitcher";
221
+ export { ThemeSwitcher, useColorPreference } from "./theme-switcher/ThemeSwitcher";
212
222
  export type { ThemeToggleProps } from "./theme-toggle/ThemeToggle";
213
223
  export { ThemeToggle, useColorMode } from "./theme-toggle/ThemeToggle";
214
224
  export type { TimePickerProps, TimeValue } from "./timepicker/TimePicker";
215
225
  export { TimePicker } from "./timepicker/TimePicker";
216
226
  export type { TooltipPlacement, TooltipProps } from "./tooltip/Tooltip";
217
227
  export { Tooltip } from "./tooltip/Tooltip";
228
+ export type { TitleLevel, TypographyLinkProps, TypographyParagraphProps, TypographyProps, TypographyTextProps, TypographyTitleProps, TypographyType } from "./typography/Typography";
229
+ export { Link, Paragraph, Text, Title, Typography } from "./typography/Typography";