devnonla-ui 0.16.0 → 0.17.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
@@ -23,4 +23,11 @@ export function Root() {
23
23
  }
24
24
  ```
25
25
 
26
+ Chat and markdown are separate entries. Theme tokens live on the `.nonla-ui` host that `App` renders, not on the rest of the page.
27
+
28
+ ```tsx
29
+ import { AgentPanel } from "devnonla-ui/chat";
30
+ import { MarkdownViewer } from "devnonla-ui/markdown";
31
+ ```
32
+
26
33
  Install, theme, and each control are in the [docs](https://devnonla.github.io/devnonla-ui/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -21,6 +21,8 @@
21
21
  ],
22
22
  "exports": {
23
23
  ".": "./src/index.ts",
24
+ "./markdown": "./src/markdown-editor/index.ts",
25
+ "./chat": "./src/chat/index.ts",
24
26
  "./styles.css": "./src/styles.css"
25
27
  },
26
28
  "main": "./src/index.ts",
package/src/app/App.tsx CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2
- import { type ReactNode, useMemo } from "react";
2
+ import { type ReactNode, useLayoutEffect, useMemo, useRef } from "react";
3
+ import { cn } from "../lib/cn";
3
4
  import { type ControlSize, ControlSizeContext, normalizeSize } from "../lib/sizes";
4
5
  import { MessageHolder, message } from "../message/message";
5
6
  import { ConfirmHolder, Modal } from "../modal/Modal";
6
- import { initColorMode } from "../theme";
7
+ import { bindColorModeTarget, initColorMode } from "../theme";
7
8
  import { AppContext, type NonlaAppConfig, useAppConfig, usePopupContainer } from "./context";
8
9
 
9
10
  export type { NonlaAppConfig };
@@ -14,25 +15,42 @@ export type AppProps = {
14
15
  getPopupContainer?: () => HTMLElement;
15
16
  /** Default control size (`componentSize`). Per-control `size` still wins. */
16
17
  componentSize?: ControlSize;
18
+ /** Extra classes on the `.nonla-ui` host. */
19
+ className?: string;
17
20
  };
18
21
 
19
- /** Root host for NonlaUI — ConfigProvider + message/modal holders. Mount once near app root. */
20
- export function App({ children, getPopupContainer, componentSize }: AppProps) {
21
- // Before children paint, so a sandbox iframe can open on the saved mode instead of flashing the default.
22
- initColorMode();
22
+ /** Root host for NonlaUI — theme scope + message/modal holders. Mount once near app root. */
23
+ export function App({ children, getPopupContainer, componentSize, className }: AppProps) {
24
+ const hostRef = useRef<HTMLDivElement>(null);
23
25
  const size = componentSize ? normalizeSize(componentSize) : undefined;
24
- const value = useMemo<NonlaAppConfig>(() => ({ getPopupContainer, componentSize: size }), [getPopupContainer, size]);
26
+ const value = useMemo<NonlaAppConfig>(
27
+ () => ({
28
+ getPopupContainer: getPopupContainer ?? (() => hostRef.current ?? document.body),
29
+ componentSize: size,
30
+ }),
31
+ [getPopupContainer, size],
32
+ );
33
+
34
+ useLayoutEffect(() => {
35
+ const host = hostRef.current;
36
+ if (!host) return;
37
+ bindColorModeTarget(host);
38
+ initColorMode(host);
39
+ return () => bindColorModeTarget(null);
40
+ }, []);
25
41
 
26
42
  return (
27
- <AppContext.Provider value={value}>
28
- <ControlSizeContext.Provider value={size}>
29
- <TooltipPrimitive.Provider delayDuration={100}>
30
- {children}
31
- <MessageHolder />
32
- <ConfirmHolder />
33
- </TooltipPrimitive.Provider>
34
- </ControlSizeContext.Provider>
35
- </AppContext.Provider>
43
+ <div ref={hostRef} className={cn("nonla-ui h-full min-h-0", className)}>
44
+ <AppContext.Provider value={value}>
45
+ <ControlSizeContext.Provider value={size}>
46
+ <TooltipPrimitive.Provider delayDuration={100}>
47
+ {children}
48
+ <MessageHolder />
49
+ <ConfirmHolder />
50
+ </TooltipPrimitive.Provider>
51
+ </ControlSizeContext.Provider>
52
+ </AppContext.Provider>
53
+ </div>
36
54
  );
37
55
  }
38
56
 
@@ -12,7 +12,7 @@ export function useAppConfig() {
12
12
  return useContext(AppContext);
13
13
  }
14
14
 
15
- /** Portal container for overlays (`getPopupContainer`). Always leaves the desktop stacking context. */
15
+ /** Portal container for overlays (`getPopupContainer`). Defaults to the `App` `.nonla-ui` host, then `document.body`. */
16
16
  export function usePopupContainer(override?: () => HTMLElement) {
17
17
  const { getPopupContainer } = useAppConfig();
18
18
  return () => (override ?? getPopupContainer)?.() ?? document.body;
@@ -1,17 +1,17 @@
1
- import { createContext, type ReactNode, useContext, useId } from "react";
1
+ import { createContext, type ReactNode, useContext, useEffect, useId, useState } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
 
4
- /** `still` holds the pose. `idle` looks around. Defaults to `still`. */
4
+ /** `still` holds the pose. `idle` turns to a random direction. Defaults to `still`. */
5
5
  export type AgentAvatarMotion = "still" | "idle";
6
6
 
7
- /** Fixed facing. The head turns that way and the eyes follow. */
7
+ /** Fixed facing. The shape stays centered and the eyes move that way. */
8
8
  export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
9
9
 
10
10
  /** Pupil color. Omitted picks black, or white when the face is dark. */
11
11
  export type AgentAvatarEyeColor = "black" | "white";
12
12
 
13
13
  export const AGENT_AVATAR_PARTS = {
14
- shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
14
+ shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield", "nonla"],
15
15
  color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
16
16
  } as const;
17
17
 
@@ -82,19 +82,64 @@ function eyeFill(color: string, eyeColor?: AgentAvatarEyeColor) {
82
82
  return eyeInk(color);
83
83
  }
84
84
 
85
- /** Head shift, then how much further the eyes travel, in viewBox units. */
86
- const LOOK: Record<AgentAvatarLook, { head: [number, number]; eyes: [number, number] }> = {
87
- forward: { head: [0, 0], eyes: [0, 0] },
88
- left: { head: [-3.2, 0.6], eyes: [-6.4, 0.4] },
89
- right: { head: [3.2, 0.6], eyes: [6.4, 0.4] },
90
- up: { head: [0, -2.6], eyes: [0, -4.4] },
91
- down: { head: [0, 2.8], eyes: [0, 4.6] },
92
- "up-left": { head: [-2.3, -1.9], eyes: [-4.5, -3.1] },
93
- "up-right": { head: [2.3, -1.9], eyes: [4.5, -3.1] },
94
- "down-left": { head: [-2.3, 2], eyes: [-4.5, 3.3] },
95
- "down-right": { head: [2.3, 2], eyes: [4.5, 3.3] },
85
+ function randomLook(current: AgentAvatarLook) {
86
+ const pool = LOOKS.filter((item) => item !== current);
87
+ return pool[Math.floor(Math.random() * pool.length)];
88
+ }
89
+
90
+ /** Idle holds one facing, then picks a different one. */
91
+ function useIdleLook(active: boolean, home: AgentAvatarLook, delay: number) {
92
+ const [glance, setGlance] = useState(home);
93
+
94
+ useEffect(() => {
95
+ if (!active) return;
96
+ const media = window.matchMedia("(prefers-reduced-motion: reduce)");
97
+ if (media.matches) {
98
+ setGlance(home);
99
+ return;
100
+ }
101
+
102
+ let timer = 0;
103
+ const arm = (wait: number) => {
104
+ timer = window.setTimeout(() => {
105
+ setGlance((current) => randomLook(current));
106
+ arm(1100 + Math.random() * 1700);
107
+ }, wait);
108
+ };
109
+
110
+ setGlance(home);
111
+ arm(700 + delay * 1000 + Math.random() * 900);
112
+
113
+ const onChange = () => {
114
+ if (!media.matches) return;
115
+ window.clearTimeout(timer);
116
+ setGlance(home);
117
+ };
118
+ media.addEventListener("change", onChange);
119
+ return () => {
120
+ window.clearTimeout(timer);
121
+ media.removeEventListener("change", onChange);
122
+ };
123
+ }, [active, home, delay]);
124
+
125
+ return active ? glance : home;
126
+ }
127
+
128
+ /** Eye travel in viewBox units. The shape stays on the center of the box. */
129
+ const LOOK: Record<AgentAvatarLook, [number, number]> = {
130
+ forward: [0, 0],
131
+ left: [-6.4, 0],
132
+ right: [6.4, 0],
133
+ up: [0, -4.4],
134
+ down: [0, 4.4],
135
+ "up-left": [-4.5, -3.1],
136
+ "up-right": [4.5, -3.1],
137
+ "down-left": [-4.5, 3.1],
138
+ "down-right": [4.5, 3.1],
96
139
  };
97
140
 
141
+ const LOOKS = Object.keys(LOOK) as AgentAvatarLook[];
142
+
98
143
  function mixHex(color: string, toward: "#fff" | "#000", amount: number) {
99
144
  const hex = color.replace("#", "");
100
145
  const channel = (start: number) => Number.parseInt(hex.slice(start, start + 2), 16);
@@ -109,6 +154,67 @@ const PaintContext = createContext("#111");
109
154
  const ShadowContext = createContext<string | undefined>(undefined);
110
155
  const InkContext = createContext(EYE);
111
156
 
157
+ /** Logo mark, fitted to the avatar box. The mark stays centered. Eyes and the smile travel. */
158
+ const NONLA_HAT =
159
+ "M32.05 11.6C31.32 11.6 26.28 15.07 17.23 22.05C12.68 25.52 8.71 28.77 6.19 31.06C5.2 31.92 4.21 32.86 3.49 33.77C2.95 34.49 2.36 35.16 2.09 35.57C1.91 36.15 1.95 36.83 2 37.37A30 4.86 0 0 1 62 37.37C62.05 36.83 62.09 36.15 61.91 35.57C61.64 35.16 61.05 34.49 60.51 33.77C59.79 32.86 58.8 31.92 57.81 31.06C55.29 28.77 51.32 25.52 46.77 22.05C37.72 15.07 32.68 11.6 32.05 11.6Z";
160
+
161
+ function nonlaTones(color: string) {
162
+ return {
163
+ brim: mixHex(color, "#000", 0.3),
164
+ face: mixHex(color, "#fff", 0.25),
165
+ hat: color,
166
+ };
167
+ }
168
+
169
+ function NonlaHat({ tone }: { tone: ReturnType<typeof nonlaTones> }) {
170
+ return (
171
+ <>
172
+ <path fill={tone.hat} d={NONLA_HAT} />
173
+ <path fill="none" stroke={tone.hat} strokeWidth="0.4" d="M2.5 37.37A29.5 4.86 0 0 1 61.5 37.37" />
174
+ <path fill="none" stroke={tone.brim} strokeWidth="1" d="M2.5 37.37A29.5 4.77 0 0 1 61.5 37.37" />
175
+ <g fill="none" stroke={tone.brim} strokeWidth="0.5" strokeLinecap="round" opacity="0.55">
176
+ <path d="M31.23 12.86C25.6 20.25 17.95 27.5 10.15 33.9" />
177
+ <path d="M31.59 12.86C28.98 19.4 26.46 25.52 23.94 31.38" />
178
+ <path d="M32.5 12.86C35.11 19.4 37.63 25.52 40.15 31.38" />
179
+ <path d="M32.86 12.86C38.49 20.25 46.14 27.5 53.94 33.9" />
180
+ </g>
181
+ </>
182
+ );
183
+ }
184
+
185
+ function NonlaMark({ color }: { color: string }) {
186
+ const tone = nonlaTones(color);
187
+ const ink = useContext(InkContext);
188
+ const shadow = useContext(ShadowContext);
189
+ const catchlight = ink === EYE_ON_DARK ? EYE : "#fff";
190
+ const clip = `nonla-face-${useId().replace(/:/g, "")}`;
191
+ return (
192
+ <>
193
+ <g filter={shadow}>
194
+ <ellipse cx="32" cy="37.37" rx="30" ry="8.56" fill={tone.brim} />
195
+ <circle cx="32.05" cy="35.66" r="16.74" fill={tone.face} />
196
+ <NonlaHat tone={tone} />
197
+ </g>
198
+ <clipPath id={clip}>
199
+ <circle cx="32.05" cy="35.66" r="16.74" />
200
+ </clipPath>
201
+ <g clipPath={`url(#${clip})`}>
202
+ <g className="nonla-avatar-gaze">
203
+ <g className="nonla-avatar-eyes">
204
+ <ellipse cx="24.82" cy="40.3" rx="2" ry="3.06" fill={ink} />
205
+ <ellipse cx="38.96" cy="40.3" rx="2" ry="3.06" fill={ink} />
206
+ <ellipse cx="25.29" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
207
+ <ellipse cx="39.43" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
208
+ </g>
209
+ <path fill="none" stroke={EYE} strokeWidth="1.08" strokeLinecap="round" d="M28.8 44.67C30.47 46.65 33.53 46.65 35.15 44.67" />
210
+ </g>
211
+ </g>
212
+ {/* Covers eyes that travel up into the cone. The smile stays below this edge. */}
213
+ <NonlaHat tone={tone} />
214
+ </>
215
+ );
216
+ }
217
+
112
218
  function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number; h?: number }) {
113
219
  const gap = w * 1.5;
114
220
  const top = cy - h / 2;
@@ -162,6 +268,7 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
162
268
  <Eyes cx={32} cy={34} />,
163
269
  -6,
164
270
  ),
271
+ nonla: <NonlaMark color={color} />,
165
272
  };
166
273
  return <InkContext.Provider value={eyeFill(color, eyeColor)}>{body[shape]}</InkContext.Provider>;
167
274
  }
@@ -169,9 +276,8 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
169
276
  export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
170
277
  const resolved = resolveConfig(config);
171
278
  const delay = stagger(`${resolved.shape}${resolved.color}`);
172
- const facing = LOOK[look];
173
- const [hx, hy] = facing.head;
174
- const [ex, ey] = facing.eyes;
279
+ const shown = useIdleLook(motion === "idle", look, delay);
280
+ const [ex, ey] = LOOK[shown];
175
281
  const uid = useId().replace(/:/g, "");
176
282
  const light = `nonla-av-${uid}`;
177
283
  const shadow = `nonla-av-s-${uid}`;
@@ -181,14 +287,12 @@ export function AgentAvatar({ config, size = 64, motion = "still", look = "forwa
181
287
  role="img"
182
288
  aria-label={label}
183
289
  data-motion={motion}
184
- data-look={look}
290
+ data-look={shown}
185
291
  className={cn("nonla-avatar", className)}
186
292
  style={{
187
293
  width: size,
188
294
  height: size,
189
295
  ["--nonla-avatar-delay" as string]: `${delay}s`,
190
- ["--nonla-avatar-hx" as string]: `${(hx / 64) * 100}%`,
191
- ["--nonla-avatar-hy" as string]: `${(hy / 64) * 100}%`,
192
296
  ["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
193
297
  ["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
194
298
  }}
@@ -1,51 +1,3 @@
1
- @keyframes nonla-avatar-wander {
2
- 0%,
3
- 14%,
4
- 100% {
5
- transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
6
- }
7
- 22%,
8
- 34% {
9
- transform: translate(-5%, 1%);
10
- }
11
- 42%,
12
- 54% {
13
- transform: translate(0, -4%);
14
- }
15
- 62%,
16
- 74% {
17
- transform: translate(5%, 1%);
18
- }
19
- 82%,
20
- 94% {
21
- transform: translate(0, 4.4%);
22
- }
23
- }
24
-
25
- @keyframes nonla-avatar-glance {
26
- 0%,
27
- 14%,
28
- 100% {
29
- transform: translate(var(--nonla-avatar-ex, 0), var(--nonla-avatar-ey, 0));
30
- }
31
- 22%,
32
- 34% {
33
- transform: translate(-10%, 0.6%);
34
- }
35
- 42%,
36
- 54% {
37
- transform: translate(0, -6.9%);
38
- }
39
- 62%,
40
- 74% {
41
- transform: translate(10%, 0.6%);
42
- }
43
- 82%,
44
- 94% {
45
- transform: translate(0, 7.2%);
46
- }
47
- }
48
-
49
1
  @keyframes nonla-avatar-blink {
50
2
  0%,
51
3
  46%,
@@ -58,7 +10,7 @@
58
10
  }
59
11
  }
60
12
 
61
- /* A quiet shift, not a bounce. */
13
+ /* The shape stays put. Only the eyes travel. */
62
14
  .nonla-avatar {
63
15
  display: inline-flex;
64
16
  flex-shrink: 0;
@@ -70,7 +22,6 @@
70
22
  display: block;
71
23
  width: 100%;
72
24
  height: 100%;
73
- transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
74
25
  }
75
26
 
76
27
  .nonla-avatar-gaze {
@@ -83,14 +34,8 @@
83
34
  transform-origin: center;
84
35
  }
85
36
 
86
- .nonla-avatar[data-motion="idle"] .nonla-avatar-bob {
87
- animation: nonla-avatar-wander 8.4s ease-in-out infinite;
88
- animation-delay: var(--nonla-avatar-delay, 0s);
89
- }
90
-
91
37
  .nonla-avatar[data-motion="idle"] .nonla-avatar-gaze {
92
- animation: nonla-avatar-glance 8.4s ease-in-out infinite;
93
- animation-delay: var(--nonla-avatar-delay, 0s);
38
+ transition: transform 0.55s ease-in-out;
94
39
  }
95
40
 
96
41
  .nonla-avatar[data-motion="idle"] .nonla-avatar-eyes {
@@ -99,9 +44,9 @@
99
44
  }
100
45
 
101
46
  @media (prefers-reduced-motion: reduce) {
102
- .nonla-avatar[data-motion] .nonla-avatar-bob,
103
47
  .nonla-avatar[data-motion] .nonla-avatar-gaze,
104
48
  .nonla-avatar[data-motion] .nonla-avatar-eyes {
105
49
  animation: none;
50
+ transition: none;
106
51
  }
107
52
  }
package/src/index.ts CHANGED
@@ -23,71 +23,6 @@ export type { CalendarProps } from "./calendar/Calendar";
23
23
  export { Calendar } from "./calendar/Calendar";
24
24
  export type { CardFooterProps, CardItemProps, CardProps } from "./card/Card";
25
25
  export { Card } from "./card/Card";
26
- export type {
27
- AgentChatboxProps,
28
- AgentHistoryMessage,
29
- AgentMessage,
30
- AgentMessageRole,
31
- AgentPanelEndpoint,
32
- AgentPanelProps,
33
- AgentSseCallbacks,
34
- AgentStreamRequest,
35
- AgentToolCallEvent,
36
- AgentToolHook,
37
- AgentToolNameMatch,
38
- AgentToolResultEvent,
39
- AgentToolUI,
40
- AgentToolUIName,
41
- BackgroundTasksBarProps,
42
- ChatAgentMessageProps,
43
- ChatBgTask,
44
- ChatErrorProps,
45
- ChatInputProps,
46
- ChatMarkdownProps,
47
- ChatThinkingProps,
48
- ChatToolCallProps,
49
- ChatToolMessage,
50
- ChatUserMessageProps,
51
- ChatWelcomeProps,
52
- ToolUIProps,
53
- } from "./chat";
54
- export {
55
- AgentChatbox,
56
- AgentPanel,
57
- BackgroundTasksBar,
58
- BackgroundTaskToolUI,
59
- buildAgentHistory,
60
- builtinToolUis,
61
- CallAgentToolUI,
62
- ChatAgentMessage,
63
- ChatError,
64
- ChatInput,
65
- ChatMarkdown,
66
- ChatSpinner,
67
- ChatThinking,
68
- ChatToolCall,
69
- ChatUserMessage,
70
- ChatWelcome,
71
- formatBgElapsed,
72
- formatToolName,
73
- GetCurrentTimeToolUI,
74
- isCallAgentToolName,
75
- isToolRunning,
76
- matchesToolHook,
77
- matchesToolName,
78
- matchesToolUIName,
79
- parseBgTaskRef,
80
- parseCallAgentToolTargetId,
81
- parseSseStream,
82
- prettyJson,
83
- ReadSkillToolUI,
84
- RunJsToolUI,
85
- resolveToolUI,
86
- ToolUiTrailing,
87
- useAgentChatStream,
88
- useAgentStream,
89
- WebFetchToolUI,
90
- } from "./chat";
91
26
  export type { CheckboxColor, CheckboxProps } from "./checkbox/Checkbox";
92
27
  export { Checkbox } from "./checkbox/Checkbox";
93
28
  export type { CodeBlockCopyButtonProps, CodeBlockProps } from "./codeblock/CodeBlock";
@@ -96,15 +31,6 @@ export type { ColorFormat, ColorPickerProps, ColorPickerSemanticSlot, ColorType,
96
31
  export { Color, ColorPicker } from "./colorpicker/ColorPicker";
97
32
  export type { DatePickerProps, RangePickerProps, RangeValue } from "./datepicker/DatePicker";
98
33
  export { DatePicker, RangePicker } from "./datepicker/DatePicker";
99
- export type { DesktopHeaderProps } from "./desktop/DesktopHeader";
100
- export { DesktopBarButton, DesktopBarDivider, DesktopBarItem, DesktopHeader } from "./desktop/DesktopHeader";
101
- export { DesktopIcon } from "./desktop/DesktopIcon";
102
- export { DesktopStage } from "./desktop/DesktopStage";
103
- export type { DesktopWindowProps, WindowHeaderProps } from "./desktop/DesktopWindow";
104
- export { DesktopWindow, WindowHeader } from "./desktop/DesktopWindow";
105
- export { MeadowDesktop } from "./desktop/MeadowDesktop";
106
- export { MeadowShell } from "./desktop/MeadowShell";
107
- export { MeadowWallpaper } from "./desktop/MeadowWallpaper";
108
34
  export type { DrawerPlacement, DrawerProps } from "./drawer/Drawer";
109
35
  export { Drawer } from "./drawer/Drawer";
110
36
  export type { ContextMenuProps } from "./dropdown/ContextMenu";
@@ -147,19 +73,6 @@ export { CONTROL_SIZES, controlHeightVar, controlRadiusVar, controlStatusClass,
147
73
  export { glassOverlayClass, glassSurfaceClass, meadowSurfaceClass } from "./lib/surface";
148
74
  export type { LogoProps, LogoVariant } from "./logo/Logo";
149
75
  export { Logo } from "./logo/Logo";
150
- export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
151
- export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
152
- export type { MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
153
- export { MarkdownViewer } from "./markdown-editor/MarkdownViewer";
154
- export type { MermaidBlockProps } from "./markdown-editor/MermaidBlock";
155
- export { MermaidBlock } from "./markdown-editor/MermaidBlock";
156
- export type { ReactCodeProps } from "./markdown-editor/ReactCode";
157
- export { ReactCode } from "./markdown-editor/ReactCode";
158
- export type { ReactCodeFrameProps } from "./markdown-editor/ReactCodeFrame";
159
- export { ReactCodeFrame } from "./markdown-editor/ReactCodeFrame";
160
- export { mountReactCodeRunner } from "./markdown-editor/ReactCodeRunner";
161
- export type { ReactCodeSandboxProps } from "./markdown-editor/ReactCodeSandbox";
162
- export { ReactCodeSandbox } from "./markdown-editor/ReactCodeSandbox";
163
76
  export type { MenuItemProps, MenuRootProps, MenuTriggerProps } from "./menu/Menu";
164
77
  export { Menu, MenuAction, MenuDivider, MenuItem, MenuTrigger } from "./menu/Menu";
165
78
  export type { MessageConfig, MessageType } from "./message/message";
@@ -4,10 +4,10 @@ import remarkGfm from "remark-gfm";
4
4
  import { Checkbox } from "../checkbox/Checkbox";
5
5
  import { CodeBlock } from "../codeblock/CodeBlock";
6
6
  import { cn } from "../lib/cn";
7
+ import { headingClass, markdownScaleStyle } from "../lib/markdownScale";
7
8
  import { type InlineEdit, type MarkdownBlock, parseMarkdownDoc, readFence, readInlineEdit } from "./blocks";
8
9
  import { MarkdownTable } from "./MarkdownTable";
9
10
  import { MermaidBlock } from "./MermaidBlock";
10
- import { headingClass, markdownScaleStyle } from "./markdownScale";
11
11
  import { ReactCode } from "./ReactCode";
12
12
  import { ReactCodeSandbox } from "./ReactCodeSandbox";
13
13
 
@@ -1,7 +1,7 @@
1
1
  import { Component, type ReactNode } from "react";
2
2
  import { flushSync } from "react-dom";
3
3
  import { createRoot } from "react-dom/client";
4
- import { applyColorMode } from "../theme";
4
+ import { applyColorMode, bindColorModeTarget } from "../theme";
5
5
  import { REACT_CODE_SOURCE, type RunnerPayload, readHostMessage } from "./reactCodeProtocol";
6
6
  import { compileReactCode } from "./reactCompile";
7
7
 
@@ -32,6 +32,13 @@ class Boundary extends Component<{ report: Report; children: ReactNode }, { erro
32
32
  * `Access-Control-Allow-Origin: *` on its assets, since a sandboxed frame loads them cross-origin.
33
33
  */
34
34
  export function mountReactCodeRunner(root: HTMLElement, modules: Record<string, unknown>): () => void {
35
+ root.classList.add("nonla-ui");
36
+ bindColorModeTarget(root);
37
+ const pending = document.documentElement.dataset.pendingMode;
38
+ if (pending === "light" || pending === "dark") {
39
+ applyColorMode(pending, root);
40
+ delete document.documentElement.dataset.pendingMode;
41
+ }
35
42
  const reactRoot = createRoot(root);
36
43
  const report: Report = (message) => window.parent.postMessage({ source: REACT_CODE_SOURCE, ...message }, "*");
37
44
 
@@ -40,7 +47,7 @@ export function mountReactCodeRunner(root: HTMLElement, modules: Record<string,
40
47
  if (event.source !== window.parent) return;
41
48
  const msg = readHostMessage(event.data);
42
49
  if (!msg) return;
43
- applyColorMode(msg.mode);
50
+ applyColorMode(msg.mode, root);
44
51
  if (msg.type === "mode") return;
45
52
  waitingForRun = false;
46
53
  try {
@@ -77,6 +84,7 @@ export function mountReactCodeRunner(root: HTMLElement, modules: Record<string,
77
84
  window.clearInterval(readyBeat);
78
85
  window.removeEventListener("message", onMessage);
79
86
  observer.disconnect();
87
+ bindColorModeTarget(null);
80
88
  reactRoot.unmount();
81
89
  };
82
90
  }
@@ -0,0 +1,13 @@
1
+ export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./MarkdownEditor";
2
+ export { MarkdownEditor } from "./MarkdownEditor";
3
+ export type { MarkdownViewerProps } from "./MarkdownViewer";
4
+ export { MarkdownViewer } from "./MarkdownViewer";
5
+ export type { MermaidBlockProps } from "./MermaidBlock";
6
+ export { MermaidBlock } from "./MermaidBlock";
7
+ export type { ReactCodeProps } from "./ReactCode";
8
+ export { ReactCode } from "./ReactCode";
9
+ export type { ReactCodeFrameProps } from "./ReactCodeFrame";
10
+ export { ReactCodeFrame } from "./ReactCodeFrame";
11
+ export { mountReactCodeRunner } from "./ReactCodeRunner";
12
+ export type { ReactCodeSandboxProps } from "./ReactCodeSandbox";
13
+ export { ReactCodeSandbox } from "./ReactCodeSandbox";