devnonla-ui 0.14.0 → 0.15.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.
Files changed (50) hide show
  1. package/package.json +2 -2
  2. package/src/blob-shape/BlobShape.tsx +337 -0
  3. package/src/button/ButtonCopy.tsx +2 -2
  4. package/src/chat/AgentChatbox.tsx +1 -1
  5. package/src/chat/AgentPanel.tsx +1 -1
  6. package/src/chat/chatMessageList.tsx +5 -3
  7. package/src/chat/chatRhythm.ts +8 -0
  8. package/src/chat/common/createAgentSseSession.ts +9 -3
  9. package/src/chat/common/sse.ts +290 -122
  10. package/src/chat/common/useAgentStream.ts +1 -1
  11. package/src/chat/index.ts +2 -2
  12. package/src/chat/message-ui/ChatAgentMessage.tsx +4 -3
  13. package/src/chat/message-ui/ChatError.tsx +5 -4
  14. package/src/chat/message-ui/ChatInput.tsx +5 -5
  15. package/src/chat/message-ui/ChatMarkdown.tsx +36 -2
  16. package/src/chat/message-ui/ChatThinking.tsx +8 -7
  17. package/src/chat/message-ui/ChatUserMessage.tsx +4 -4
  18. package/src/chat/tool-ui/BackgroundTaskToolUI.tsx +7 -6
  19. package/src/chat/tool-ui/BackgroundTasksBar.tsx +7 -7
  20. package/src/chat/tool-ui/CallAgentToolUI.tsx +14 -13
  21. package/src/chat/tool-ui/ChatToolCall.tsx +13 -12
  22. package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +7 -6
  23. package/src/chat/tool-ui/ReadSkillToolUI.tsx +10 -9
  24. package/src/chat/tool-ui/RunJsToolUI.tsx +8 -7
  25. package/src/chat/tool-ui/ToolUiTrailing.tsx +3 -3
  26. package/src/chat/tool-ui/WebFetchToolUI.tsx +10 -9
  27. package/src/codeblock/CodeBlock.tsx +1 -1
  28. package/src/desktop/DesktopIcon.tsx +3 -4
  29. package/src/icon/Icon.tsx +21 -0
  30. package/src/icon/glyphs.ts +35 -0
  31. package/src/index.ts +6 -20
  32. package/src/input/EditableInput.tsx +2 -2
  33. package/src/markdown-editor/MarkdownEditor.tsx +4 -4
  34. package/src/markdown-editor/MarkdownPreview.tsx +4 -4
  35. package/src/markdown-editor/MarkdownTable.tsx +48 -11
  36. package/src/markdown-editor/MarkdownViewer.tsx +25 -28
  37. package/src/markdown-editor/MermaidBlock.tsx +4 -4
  38. package/src/markdown-editor/ReactCodeFrame.tsx +2 -2
  39. package/src/markdown-editor/ReactCodeSandbox.tsx +2 -2
  40. package/src/markdown-editor/markdownScale.ts +65 -131
  41. package/src/menu/Menu.tsx +2 -2
  42. package/src/pagination/Pagination.tsx +4 -4
  43. package/src/scroll/OverlayScroll.tsx +13 -5
  44. package/src/sidebar/Sidebar.tsx +5 -5
  45. package/src/styles.css +36 -16
  46. package/src/tabs/Tabs.tsx +75 -13
  47. package/src/theme-switcher/ThemeSwitcher.tsx +6 -6
  48. package/src/typography/Typography.tsx +4 -4
  49. package/src/icon/SolarIcon.tsx +0 -39
  50. package/src/icon/solar.ts +0 -172
package/src/index.ts CHANGED
@@ -17,6 +17,8 @@ export type { AlertProps, AlertType } from "./alert/Alert";
17
17
  export { Alert } from "./alert/Alert";
18
18
  export type { AgentAvatarConfig, AgentAvatarEyeColor, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
19
19
  export { AGENT_AVATAR_PARTS, AgentAvatar } from "./avatar/AgentAvatar";
20
+ export type { BlobShapeAppearance, BlobShapeProps, BlobShapeVariant } from "./blob-shape/BlobShape";
21
+ export { BlobShape } from "./blob-shape/BlobShape";
20
22
  export type { CalendarProps } from "./calendar/Calendar";
21
23
  export { Calendar } from "./calendar/Calendar";
22
24
  export type { CardFooterProps, CardItemProps, CardProps } from "./card/Card";
@@ -28,6 +30,7 @@ export type {
28
30
  AgentMessageRole,
29
31
  AgentPanelEndpoint,
30
32
  AgentPanelProps,
33
+ AgentSseCallbacks,
31
34
  AgentStreamRequest,
32
35
  AgentToolCallEvent,
33
36
  AgentToolHook,
@@ -134,25 +137,8 @@ export {
134
137
  export type { FormLayoutItemProps, FormLayoutProps } from "./form-layout/FormLayout";
135
138
  /** Layout-only Form + Form.Item for labeled fields. */
136
139
  export { Form } from "./form-layout/FormLayout";
137
- export { FluentIcon, SolarIcon } from "./icon/SolarIcon";
138
- export {
139
- DEFAULT_ICON_NAME,
140
- DEFAULT_TOOL_ICON,
141
- ensureSolarIcons,
142
- ensureSolarIcons as ensureFluentIcons,
143
- getIconNames,
144
- getSolarImgSrc,
145
- getSolarImgSrc as getFluentImgSrc,
146
- getSolarSvg,
147
- ICON_PREFIX,
148
- isSolarIcon,
149
- isSolarIcon as isFluentIcon,
150
- isSvgIcon,
151
- solarIconName,
152
- solarIconName as fluentIconName,
153
- solarIconRef,
154
- solarIconRef as fluentIconRef,
155
- } from "./icon/solar";
140
+ export type { IconName } from "./icon/Icon";
141
+ export { Icon } from "./icon/Icon";
156
142
  export { cn } from "./lib/cn";
157
143
  export type { PopperPlacement } from "./lib/placement";
158
144
  export { placementToRadix } from "./lib/placement";
@@ -163,7 +149,7 @@ export type { LogoProps, LogoVariant } from "./logo/Logo";
163
149
  export { Logo } from "./logo/Logo";
164
150
  export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
165
151
  export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
166
- export type { MarkdownVariant, MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
152
+ export type { MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
167
153
  export { MarkdownViewer } from "./markdown-editor/MarkdownViewer";
168
154
  export type { MermaidBlockProps } from "./markdown-editor/MermaidBlock";
169
155
  export { MermaidBlock } from "./markdown-editor/MermaidBlock";
@@ -2,7 +2,7 @@ import { type CSSProperties, cloneElement, isValidElement, type KeyboardEvent, t
2
2
  import { createPortal } from "react-dom";
3
3
  import { usePopupContainer } from "../app/context";
4
4
  import { Button } from "../button/Button";
5
- import { SolarIcon } from "../icon/SolarIcon";
5
+ import { Icon } from "../icon/Icon";
6
6
  import { cn } from "../lib/cn";
7
7
  import { type CanonicalSize, type ControlSize, controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
8
8
  import { glassSurfaceClass } from "../lib/surface";
@@ -228,7 +228,7 @@ function EditButton({ label, size, onClick }: { label: string; size: CanonicalSi
228
228
  className="inline-flex shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity hover:bg-muted hover:text-foreground group-hover/edit:opacity-100 focus-visible:opacity-100"
229
229
  style={{ width: box, height: box }}
230
230
  >
231
- <SolarIcon name="pen-linear" size={tok.icon} />
231
+ <Icon name="pen" size={tok.icon} />
232
232
  </button>
233
233
  );
234
234
  }
@@ -1,5 +1,5 @@
1
1
  import { type CSSProperties, type MouseEvent, type ReactNode, useCallback, useMemo, useRef, useState } from "react";
2
- import { SolarIcon } from "../icon/SolarIcon";
2
+ import { Icon } from "../icon/Icon";
3
3
  import { cn } from "../lib/cn";
4
4
  import { Segmented } from "../segmented/Segmented";
5
5
  import { appendTextBlock, cleanupDoc, joinMarkdownDoc, type MarkdownDoc, parseMarkdownDoc, readInlineEdit, splitListItem } from "./blocks";
@@ -268,9 +268,9 @@ export function MarkdownEditor({
268
268
  value={mode}
269
269
  onChange={changeMode}
270
270
  options={[
271
- { label: "Preview", value: "preview", icon: <SolarIcon name="eye-linear" size={14} /> },
272
- { label: "Edit", value: "edit", icon: <SolarIcon name="pen-linear" size={14} /> },
273
- { label: "Diff", value: "diff", icon: <SolarIcon name="transfer-horizontal-linear" size={14} />, disabled: original === undefined },
271
+ { label: "Preview", value: "preview", icon: <Icon name="eye" size={14} /> },
272
+ { label: "Edit", value: "edit", icon: <Icon name="pen" size={14} /> },
273
+ { label: "Diff", value: "diff", icon: <Icon name="transfer" size={14} />, disabled: original === undefined },
274
274
  ]}
275
275
  />
276
276
  ) : null}
@@ -2,7 +2,7 @@ import { type MouseEvent, useLayoutEffect, useRef } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
  import { OverlayScroll } from "../scroll/OverlayScroll";
4
4
  import { type MarkdownDoc, readInlineEdit, writeInlineEdit } from "./blocks";
5
- import { BlockBody, headingClass, ListItem, markdownVariantStyle, spaceBefore } from "./MarkdownViewer";
5
+ import { BlockBody, headingClass, ListItem, markdownScaleStyle, spaceBefore } from "./MarkdownViewer";
6
6
 
7
7
  function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur, onEnter }: { value: string; mono?: boolean; className?: string; caret?: "start" | "end"; onChange: (value: string) => void; onBlur: () => void; onEnter?: (before: string, after: string) => void }) {
8
8
  const ref = useRef<HTMLTextAreaElement>(null);
@@ -57,8 +57,8 @@ function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur,
57
57
  });
58
58
  }}
59
59
  className={cn(
60
- "block w-full resize-none overflow-hidden border-0 bg-transparent p-0 text-(length:--md-body-size,16px) leading-(--md-body-leading,24px) text-foreground shadow-none outline-none ring-0 placeholder:text-quaternary-foreground focus:outline-none focus:ring-0",
61
- mono && "font-mono text-(length:--md-code-size,14px) leading-(--md-code-leading,22px)",
60
+ "block w-full resize-none overflow-hidden border-0 bg-transparent p-0 text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-body-leading,calc(var(--nonla-md-text-size,16px)*1.6)) text-foreground shadow-none outline-none ring-0 placeholder:text-quaternary-foreground focus:outline-none focus:ring-0",
61
+ mono && "font-mono text-(length:--md-code-size,var(--nonla-mono-text-size)) leading-(--md-code-leading,calc(var(--nonla-mono-text-size)*1.6))",
62
62
  className,
63
63
  )}
64
64
  aria-label="Edit markdown"
@@ -88,7 +88,7 @@ export type MarkdownPreviewProps = {
88
88
  export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Write markdown…", onStartEdit, onEditMouseDown, onChangeBody, onBlurBlock, onEnterList, caret = "end", onAppend }: MarkdownPreviewProps) {
89
89
  return (
90
90
  <OverlayScroll className="h-full bg-card">
91
- <div className="mx-auto flex w-full max-w-3xl flex-col px-8 py-6" style={markdownVariantStyle("docs")}>
91
+ <div className="mx-auto flex w-full max-w-3xl flex-col px-8 py-6" style={markdownScaleStyle}>
92
92
  {doc.blocks.map((block, index) => {
93
93
  const editing = editingIndex === index;
94
94
  const locked = block.kind === "mermaid" || readOnly;
@@ -1,5 +1,8 @@
1
1
  import { type ReactNode, useCallback, useRef } from "react";
2
+ import { Button } from "../button/Button";
2
3
  import { ButtonCopy } from "../button/ButtonCopy";
4
+ import { Icon } from "../icon/Icon";
5
+ import { OverlayScroll } from "../scroll/OverlayScroll";
3
6
 
4
7
  function escapeCell(text: string): string {
5
8
  return text.replace(/\|/g, "\\|").replace(/\n+/g, "").trim();
@@ -20,26 +23,60 @@ function tableToMarkdown(table: HTMLTableElement): string {
20
23
  return [`| ${header.join(" | ")} |`, `| ${separator.join(" | ")} |`, ...body.map((row) => `| ${row.join(" | ")} |`)].join("\n");
21
24
  }
22
25
 
26
+ const tableClass =
27
+ "w-max min-w-full border-separate border-spacing-0 text-base [&_th]:whitespace-normal [&_td]:whitespace-normal [&_th]:wrap-normal [&_td]:wrap-normal [&_th]:border-b [&_th]:border-border-secondary [&_th]:px-4 [&_th]:py-1.5 [&_th]:text-left [&_th]:align-top [&_th]:font-medium [&_td]:border-b [&_td]:border-border-secondary [&_td]:px-4 [&_td]:py-1.5 [&_td]:align-top";
28
+
23
29
  export function MarkdownTable({ children }: { children: ReactNode }) {
24
30
  const tableRef = useRef<HTMLTableElement>(null);
31
+ const dialogRef = useRef<HTMLDialogElement>(null);
25
32
 
26
33
  const getText = useCallback(() => {
27
34
  const table = tableRef.current;
28
35
  return table ? tableToMarkdown(table) : "";
29
36
  }, []);
30
37
 
38
+ const openFullscreen = () => {
39
+ dialogRef.current?.showModal();
40
+ };
41
+
42
+ const closeFullscreen = () => {
43
+ dialogRef.current?.close();
44
+ };
45
+
31
46
  return (
32
- <div className="relative my-(--md-table-my,16px) max-w-full overflow-hidden rounded-xl border border-border bg-card group">
33
- <ButtonCopy getText={getText} label="Copy as Markdown" className="absolute top-1 right-1 z-10 opacity-0 group-hover:opacity-100" />
34
-
35
- <div className="overflow-x-auto">
36
- <table
37
- ref={tableRef}
38
- className="w-max min-w-full border-separate border-spacing-0 text-(length:--md-table-size,15px) [&_th]:max-w-[360px] [&_td]:max-w-[360px] [&_th]:whitespace-normal [&_td]:whitespace-normal [&_th]:wrap-normal [&_td]:wrap-normal [&_th]:bg-muted [&_th]:font-semibold [&_th]:px-2.5 [&_th]:py-1.5 [&_th]:text-left [&_th]:align-top [&_th]:border-r [&_th]:border-b [&_th]:border-border [&_th:last-child]:border-r-0 [&_td]:px-2.5 [&_td]:py-1.5 [&_td]:align-top [&_td]:bg-card [&_td]:border-r [&_td]:border-b [&_td]:border-border [&_td:last-child]:border-r-0 [&_tbody_tr:last-child_td]:border-b-0"
39
- >
40
- {children}
41
- </table>
47
+ <>
48
+ <div className="group relative my-(--md-table-my,16px) max-w-full">
49
+ <div className="absolute top-1 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100">
50
+ <ButtonCopy getText={getText} label="Copy as Markdown" />
51
+ <Button size="small" icon={<Icon name="maximize" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
52
+ </div>
53
+
54
+ <OverlayScroll autoHeight visibility="hover" scope="table" innerClassName="overflow-x-auto">
55
+ <table ref={tableRef} className={`${tableClass} [&_th]:max-w-[360px] [&_td]:max-w-[360px] [&_th:first-child]:pl-0 [&_th:last-child]:pr-0 [&_td:first-child]:pl-0 [&_td:last-child]:pr-0`}>
56
+ {children}
57
+ </table>
58
+ </OverlayScroll>
42
59
  </div>
43
- </div>
60
+
61
+ <dialog
62
+ ref={dialogRef}
63
+ className="inset-2.5 m-0 h-auto w-auto max-h-none max-w-none overflow-hidden rounded-xl border border-foreground/25 bg-card p-0 shadow-xl backdrop:bg-black/40 open:flex open:flex-col"
64
+ onKeyDown={(e) => {
65
+ if (e.key !== "Escape") return;
66
+ e.preventDefault();
67
+ e.stopPropagation();
68
+ closeFullscreen();
69
+ }}
70
+ >
71
+ <div className="absolute top-5 right-5 z-50 flex items-center gap-1.5">
72
+ <ButtonCopy getText={getText} label="Copy as Markdown" />
73
+ <Button size="small" icon={<Icon name="minimize" size={12} />} title="Exit fullscreen" aria-label="Exit fullscreen" onClick={closeFullscreen} />
74
+ </div>
75
+
76
+ <div className="min-h-0 flex-1 overflow-auto p-8">
77
+ <table className={tableClass}>{children}</table>
78
+ </div>
79
+ </dialog>
80
+ </>
44
81
  );
45
82
  }
@@ -1,4 +1,4 @@
1
- import { type ReactNode, useMemo } from "react";
1
+ import { type CSSProperties, type ReactNode, useMemo } from "react";
2
2
  import ReactMarkdown, { type Components } from "react-markdown";
3
3
  import remarkGfm from "remark-gfm";
4
4
  import { Checkbox } from "../checkbox/Checkbox";
@@ -7,37 +7,35 @@ import { cn } from "../lib/cn";
7
7
  import { type InlineEdit, type MarkdownBlock, parseMarkdownDoc, readFence, readInlineEdit } from "./blocks";
8
8
  import { MarkdownTable } from "./MarkdownTable";
9
9
  import { MermaidBlock } from "./MermaidBlock";
10
- import { headingClass, type MarkdownVariant, markdownVariantStyle } from "./markdownScale";
10
+ import { headingClass, markdownScaleStyle } from "./markdownScale";
11
11
  import { ReactCode } from "./ReactCode";
12
12
  import { ReactCodeSandbox } from "./ReactCodeSandbox";
13
13
 
14
- export type { MarkdownVariant };
15
- export { headingClass, markdownVariantStyle };
14
+ export { headingClass, markdownScaleStyle };
16
15
 
17
16
  /** Task checks use the body ink, so a checked box sits with the text instead of the brand fill. */
18
17
  const taskCheckClass =
19
18
  "data-[state=checked]:border-foreground! data-[state=checked]:bg-foreground! data-[state=checked]:text-background! data-[state=indeterminate]:border-foreground! data-[state=indeterminate]:bg-foreground! data-[state=indeterminate]:text-background!";
20
19
 
21
20
  const documentClass = cn(
22
- "min-w-0 wrap-anywhere text-(length:--md-body-size,16px) leading-(--md-body-leading,24px) text-foreground",
21
+ "min-w-0 wrap-anywhere text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-body-leading,calc(var(--nonla-md-text-size,16px)*1.6)) text-foreground",
23
22
  "[&_:is(h1,h2,h3,h4,h5,h6)]:text-foreground",
24
- "[&_:is(h1,h2)]:mt-(--md-h2-mt,24px) [&_h1]:mb-(--md-h1-mb,12px) [&_h2]:mb-(--md-h2-mb,1px) [&_:is(h1,h2)]:pt-(--md-h2-py,3px) [&_:is(h1,h2)]:pb-(--md-h2-py,3px) [&_:is(h1,h2)]:text-(length:--md-h2-size,30px) [&_:is(h1,h2)]:leading-(--md-h2-leading,40px) [&_:is(h1,h2)]:font-(--md-h2-weight,700) [&_:is(h1,h2)]:tracking-normal",
25
- "[&_h3]:mt-(--md-h3-mt,22px) [&_h3]:mb-(--md-h3-mb,1px) [&_h3]:text-(length:--md-h3-size,24px) [&_h3]:leading-(--md-h3-leading,32px) [&_h3]:font-(--md-h3-weight,700)",
26
- "[&_h4]:mt-(--md-h4-mt,16px) [&_h4]:mb-(--md-h4-mb,1px) [&_h4]:text-(length:--md-h4-size,20px) [&_h4]:leading-(--md-h4-leading,26px) [&_h4]:font-(--md-h4-weight,700)",
27
- "[&_h5]:mt-(--md-h5-mt,0px) [&_h5]:mb-(--md-h5-mb,0px) [&_h5]:text-(length:--md-h5-size,16px) [&_h5]:leading-(--md-h5-leading,1.375) [&_h5]:font-(--md-h5-weight,700)",
28
- "[&_h6]:mt-(--md-h6-mt,0px) [&_h6]:mb-(--md-h6-mb,0px) [&_h6]:text-(length:--md-h6-size,14px) [&_h6]:leading-(--md-h6-leading,1.375) [&_h6]:font-(--md-h6-weight,700)",
29
- "[&_p]:my-(--md-p-my,1px) [&_p]:py-(--md-p-py,4px) [&_p]:leading-(--md-p-leading,1.5)",
23
+ "[&_:is(h1,h2)]:mt-(--md-h2-mt,24px) [&_h1]:mb-(--md-h1-mb,12px) [&_h2]:mb-(--md-h2-mb,8px) [&_:is(h1,h2)]:pt-(--md-h2-py,3px) [&_:is(h1,h2)]:pb-(--md-h2-py,3px) [&_:is(h1,h2)]:text-(length:--md-h2-size,26px) [&_:is(h1,h2)]:leading-(--md-h2-leading,32px) [&_:is(h1,h2)]:font-(--md-h2-weight,600) [&_:is(h1,h2)]:tracking-normal",
24
+ "[&_h3]:mt-(--md-h3-mt,22px) [&_h3]:mb-(--md-h3-mb,8px) [&_h3]:text-(length:--md-h3-size,24px) [&_h3]:leading-(--md-h3-leading,32px) [&_h3]:font-(--md-h3-weight,600)",
25
+ "[&_:is(h4,h5,h6)]:mt-(--md-h4-mt,16px) [&_:is(h4,h5,h6)]:mb-(--md-h4-mb,1px) [&_:is(h4,h5,h6)]:text-(length:--md-h4-size,20px) [&_:is(h4,h5,h6)]:leading-(--md-h4-leading,26px) [&_:is(h4,h5,h6)]:font-(--md-h4-weight,700)",
26
+ "[&_p]:my-(--md-p-my,1px) [&_p]:py-(--md-p-py,4px) [&_p]:leading-(--md-p-leading,1.6)",
30
27
  "[&_ul]:my-(--md-list-my,8px) [&_ul]:list-disc [&_ul]:pl-(--md-ul-pl,4px)",
31
28
  "[&_ol]:my-(--md-list-my,8px) [&_ol]:list-decimal [&_ol]:pl-(--md-ol-pl,4px)",
32
29
  "[&_li>ul]:mt-1 [&_li>ol]:mt-1 [&_li>ol]:pl-(--md-nest,1.25rem)",
33
30
  "[&_th_ul]:my-0 [&_td_ul]:my-0 [&_th_ol]:my-0 [&_td_ol]:my-0 [&_th_li]:mt-0 [&_td_li]:mt-0 [&_th_li>ul]:mt-0.5 [&_td_li>ul]:mt-0.5 [&_th_li>ol]:mt-0.5 [&_td_li>ol]:mt-0.5 [&_th_li>p]:my-0 [&_td_li>p]:my-0",
34
31
  "[&_ul.contains-task-list]:list-none",
35
- "[&_li]:mt-(--md-li-mt,4px) [&_li]:leading-[1.5]",
32
+ "[&_li]:mt-(--md-li-mt,4px) [&_li]:leading-[1.6]",
36
33
  "[&_li.task-list-item]:relative",
37
34
  "[&_li.task-list-item>.nonla-md-task-check]:absolute [&_li.task-list-item>.nonla-md-task-check]:top-1 [&_li.task-list-item>.nonla-md-task-check]:-left-5",
38
- "[&_blockquote]:my-(--md-quote-my,4px) [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground",
35
+ /* Body paragraphs sit in separate blocks, so their margins do not collapse. Quote paragraphs share one block, so the next paragraph's top margin is doubled to land on that same gap. */
36
+ "[&_blockquote]:my-(--md-quote-my,0px) [&_blockquote>p:not(:first-child)]:mt-[calc(var(--md-p-my,1px)*2)] [&_blockquote>p:not(:last-child)]:mb-0 [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-foreground",
39
37
  "[&_a]:text-link [&_a]:underline-offset-[3px] hover:[&_a]:underline",
40
- "[&_hr]:my-(--md-rule-my,8px) [&_hr]:border-border",
38
+ "[&_hr]:hidden",
41
39
  "[&_strong]:font-(--md-strong-weight,600)",
42
40
  "[&_img]:my-(--md-img-my,4px) [&_img]:max-w-full [&_img]:rounded-lg",
43
41
  );
@@ -49,7 +47,7 @@ const previewComponents: Components = {
49
47
  const codeText = String(children).replace(/\n$/, "");
50
48
  const isBlock = codeText.includes("\n") || !!match;
51
49
  if (!isBlock) {
52
- return <code className="nonla-inline-code rounded-sm bg-muted px-[0.35em] py-[0.12em] align-baseline font-mono text-(length:--md-inline-size,14px) leading-none whitespace-nowrap [box-decoration-break:clone] [-webkit-box-decoration-break:clone]">{children}</code>;
50
+ return <code className="nonla-inline-code rounded-[4px] bg-muted px-[2px] py-px align-baseline font-mono text-(length:--md-inline-size,var(--nonla-mono-text-size)) leading-none whitespace-nowrap [box-decoration-break:clone] [-webkit-box-decoration-break:clone]">{children}</code>;
53
51
  }
54
52
  if (lang.toLowerCase() === "mermaid") return <MermaidView code={codeText} />;
55
53
  return <CodeBlock code={codeText} language={lang || undefined} className="my-(--md-code-my,8px)" />;
@@ -67,7 +65,7 @@ const previewComponents: Components = {
67
65
  input({ type, checked }) {
68
66
  if (type !== "checkbox") return <input type={type} checked={checked} readOnly />;
69
67
  return (
70
- <span className="nonla-md-task-check pointer-events-none inline-flex h-(--md-body-leading,24px) items-center">
68
+ <span className="nonla-md-task-check pointer-events-none inline-flex h-(--md-body-leading,calc(var(--nonla-md-text-size,16px)*1.6)) items-center">
71
69
  <Checkbox checked={Boolean(checked)} tabIndex={-1} className={taskCheckClass} />
72
70
  </span>
73
71
  );
@@ -137,7 +135,7 @@ function RichText({ source }: { source: string }) {
137
135
  export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind: "list" }>; children: ReactNode }) {
138
136
  const level = Math.floor(view.indent.length / 2);
139
137
  const ordinal = Number(/^(\d+)/.exec(view.marker)?.[1] ?? "1");
140
- const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,16px) leading-(--md-p-leading,1.5)";
138
+ const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-p-leading,1.6)";
141
139
  return (
142
140
  <div className="flex items-start gap-1.5 pl-(--md-item-pl,4px)" style={level > 0 ? { marginLeft: `calc(${level} * var(--md-nest, 1.25rem))` } : undefined}>
143
141
  {view.task ? (
@@ -162,14 +160,13 @@ function isListBlock(block: MarkdownBlock): boolean {
162
160
  return block.kind === "text" && readInlineEdit(block.body).kind === "list";
163
161
  }
164
162
 
165
- export function spaceBefore(block: MarkdownBlock, prev?: MarkdownBlock, variant: MarkdownVariant = "docs"): string {
166
- const chat = variant === "chat";
163
+ export function spaceBefore(block: MarkdownBlock, prev?: MarkdownBlock): string {
167
164
  if (!prev) return "";
168
- if (isListBlock(block) && isListBlock(prev)) return chat ? "mt-px" : "mt-0.5";
169
- if (prev.kind === "text" && readInlineEdit(prev.body).kind === "heading") return "[&_p]:mt-0! [&_p]:pt-0.5!";
170
- if (isListBlock(block) && prev.kind === "text") return chat ? "mt-0.5" : "mt-1";
165
+ if (isListBlock(block) && isListBlock(prev)) return "mt-0.5";
166
+ if (prev.kind === "text" && readInlineEdit(prev.body).kind === "heading") return "[&_p:first-child]:mt-0! [&_p:first-child]:pt-0.5!";
167
+ if (isListBlock(block) && prev.kind === "text") return "mt-1";
171
168
  if (block.kind === "text" && prev.kind === "text") return "";
172
- return chat ? "mt-2" : "mt-3";
169
+ return "mt-3";
173
170
  }
174
171
 
175
172
  function fenceClosed(body: string): boolean {
@@ -235,24 +232,24 @@ export type MarkdownViewerProps = {
235
232
  showHeader?: boolean;
236
233
  /** Switch that opens the source of a `live-react` preview. Needs `showHeader`. Default `true`. */
237
234
  showCode?: boolean;
238
- /** `docs` is the article scale. `chat` tightens size and spacing for a thread. Default `docs`. */
239
- variant?: MarkdownVariant;
235
+ /** Overrides scale variables from `markdownScaleStyle`, such as heading size. */
236
+ style?: CSSProperties;
240
237
  };
241
238
 
242
239
  /** Read-only markdown. Same blocks as the editor preview, without editing. */
243
- export function MarkdownViewer({ value = "", streaming = false, sandboxSrc, trustedModules, showHeader = true, showCode = true, placeholder, className, variant = "docs" }: MarkdownViewerProps) {
240
+ export function MarkdownViewer({ value = "", streaming = false, sandboxSrc, trustedModules, showHeader = true, showCode = true, placeholder, className, style }: MarkdownViewerProps) {
244
241
  const doc = useMemo(() => parseMarkdownDoc(value), [value]);
245
242
  if (doc.blocks.length === 0) {
246
243
  return placeholder ? <p className={cn("m-0 text-sm text-quaternary-foreground", className)}>{placeholder}</p> : null;
247
244
  }
248
245
  return (
249
- <div data-variant={variant} className={cn("nonla-markdown-viewer flex min-w-0 flex-col text-foreground", variant === "chat" && "[&>[data-md-block]:first-child_:is(h1,h2,h3,h4,h5,h6)]:mt-0", className)} style={markdownVariantStyle(variant)}>
246
+ <div className={cn("nonla-markdown-viewer flex min-w-0 flex-col text-foreground", className)} style={{ ...markdownScaleStyle, ...style }}>
250
247
  {doc.blocks.map((block, index) => (
251
248
  <div
252
249
  // biome-ignore lint/suspicious/noArrayIndexKey: block position is the document identity
253
250
  key={`${index}:${block.kind}`}
254
251
  data-md-block={block.kind}
255
- className={cn("outline-none", spaceBefore(block, doc.blocks[index - 1], variant))}
252
+ className={cn("outline-none", spaceBefore(block, doc.blocks[index - 1]))}
256
253
  >
257
254
  <BlockBody block={block} streaming={streaming} trustedModules={trustedModules} sandboxSrc={sandboxSrc} showHeader={showHeader} showCode={showCode} />
258
255
  </div>
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
2
2
  import { Button } from "../button/Button";
3
3
  import { CodeBlock } from "../codeblock/CodeBlock";
4
- import { SolarIcon } from "../icon/SolarIcon";
4
+ import { Icon } from "../icon/Icon";
5
5
  import { cn } from "../lib/cn";
6
6
  import { getColorMode, subscribeColorMode } from "../theme";
7
7
  import { sanitizeMermaid } from "./sanitizeMermaid";
@@ -191,7 +191,7 @@ export function MermaidBlock({ children, className }: MermaidBlockProps) {
191
191
  <>
192
192
  <div className={cn("my-3 last:mb-0 group relative overflow-hidden rounded-xl bg-card", className)}>
193
193
  <div className="absolute top-2 right-2 z-10 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
194
- <Button size="small" icon={<SolarIcon name="maximize-linear" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
194
+ <Button size="small" icon={<Icon name="maximize" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
195
195
  </div>
196
196
  <div ref={containerRef} className="flex justify-center p-6 overflow-x-auto [&_svg]:max-w-full" />
197
197
  </div>
@@ -208,8 +208,8 @@ export function MermaidBlock({ children, className }: MermaidBlockProps) {
208
208
  }}
209
209
  >
210
210
  <div className="absolute top-5 right-5 z-50 flex items-center gap-1.5">
211
- <Button size="small" icon={<SolarIcon name="download-linear" size={12} />} title="Download SVG" aria-label="Download SVG" onClick={downloadSvg} disabled={!svgContent} />
212
- <Button size="small" icon={<SolarIcon name="minimize-linear" size={12} />} title="Exit fullscreen" onClick={closeFullscreen}>
211
+ <Button size="small" icon={<Icon name="download" size={12} />} title="Download SVG" aria-label="Download SVG" onClick={downloadSvg} disabled={!svgContent} />
212
+ <Button size="small" icon={<Icon name="minimize" size={12} />} title="Exit fullscreen" onClick={closeFullscreen}>
213
213
  Exit
214
214
  </Button>
215
215
  </div>
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode, useState } from "react";
2
2
  import { CodeBlock } from "../codeblock/CodeBlock";
3
- import { SolarIcon } from "../icon/SolarIcon";
3
+ import { Icon } from "../icon/Icon";
4
4
  import { cn } from "../lib/cn";
5
5
  import { Segmented } from "../segmented/Segmented";
6
6
  import { Tooltip } from "../tooltip/Tooltip";
@@ -61,7 +61,7 @@ export function ReactCodeFrame({ title, icon, showHeader = true, code, className
61
61
  )}
62
62
  onClick={() => setOpen((value) => !value)}
63
63
  >
64
- <SolarIcon name="code-square-linear" size={16} />
64
+ <Icon name="code" size={16} />
65
65
  </button>
66
66
  </Tooltip>
67
67
  </div>
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
2
- import { SolarIcon } from "../icon/SolarIcon";
2
+ import { Icon } from "../icon/Icon";
3
3
  import { cn } from "../lib/cn";
4
4
  import { getColorMode, type NonlaColorMode, subscribeColorMode } from "../theme";
5
5
  import { ReactCodeFrame } from "./ReactCodeFrame";
@@ -136,7 +136,7 @@ export function ReactCodeSandbox({ code, src, showHeader = true, showCode = true
136
136
  return (
137
137
  <ReactCodeFrame
138
138
  title={title}
139
- icon={icon === undefined ? <SolarIcon name="shield-check-linear" size={16} className="text-success" /> : icon}
139
+ icon={icon === undefined ? <Icon name="shield-check" size={16} className="text-success" /> : icon}
140
140
  showHeader={showHeader}
141
141
  code={showCode ? code : undefined}
142
142
  className={className}
@@ -1,149 +1,83 @@
1
1
  import type { CSSProperties } from "react";
2
2
 
3
- /** `docs` is the article scale. `chat` is the tighter thread scale. */
4
- export type MarkdownVariant = "docs" | "chat";
5
-
6
3
  /**
7
- * Size and spacing for each scale. Class fallbacks match `docs`, so the editor
8
- * preview stays on the article scale when no preset is set.
9
- * Docs body reads `--nonla-base-text-size` (16px, leading 1.5). Chat body, headings, table, and inline code are 14px.
10
- * Fenced code is 14px.
4
+ * One markdown scale. Body reads `text-md` (`--nonla-md-text-size`). Leading is 1.6.
5
+ * Tables always use `text-base`.
6
+ * Inline code and fenced code read `--nonla-mono-text-size`.
7
+ * Class fallbacks match these values when the variables are not set.
11
8
  */
12
- const MARKDOWN_PRESETS = {
13
- docs: {
14
- "--md-body-size": "var(--nonla-base-text-size, 16px)",
15
- "--md-body-leading": "calc(var(--nonla-base-text-size, 16px) * 1.5)",
16
- "--md-h1-size": "32px",
17
- "--md-h1-leading": "1.25",
18
- "--md-h1-weight": "800",
19
- "--md-h1-mt": "0px",
20
- "--md-h1-mb": "12px",
21
- "--md-h1-py": "3px",
22
- "--md-h2-size": "30px",
23
- "--md-h2-leading": "40px",
24
- "--md-h2-weight": "700",
25
- "--md-h2-mt": "24px",
26
- "--md-h2-mb": "1px",
27
- "--md-h2-py": "3px",
28
- "--md-h3-size": "24px",
29
- "--md-h3-leading": "32px",
30
- "--md-h3-weight": "700",
31
- "--md-h3-mt": "22px",
32
- "--md-h3-mb": "1px",
33
- "--md-h4-size": "20px",
34
- "--md-h4-leading": "26px",
35
- "--md-h4-weight": "700",
36
- "--md-h4-mt": "16px",
37
- "--md-h4-mb": "1px",
38
- "--md-h5-size": "16px",
39
- "--md-h5-leading": "1.375",
40
- "--md-h5-weight": "700",
41
- "--md-h5-mt": "0px",
42
- "--md-h5-mb": "0px",
43
- "--md-h6-size": "14px",
44
- "--md-h6-leading": "1.375",
45
- "--md-h6-weight": "700",
46
- "--md-h6-mt": "0px",
47
- "--md-h6-mb": "0px",
48
- "--md-strong-weight": "600",
49
- "--md-p-my": "1px",
50
- "--md-p-py": "4px",
51
- "--md-p-leading": "1.5",
52
- "--md-list-my": "8px",
53
- "--md-ul-pl": "4px",
54
- "--md-ol-pl": "4px",
55
- "--md-li-mt": "4px",
56
- "--md-quote-my": "4px",
57
- "--md-rule-my": "8px",
58
- "--md-img-my": "4px",
59
- "--md-table-my": "16px",
60
- "--md-table-size": "15px",
61
- "--md-code-my": "8px",
62
- "--md-code-size": "14px",
63
- "--md-code-leading": "22px",
64
- "--md-inline-size": "14px",
65
- "--md-item-pl": "4px",
66
- "--md-nest": "1.25rem",
67
- },
68
- chat: {
69
- "--md-body-size": "14px",
70
- "--md-body-leading": "22px",
71
- "--md-h1-size": "14px",
72
- "--md-h1-leading": "22px",
73
- "--md-h1-weight": "600",
74
- "--md-h1-mt": "0px",
75
- "--md-h1-mb": "2px",
76
- "--md-h1-py": "0px",
77
- "--md-h2-size": "14px",
78
- "--md-h2-leading": "22px",
79
- "--md-h2-weight": "600",
80
- "--md-h2-mt": "12px",
81
- "--md-h2-mb": "2px",
82
- "--md-h2-py": "0px",
83
- "--md-h3-size": "14px",
84
- "--md-h3-leading": "22px",
85
- "--md-h3-weight": "600",
86
- "--md-h3-mt": "10px",
87
- "--md-h3-mb": "2px",
88
- "--md-h4-size": "14px",
89
- "--md-h4-leading": "22px",
90
- "--md-h4-weight": "600",
91
- "--md-h4-mt": "8px",
92
- "--md-h4-mb": "2px",
93
- "--md-h5-size": "14px",
94
- "--md-h5-leading": "22px",
95
- "--md-h5-weight": "600",
96
- "--md-h5-mt": "6px",
97
- "--md-h5-mb": "0px",
98
- "--md-h6-size": "14px",
99
- "--md-h6-leading": "22px",
100
- "--md-h6-weight": "600",
101
- "--md-h6-mt": "6px",
102
- "--md-h6-mb": "0px",
103
- "--md-strong-weight": "400",
104
- "--md-p-my": "0px",
105
- "--md-p-py": "1px",
106
- "--md-p-leading": "1.5",
107
- "--md-list-my": "4px",
108
- "--md-ul-pl": "4px",
109
- "--md-ol-pl": "4px",
110
- "--md-li-mt": "2px",
111
- "--md-quote-my": "2px",
112
- "--md-rule-my": "6px",
113
- "--md-img-my": "4px",
114
- "--md-table-my": "8px",
115
- "--md-table-size": "14px",
116
- "--md-code-my": "6px",
117
- "--md-code-size": "14px",
118
- "--md-code-leading": "22px",
119
- "--md-inline-size": "14px",
120
- "--md-item-pl": "4px",
121
- "--md-nest": "1rem",
122
- },
123
- } as const;
124
-
125
- export function markdownVariantStyle(variant: MarkdownVariant = "docs"): CSSProperties {
126
- return MARKDOWN_PRESETS[variant] as CSSProperties;
127
- }
9
+ export const markdownScaleStyle = {
10
+ "--md-body-size": "var(--nonla-md-text-size)",
11
+ "--md-body-leading": "calc(var(--nonla-md-text-size) * 1.6)",
12
+ "--md-h1-size": "32px",
13
+ "--md-h1-leading": "1.25",
14
+ "--md-h1-weight": "800",
15
+ "--md-h1-mt": "0px",
16
+ "--md-h1-mb": "12px",
17
+ "--md-h1-py": "3px",
18
+ "--md-h2-size": "26px",
19
+ "--md-h2-leading": "32px",
20
+ "--md-h2-weight": "600",
21
+ "--md-h2-mt": "24px",
22
+ "--md-h2-mb": "8px",
23
+ "--md-h2-py": "3px",
24
+ "--md-h3-size": "24px",
25
+ "--md-h3-leading": "32px",
26
+ "--md-h3-weight": "600",
27
+ "--md-h3-mt": "22px",
28
+ "--md-h3-mb": "8px",
29
+ "--md-h4-size": "20px",
30
+ "--md-h4-leading": "26px",
31
+ "--md-h4-weight": "700",
32
+ "--md-h4-mt": "16px",
33
+ "--md-h4-mb": "1px",
34
+ "--md-h5-size": "20px",
35
+ "--md-h5-leading": "26px",
36
+ "--md-h5-weight": "700",
37
+ "--md-h5-mt": "16px",
38
+ "--md-h5-mb": "1px",
39
+ "--md-h6-size": "20px",
40
+ "--md-h6-leading": "26px",
41
+ "--md-h6-weight": "700",
42
+ "--md-h6-mt": "16px",
43
+ "--md-h6-mb": "1px",
44
+ "--md-strong-weight": "600",
45
+ "--md-p-my": "1px",
46
+ "--md-p-py": "4px",
47
+ "--md-p-leading": "1.6",
48
+ "--md-list-my": "8px",
49
+ "--md-ul-pl": "4px",
50
+ "--md-ol-pl": "4px",
51
+ "--md-li-mt": "4px",
52
+ "--md-quote-my": "0px",
53
+ "--md-rule-my": "8px",
54
+ "--md-img-my": "4px",
55
+ "--md-table-my": "16px",
56
+ "--md-code-my": "8px",
57
+ "--md-code-size": "var(--nonla-mono-text-size)",
58
+ "--md-code-leading": "calc(var(--nonla-mono-text-size) * 1.6)",
59
+ "--md-inline-size": "var(--nonla-mono-text-size)",
60
+ "--md-item-pl": "4px",
61
+ "--md-nest": "1.25rem",
62
+ } as CSSProperties;
128
63
 
129
64
  /**
130
65
  * Article headings. A markdown `#` paints the same as `##`.
66
+ * `#####` and `######` paint the same as `####`.
131
67
  * The large page title is `pageTitleClass`, used by Typography only.
132
68
  */
133
69
  export function headingClass(level: number): string {
134
- if (level <= 1) return "text-foreground mt-(--md-h2-mt,24px) mb-(--md-h1-mb,12px) pt-(--md-h2-py,3px) pb-(--md-h2-py,3px) text-(length:--md-h2-size,30px) leading-(--md-h2-leading,40px) font-(--md-h2-weight,600)";
135
- if (level === 2) return "text-foreground mt-(--md-h2-mt,24px) mb-(--md-h2-mb,1px) pt-(--md-h2-py,3px) pb-(--md-h2-py,3px) text-(length:--md-h2-size,30px) leading-(--md-h2-leading,40px) font-(--md-h2-weight,600)";
136
- if (level === 3) return "text-foreground mt-(--md-h3-mt,22px) mb-(--md-h3-mb,1px) text-(length:--md-h3-size,24px) leading-(--md-h3-leading,32px) font-(--md-h3-weight,700)";
137
- if (level === 4) return "text-foreground mt-(--md-h4-mt,16px) mb-(--md-h4-mb,1px) text-(length:--md-h4-size,20px) leading-(--md-h4-leading,26px) font-(--md-h4-weight,700)";
138
- if (level === 5) return "text-foreground mt-(--md-h5-mt,0px) mb-(--md-h5-mb,0px) text-(length:--md-h5-size,16px) leading-(--md-h5-leading,1.375) font-(--md-h5-weight,700)";
139
- return "text-foreground mt-(--md-h6-mt,0px) mb-(--md-h6-mb,0px) text-(length:--md-h6-size,14px) leading-(--md-h6-leading,1.375) font-(--md-h6-weight,700)";
70
+ if (level <= 1) return "text-foreground mt-(--md-h2-mt,24px) mb-(--md-h1-mb,12px) pt-(--md-h2-py,3px) pb-(--md-h2-py,3px) text-(length:--md-h2-size,26px) leading-(--md-h2-leading,32px) font-(--md-h2-weight,600)";
71
+ if (level === 2) return "text-foreground mt-(--md-h2-mt,24px) mb-(--md-h2-mb,8px) pt-(--md-h2-py,3px) pb-(--md-h2-py,3px) text-(length:--md-h2-size,26px) leading-(--md-h2-leading,32px) font-(--md-h2-weight,600)";
72
+ if (level === 3) return "text-foreground mt-(--md-h3-mt,22px) mb-(--md-h3-mb,8px) text-(length:--md-h3-size,24px) leading-(--md-h3-leading,32px) font-(--md-h3-weight,600)";
73
+ return "text-foreground mt-(--md-h4-mt,16px) mb-(--md-h4-mb,1px) text-(length:--md-h4-size,20px) leading-(--md-h4-leading,26px) font-(--md-h4-weight,700)";
140
74
  }
141
75
 
142
76
  /** Landing and page title. Not used inside markdown. */
143
77
  export const pageTitleClass = "text-foreground mt-(--md-h1-mt,0px) mb-(--md-h1-mb,1px) pt-(--md-h1-py,3px) pb-(--md-h1-py,3px) text-(length:--md-h1-size,32px) leading-(--md-h1-leading,1.25) font-(--md-h1-weight,800) tracking-tight";
144
78
 
145
79
  /** Body line. Same size and color as a markdown paragraph. */
146
- export const markdownBodyClass = "text-(length:--md-body-size,16px) leading-(--md-body-leading,24px) text-foreground";
80
+ export const markdownBodyClass = "text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-body-leading,calc(var(--nonla-md-text-size,16px)*1.6)) text-foreground";
147
81
 
148
82
  /** Paragraph box. Same rhythm as `MarkdownViewer` `p`. */
149
- export const markdownParagraphClass = "nonla-typo m-0 my-(--md-p-my,1px) py-(--md-p-py,4px) text-(length:--md-body-size,16px) leading-(--md-p-leading,1.5) text-foreground";
83
+ export const markdownParagraphClass = "nonla-typo m-0 my-(--md-p-my,1px) py-(--md-p-py,4px) text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-p-leading,1.6) text-foreground";