devnonla-ui 0.11.0 → 0.12.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
@@ -132,7 +132,7 @@ import { DesktopStage, DesktopHeader, MeadowDesktop, DesktopWindow, MeadowShell,
132
132
  </DesktopStage>
133
133
  ```
134
134
 
135
- `MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. Last collapsed position and size are restored on reopen (`persistKey`, or `false` to disable). Resize handles stay when expanded; dragging an edge leaves expand and keeps the new size. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
135
+ `MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. The window zooms open; `origin` is the element it zooms from, and `closeRef` receives a close function to call instead of unmounting so it can shrink back. Last collapsed position and size are restored on reopen (`persistKey`, or `false` to disable). Resize handles stay when expanded; dragging an edge leaves expand and keeps the new size. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
136
136
 
137
137
  # Sidebar
138
138
 
@@ -246,14 +246,14 @@ import { Link, Paragraph, Text, Title } from "devnonla-ui";
246
246
 
247
247
  # Logo
248
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.
249
+ `Logo` is the mark and the wordmark “Nonla Agents”. The wordmark is K2D regular, drawn as SVG outlines. `variant` is `icon`, `text`, or `full` (default). `size` is the icon height in px (default 32). `color` recolors the mark and the wordmark; the eyes and the smile stay.
250
250
 
251
251
  ```tsx
252
252
  import { Logo } from "devnonla-ui";
253
253
 
254
254
  <Logo />
255
255
  <Logo variant="icon" size={24} />
256
- <Logo face="jakarta" color="#181818" />
256
+ <Logo color="#181818" />
257
257
  ```
258
258
 
259
259
  # Icons
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -29,7 +29,8 @@
29
29
  "src"
30
30
  ],
31
31
  "scripts": {
32
- "typecheck": "tsc --noEmit"
32
+ "typecheck": "tsc --noEmit",
33
+ "docs": "bun --cwd docs run dev"
33
34
  },
34
35
  "peerDependencies": {
35
36
  "react": ">=19",
package/src/app/App.tsx CHANGED
@@ -20,6 +20,8 @@ export type AppProps = {
20
20
 
21
21
  /** Root host for NonlaUI — ConfigProvider + message/modal holders. Mount once near app root. */
22
22
  export function App({ children, getPopupContainer, componentSize, theme }: AppProps) {
23
+ // Before children paint, so a sandbox iframe can open on the saved mode instead of flashing the default.
24
+ initColorMode();
23
25
  const [themeRev, setThemeRev] = useState(0);
24
26
  const size = componentSize ? normalizeSize(componentSize) : undefined;
25
27
  const value = useMemo<NonlaAppConfig>(
@@ -27,10 +29,6 @@ export function App({ children, getPopupContainer, componentSize, theme }: AppPr
27
29
  [getPopupContainer, size, themeRev],
28
30
  );
29
31
 
30
- useLayoutEffect(() => {
31
- initColorMode();
32
- }, []);
33
-
34
32
  useLayoutEffect(() => {
35
33
  if (!theme) return;
36
34
  const restore = applyNonlaTheme(theme);
@@ -4,7 +4,7 @@ import type { ControlSize } from "../lib/sizes";
4
4
  import { controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
5
5
 
6
6
  export type ButtonType = "default" | "primary" | "dashed" | "link" | "text";
7
- export type ButtonVariant = "outlined" | "dashed" | "solid" | "filled" | "text" | "link";
7
+ export type ButtonVariant = "outlined" | "dashed" | "solid" | "filled" | "text" | "link" | "nostyle";
8
8
  export type ButtonShape = "default" | "circle" | "round" | "square";
9
9
  export type ButtonHtmlType = "submit" | "button" | "reset";
10
10
  export type ButtonSize = ControlSize;
@@ -56,6 +56,7 @@ function isButtonType(value: unknown): value is ButtonType {
56
56
  }
57
57
 
58
58
  function resolveTone(type: ButtonType | undefined, color: ButtonColor | undefined, variant: ButtonVariant | undefined, danger: boolean): [ButtonColor, ButtonVariant] {
59
+ if (variant === "nostyle") return ["default", "nostyle"];
59
60
  if (color && variant) return [danger ? "danger" : color, variant];
60
61
  if (type || danger) {
61
62
  const pair = TYPE_MAP[isButtonType(type) ? type : "default"];
@@ -71,6 +72,7 @@ const TWO_CN = /^[\u4e00-\u9fa5]{2}$/;
71
72
  const GroupSizeContext = createContext<ButtonSize | undefined>(undefined);
72
73
 
73
74
  function tokenAppearance(color: "default" | "primary" | "danger" | "link", variant: ButtonVariant, ghost: boolean): string {
75
+ if (variant === "nostyle") return "";
74
76
  const g = ghost && variant !== "text" && variant !== "link";
75
77
  if (color === "primary") {
76
78
  if (variant === "solid" && !g) return "border-transparent bg-brand text-[var(--nonla-solid-fg)] hover:bg-[color-mix(in_oklab,var(--brand),var(--background)_14%)] active:bg-[color-mix(in_oklab,var(--brand),black_18%)]";
@@ -94,6 +96,7 @@ function tokenAppearance(color: "default" | "primary" | "danger" | "link", varia
94
96
  }
95
97
 
96
98
  function presetAppearance(variant: ButtonVariant, ghost: boolean): string {
99
+ if (variant === "nostyle") return "";
97
100
  const g = ghost && variant !== "text" && variant !== "link";
98
101
  if (variant === "solid" && !g) return "bg-(--nonla-btn) text-[var(--nonla-solid-fg)] border-transparent hover:brightness-110";
99
102
  if (variant === "filled") return "bg-(--nonla-btn)/15 text-(--nonla-btn) border-transparent hover:bg-(--nonla-btn)/25";
@@ -196,22 +199,24 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
196
199
 
197
200
  const iconNode = innerLoading ? typeof loading === "object" && loading.icon ? loading.icon : <LoadingDot size={tok.icon} /> : icon;
198
201
  const showIcon = Boolean(iconNode);
202
+ const bare = mergedVariant === "nostyle";
199
203
  const radius = shape === "circle" || shape === "round" ? 9999 : shape === "square" ? 4 : controlRadiusVar(size);
200
- const appearance = preset ? presetAppearance(mergedVariant, ghost) : tokenAppearance(mergedColor as "default" | "primary" | "danger" | "link", mergedVariant, ghost);
201
- const bordered = mergedVariant !== "text" && mergedVariant !== "link";
204
+ const appearance = bare ? "" : preset ? presetAppearance(mergedVariant, ghost) : tokenAppearance(mergedColor as "default" | "primary" | "danger" | "link", mergedVariant, ghost);
205
+ const bordered = !bare && mergedVariant !== "text" && mergedVariant !== "link";
202
206
 
203
207
  const padText = tok.paddingInline;
204
208
  const paddingLeft = iconOnly ? 0 : showIcon && placement === "start" ? tok.paddingInlineIconStart : padText;
205
209
  const paddingRight = iconOnly ? 0 : showIcon && placement === "end" ? tok.paddingInlineIconEnd : padText;
206
210
 
207
211
  const rootClass = cn(
208
- "inline-flex items-center justify-center gap-2 font-normal whitespace-nowrap select-none cursor-pointer border border-solid transition-colors duration-150",
209
- "focus-visible:outline-none",
210
- "disabled:cursor-not-allowed disabled:opacity-45",
211
- bordered ? "border" : "border-transparent",
212
+ bare
213
+ ? "inline-flex items-center justify-center gap-2 cursor-pointer border-0 bg-transparent px-0 py-0 text-inherit rounded-none disabled:cursor-not-allowed"
214
+ : "inline-flex items-center justify-center gap-2 font-normal whitespace-nowrap select-none cursor-pointer border border-solid transition-colors duration-150 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45",
215
+ !bare && (bordered ? "border" : "border-transparent"),
212
216
  appearance,
213
217
  block && "flex w-full",
214
- innerLoading && "pointer-events-none opacity-80",
218
+ innerLoading && "pointer-events-none",
219
+ !bare && innerLoading && "opacity-80",
215
220
  placement === "end" && "flex-row-reverse",
216
221
  prefixCls,
217
222
  className,
@@ -220,18 +225,20 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
220
225
  );
221
226
 
222
227
  const boxH = controlHeightVar(size);
223
- const mergedStyle: CSSProperties = {
224
- height: boxH,
225
- width: iconOnly ? boxH : undefined,
226
- fontSize: tok.fontSize,
227
- lineHeight: `${tok.lineHeight}px`,
228
- paddingLeft,
229
- paddingRight,
230
- borderRadius: radius,
231
- ...(preset ? ({ "--nonla-btn": `var(--nonla-${mergedColor})` } as CSSProperties) : null),
232
- ...styles?.root,
233
- ...style,
234
- };
228
+ const mergedStyle: CSSProperties = bare
229
+ ? { ...styles?.root, ...style }
230
+ : {
231
+ height: boxH,
232
+ width: iconOnly ? boxH : undefined,
233
+ fontSize: tok.fontSize,
234
+ lineHeight: `${tok.lineHeight}px`,
235
+ paddingLeft,
236
+ paddingRight,
237
+ borderRadius: radius,
238
+ ...(preset ? ({ "--nonla-btn": `var(--nonla-${mergedColor})` } as CSSProperties) : null),
239
+ ...styles?.root,
240
+ ...style,
241
+ };
235
242
 
236
243
  const handleClick = (e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
237
244
  if (innerLoading || disabled) {
@@ -244,7 +251,7 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
244
251
  const inner = (
245
252
  <>
246
253
  {showIcon ? (
247
- <span className={cn("relative z-10 inline-flex shrink-0 items-center justify-center [&_svg]:size-full", classNames?.icon)} style={{ width: tok.icon, height: tok.icon, ...styles?.icon }}>
254
+ <span className={cn("relative z-10 inline-flex shrink-0 items-center justify-center", !bare && "[&_svg]:size-full", classNames?.icon)} style={bare ? styles?.icon : { width: tok.icon, height: tok.icon, ...styles?.icon }}>
248
255
  {iconNode}
249
256
  </span>
250
257
  ) : null}
@@ -4,7 +4,7 @@ import { cn } from "../lib/cn";
4
4
  import { glassSurfaceClass } from "../lib/surface";
5
5
  import { OverlayScroll, type OverlayScrollVisibility } from "../scroll/OverlayScroll";
6
6
 
7
- type Phase = "open" | "leaving";
7
+ type Phase = "enter" | "open" | "leaving";
8
8
  type Size = { w: number; h: number };
9
9
  type Point = { x: number; y: number };
10
10
  type Rect = { x: number; y: number; w: number; h: number };
@@ -41,11 +41,11 @@ function hasOpenDialog() {
41
41
  return Boolean(document.querySelector('dialog[open], [role="dialog"][data-state="open"], .nonla-modal-content'));
42
42
  }
43
43
 
44
- function originFromActiveIcon(overlay: HTMLElement, frame: HTMLElement) {
45
- const source = document.querySelector('[aria-current="true"]');
46
- if (!(source instanceof HTMLElement)) return "50% 50%";
44
+ function zoomOrigin(overlay: HTMLElement, frame: HTMLElement, source: HTMLElement | null) {
45
+ const from = source ?? document.querySelector('[aria-current="true"]');
46
+ if (!(from instanceof HTMLElement)) return "50% 50%";
47
47
 
48
- const icon = source.getBoundingClientRect();
48
+ const icon = from.getBoundingClientRect();
49
49
  const overlayBox = overlay.getBoundingClientRect();
50
50
  const x = icon.left + icon.width / 2 - overlayBox.left - frame.offsetLeft;
51
51
  const y = icon.top + icon.height / 2 - overlayBox.top - frame.offsetTop;
@@ -317,6 +317,10 @@ export type DesktopWindowProps = {
317
317
  scrollbar?: OverlayScrollVisibility;
318
318
  /** Last collapsed position and size. Default `"default"`. Pass a unique key per window, or `false` to disable. */
319
319
  persistKey?: string | false;
320
+ /** Zoom from this element on open, and back to it on close. Falls back to the active desktop icon. */
321
+ origin?: { current: HTMLElement | null };
322
+ /** Animated close. Call this instead of unmounting so the window shrinks back to `origin`. */
323
+ closeRef?: { current: (() => void) | null };
320
324
  children: ReactNode;
321
325
  };
322
326
 
@@ -331,6 +335,8 @@ export function DesktopWindow({
331
335
  scroll = true,
332
336
  scrollbar = "hover",
333
337
  persistKey = "default",
338
+ origin,
339
+ closeRef,
334
340
  children,
335
341
  }: DesktopWindowProps) {
336
342
  const overlayRef = useRef<HTMLDivElement>(null);
@@ -351,7 +357,7 @@ export function DesktopWindow({
351
357
  startY: number;
352
358
  orig: Rect;
353
359
  } | null>(null);
354
- const [phase, setPhase] = useState<Phase>("open");
360
+ const [phase, setPhase] = useState<Phase>(() => (prefersReducedMotion() ? "open" : "enter"));
355
361
  const [view, setView] = useState<Size>(initialView);
356
362
  const [offset, setOffset] = useState(() => restoreGeometry(persistKey, initialView()).offset);
357
363
  const [size, setSize] = useState<Size | null>(() => restoreGeometry(persistKey, initialView()).size);
@@ -371,14 +377,31 @@ export function DesktopWindow({
371
377
  viewRef.current = view;
372
378
  offsetRef.current = offset;
373
379
 
374
- useLayoutEffect(() => {
380
+ const applyOrigin = () => {
375
381
  const overlay = overlayRef.current;
376
382
  const frame = frameRef.current;
377
- if (overlay && frame) {
378
- frame.style.transformOrigin = originFromActiveIcon(overlay, frame);
379
- }
383
+ if (!overlay || !frame) return;
384
+ frame.style.transformOrigin = zoomOrigin(overlay, frame, origin?.current ?? null);
385
+ };
386
+
387
+ useLayoutEffect(() => {
388
+ applyOrigin();
380
389
  }, []);
381
390
 
391
+ useEffect(() => {
392
+ if (phase !== "enter") return;
393
+ const id = requestAnimationFrame(() => setPhase("open"));
394
+ return () => cancelAnimationFrame(id);
395
+ }, [phase]);
396
+
397
+ useLayoutEffect(() => {
398
+ if (!closeRef) return;
399
+ closeRef.current = () => requestCloseRef.current();
400
+ return () => {
401
+ closeRef.current = null;
402
+ };
403
+ });
404
+
382
405
  const requestClose = () => {
383
406
  if (closedRef.current || phase === "leaving") return;
384
407
  if (prefersReducedMotion()) {
@@ -386,6 +409,7 @@ export function DesktopWindow({
386
409
  onClose();
387
410
  return;
388
411
  }
412
+ applyOrigin();
389
413
  setPhase("leaving");
390
414
  };
391
415
  requestCloseRef.current = requestClose;
@@ -571,13 +595,13 @@ export function DesktopWindow({
571
595
  onToggleExpand();
572
596
  };
573
597
 
574
- const visible = phase === "open";
598
+ const shown = phase === "open";
575
599
  const leaving = phase === "leaving";
576
600
  const rect = expanded ? { x: 0, y: 0, w: view.w, h: view.h } : collapsedRect(view, offset, size);
577
601
  const reduce = prefersReducedMotion();
578
602
  const duration = reduce ? "150ms" : "300ms";
579
- const geom = !dragging && !resizing && !leaving && !reduce ? `top ${duration} ${EASE}, left ${duration} ${EASE}, width ${duration} ${EASE}, height ${duration} ${EASE}` : "";
580
- const fade = leaving && !reduce ? `opacity ${duration} ${EASE}, transform ${duration} ${EASE}` : "";
603
+ const geom = phase === "open" && !dragging && !resizing && !reduce ? `top ${duration} ${EASE}, left ${duration} ${EASE}, width ${duration} ${EASE}, height ${duration} ${EASE}` : "";
604
+ const zoom = !dragging && !resizing && !reduce ? `opacity ${duration} ${EASE}, transform ${duration} ${EASE}` : "";
581
605
 
582
606
  return (
583
607
  <WindowHeaderSlotContext.Provider value={headerChrome}>
@@ -598,12 +622,12 @@ export function DesktopWindow({
598
622
  left: rect.x,
599
623
  width: rect.w,
600
624
  height: rect.h,
601
- opacity: visible ? 1 : 0,
602
- transform: visible ? "scale(1)" : "scale(0.18)",
603
- transition: [geom, fade].filter(Boolean).join(", ") || undefined,
625
+ opacity: shown ? 1 : 0,
626
+ transform: shown ? "scale(1)" : "scale(0.18)",
627
+ transition: [geom, zoom].filter(Boolean).join(", ") || undefined,
604
628
  }}
605
629
  data-expanded={expanded || undefined}
606
- className={cn("absolute flex flex-col rounded-xl pointer-events-auto transform-gpu", glassSurfaceClass, "nonla-window-glass", leaving && "pointer-events-none")}
630
+ className={cn("absolute flex flex-col rounded-xl pointer-events-auto transform-gpu", glassSurfaceClass, "nonla-window-glass", phase !== "open" && "pointer-events-none")}
607
631
  >
608
632
  <div className="relative flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl">
609
633
  {header ? (
package/src/index.ts CHANGED
@@ -159,7 +159,7 @@ export { placementToRadix } from "./lib/placement";
159
159
  export type { CanonicalSize, ControlSize, ControlSizeTokens } from "./lib/sizes";
160
160
  export { CONTROL_SIZES, controlHeightVar, controlRadiusVar, controlStatusClass, getSizeTokens, normalizeSize, useControlSize } from "./lib/sizes";
161
161
  export { glassOverlayClass, glassSurfaceClass, meadowSurfaceClass } from "./lib/surface";
162
- export type { LogoFace, LogoProps, LogoVariant } from "./logo/Logo";
162
+ export type { LogoProps, LogoVariant } from "./logo/Logo";
163
163
  export { Logo } from "./logo/Logo";
164
164
  export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
165
165
  export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
package/src/logo/Logo.tsx CHANGED
@@ -1,18 +1,12 @@
1
- import "@fontsource-variable/plus-jakarta-sans/wght.css";
2
1
  import type { CSSProperties } from "react";
3
2
  import { cn } from "../lib/cn";
4
3
 
5
4
  /** `icon` is the mark. `text` is the wordmark. `full` is both. */
6
5
  export type LogoVariant = "icon" | "text" | "full";
7
6
 
8
- /** `pixel` is the grid. `jakarta` is Plus Jakarta Sans. */
9
- export type LogoFace = "pixel" | "jakarta";
10
-
11
7
  export type LogoProps = {
12
8
  variant?: LogoVariant;
13
- /** Wordmark face. Ignored when `variant` is `icon`. Defaults to `pixel`. */
14
- face?: LogoFace;
15
- /** Icon height in px. Width follows each asset's aspect ratio. Defaults to 32. */
9
+ /** Icon height in px. Width follows the mark's aspect ratio. Defaults to 32. */
16
10
  size?: number;
17
11
  /** Icon and wordmark fill. Eyes and the smile stay. Omit to keep the mascot palette and the current text color. */
18
12
  color?: string;
@@ -26,161 +20,6 @@ const WORDMARK = "Nonla Agents";
26
20
  const MARK_W = 1336;
27
21
  const MARK_H = 960;
28
22
 
29
- /** Pixel grid wordmark. 11 rows; cap letters use 7, so the box is taller than the caps. */
30
- const WORD_W = 1340;
31
- const WORD_H = 220;
32
- const WORD_CELLS: ReadonlyArray<readonly [number, number]> = [
33
- [2.4, 2.4],
34
- [82.4, 2.4],
35
- [2.4, 22.4],
36
- [22.4, 22.4],
37
- [82.4, 22.4],
38
- [2.4, 42.4],
39
- [22.4, 42.4],
40
- [82.4, 42.4],
41
- [2.4, 62.4],
42
- [42.4, 62.4],
43
- [82.4, 62.4],
44
- [2.4, 82.4],
45
- [62.4, 82.4],
46
- [82.4, 82.4],
47
- [2.4, 102.4],
48
- [62.4, 102.4],
49
- [82.4, 102.4],
50
- [2.4, 122.4],
51
- [82.4, 122.4],
52
- [142.4, 42.4],
53
- [162.4, 42.4],
54
- [182.4, 42.4],
55
- [122.4, 62.4],
56
- [202.4, 62.4],
57
- [122.4, 82.4],
58
- [202.4, 82.4],
59
- [122.4, 102.4],
60
- [202.4, 102.4],
61
- [142.4, 122.4],
62
- [162.4, 122.4],
63
- [182.4, 122.4],
64
- [242.4, 42.4],
65
- [262.4, 42.4],
66
- [282.4, 42.4],
67
- [302.4, 42.4],
68
- [242.4, 62.4],
69
- [322.4, 62.4],
70
- [242.4, 82.4],
71
- [322.4, 82.4],
72
- [242.4, 102.4],
73
- [322.4, 102.4],
74
- [242.4, 122.4],
75
- [322.4, 122.4],
76
- [362.4, 2.4],
77
- [382.4, 2.4],
78
- [382.4, 22.4],
79
- [382.4, 42.4],
80
- [382.4, 62.4],
81
- [382.4, 82.4],
82
- [382.4, 102.4],
83
- [382.4, 122.4],
84
- [402.4, 122.4],
85
- [462.4, 42.4],
86
- [482.4, 42.4],
87
- [502.4, 42.4],
88
- [522.4, 62.4],
89
- [462.4, 82.4],
90
- [482.4, 82.4],
91
- [502.4, 82.4],
92
- [522.4, 82.4],
93
- [442.4, 102.4],
94
- [522.4, 102.4],
95
- [462.4, 122.4],
96
- [482.4, 122.4],
97
- [502.4, 122.4],
98
- [522.4, 122.4],
99
- [662.4, 2.4],
100
- [642.4, 22.4],
101
- [682.4, 22.4],
102
- [622.4, 42.4],
103
- [702.4, 42.4],
104
- [622.4, 62.4],
105
- [702.4, 62.4],
106
- [622.4, 82.4],
107
- [642.4, 82.4],
108
- [662.4, 82.4],
109
- [682.4, 82.4],
110
- [702.4, 82.4],
111
- [622.4, 102.4],
112
- [702.4, 102.4],
113
- [622.4, 122.4],
114
- [702.4, 122.4],
115
- [762.4, 42.4],
116
- [782.4, 42.4],
117
- [802.4, 42.4],
118
- [822.4, 42.4],
119
- [742.4, 62.4],
120
- [822.4, 62.4],
121
- [742.4, 82.4],
122
- [822.4, 82.4],
123
- [742.4, 102.4],
124
- [822.4, 102.4],
125
- [762.4, 122.4],
126
- [782.4, 122.4],
127
- [802.4, 122.4],
128
- [822.4, 122.4],
129
- [822.4, 142.4],
130
- [762.4, 162.4],
131
- [782.4, 162.4],
132
- [802.4, 162.4],
133
- [882.4, 42.4],
134
- [902.4, 42.4],
135
- [922.4, 42.4],
136
- [862.4, 62.4],
137
- [942.4, 62.4],
138
- [862.4, 82.4],
139
- [882.4, 82.4],
140
- [902.4, 82.4],
141
- [922.4, 82.4],
142
- [942.4, 82.4],
143
- [862.4, 102.4],
144
- [882.4, 122.4],
145
- [902.4, 122.4],
146
- [922.4, 122.4],
147
- [942.4, 122.4],
148
- [982.4, 42.4],
149
- [1002.4, 42.4],
150
- [1022.4, 42.4],
151
- [1042.4, 42.4],
152
- [982.4, 62.4],
153
- [1062.4, 62.4],
154
- [982.4, 82.4],
155
- [1062.4, 82.4],
156
- [982.4, 102.4],
157
- [1062.4, 102.4],
158
- [982.4, 122.4],
159
- [1062.4, 122.4],
160
- [1122.4, 22.4],
161
- [1102.4, 42.4],
162
- [1122.4, 42.4],
163
- [1142.4, 42.4],
164
- [1122.4, 62.4],
165
- [1122.4, 82.4],
166
- [1122.4, 102.4],
167
- [1142.4, 122.4],
168
- [1162.4, 122.4],
169
- [1222.4, 42.4],
170
- [1242.4, 42.4],
171
- [1262.4, 42.4],
172
- [1282.4, 42.4],
173
- [1202.4, 62.4],
174
- [1222.4, 82.4],
175
- [1242.4, 82.4],
176
- [1262.4, 82.4],
177
- [1282.4, 102.4],
178
- [1202.4, 122.4],
179
- [1222.4, 122.4],
180
- [1242.4, 122.4],
181
- [1262.4, 122.4],
182
- ];
183
-
184
23
  /** One paint color, split so the brim stays darker and the face stays lighter than the hat. */
185
24
  function markTones(color?: string) {
186
25
  if (!color) return { brim: "#dd7627", face: "#ffb45c", hat: "#ffa333" };
@@ -219,54 +58,35 @@ function LogoMark({ height, color }: { height: number; color?: string }) {
219
58
  );
220
59
  }
221
60
 
61
+ /** K2D regular outlines. Cap height is 709 units; the box includes the g. */
62
+ const WORD_CAP = 709;
63
+ const WORD_X = 70;
64
+ const WORD_Y = -709;
65
+ const WORD_W = 5908;
66
+ const WORD_H = 918;
67
+ const WORD_PATH = "M70 9L70-628Q70-666 93.50-687.50Q117-709 159-709L547-119L554-125L525-173L525-709Q571-709 594.50-689Q618-669 618-631L618-65Q618-33 595.50-12Q573 9 538 9L141-594L134-588L163-540L163-69Q163-31 139.50-11Q116 9 70 9M923 9Q862 9 812.50-14Q763-37 735.50-76.50Q708-116 708-165L708-329Q708-379 735.50-420Q763-461 812-485Q861-509 923-509Q985-509 1034.50-485Q1084-461 1111.50-420Q1139-379 1139-329L1139-165Q1139-116 1111-76.50Q1083-37 1034-14Q985 9 923 9M923-66Q983-66 1018.50-94.50Q1054-123 1054-169L1054-326Q1054-374 1018.50-404Q983-434 923-434Q864-434 828-404Q792-374 792-326L792-169Q792-123 827.50-94.50Q863-66 923-66M1254 9L1254-435Q1254-509 1338-509L1338-445Q1329-436 1317-418L1321-414Q1351-456 1399-482.50Q1447-509 1503-509Q1584-509 1631-461Q1678-413 1678-337L1678-55Q1678-22 1656.50-6.50Q1635 9 1591 9L1591-328Q1591-376 1564-404Q1537-432 1482-432Q1445-432 1412.50-416.50Q1380-401 1360.50-374.50Q1341-348 1341-317L1341-55Q1341-22 1319.50-6.50Q1298 9 1254 9M1953 9Q1880 9 1844-31.50Q1808-72 1808-138L1808-645Q1808-678 1829.50-693.50Q1851-709 1895-709L1895-141Q1895-102 1911-85Q1927-68 1964-68Q2001-68 2032-86Q2045-71 2045-51Q2045-27 2020-9Q1995 9 1953 9M2291 9Q2205 9 2152.50-37Q2100-83 2100-158Q2100-234 2155-280.50Q2210-327 2300-327Q2396-327 2458-259L2462-263Q2451-275 2437-288L2437-330Q2437-381 2405-409Q2373-437 2314-437Q2209-437 2164-354Q2148-362 2137.50-375.50Q2127-389 2127-403Q2127-430 2154-454.50Q2181-479 2225.50-494Q2270-509 2319-509Q2414-509 2468.50-462Q2523-415 2523-332L2523-58Q2523-23 2503-7Q2483 9 2440 9L2440-38Q2461-60 2463-64L2459-68Q2394 9 2291 9M2306-60Q2368-60 2403.50-86Q2439-112 2439-158Q2439-204 2404-231Q2369-258 2308-258Q2251-258 2218.50-231.50Q2186-205 2186-158Q2186-111 2217.50-85.50Q2249-60 2306-60M2955 9Q2925 3 2908-16.50Q2891-36 2891-64Q2891-83 2900-104L3139-679Q3151-709 3185-709Q3217-709 3230-679L3469-104Q3478-83 3478-64Q3478-37 3461-17Q3444 3 3414 9L3328-200L3041-200L2955 9M3070-281L3299-281L3170-608L3162-605L3180-559L3070-281M3757 209Q3705 209 3660 192Q3615 175 3589 146.50Q3563 118 3563 85Q3563 59 3580.50 47Q3598 35 3628 35Q3630 82 3664.50 109.50Q3699 137 3757 137Q3885 137 3885 13L3885-45Q3899-57 3906-67L3903-72Q3874-41 3830.50-21Q3787-1 3743-1Q3657-1 3602.50-48.50Q3548-96 3548-174L3548-335Q3548-386 3573.50-425.50Q3599-465 3643.50-487Q3688-509 3742-509Q3840-509 3906-423L3910-427L3890-452Q3890-480 3909.50-494.50Q3929-509 3973-509L3973 4Q3973 64 3945.50 110.50Q3918 157 3869 183Q3820 209 3757 209M3759-77Q3812-77 3849-105.50Q3886-134 3886-173L3886-336Q3886-377 3849.50-405Q3813-433 3761-433Q3701-433 3668-406.50Q3635-380 3635-331L3635-178Q3635-131 3667.50-104Q3700-77 3759-77M4314 9Q4253 9 4205-14.50Q4157-38 4130-79.50Q4103-121 4103-173L4103-321Q4103-374 4131.50-417Q4160-460 4208.50-484.50Q4257-509 4314-509Q4371-509 4418.50-485Q4466-461 4493.50-419Q4521-377 4521-324L4521-260Q4521-244 4509-233Q4497-222 4480-222L4188-222L4188-177Q4188-126 4220.50-95Q4253-64 4314-64Q4375-64 4407-91Q4439-118 4439-164Q4469-166 4489.50-152.50Q4510-139 4510-113Q4510-81 4482.50-53Q4455-25 4410-8Q4365 9 4314 9M4188-290L4440-290L4440-324Q4440-374 4405.50-405.50Q4371-437 4314-437Q4257-437 4222.50-405.50Q4188-374 4188-324L4188-290M4636 9L4636-435Q4636-509 4720-509L4720-445Q4711-436 4699-418L4703-414Q4733-456 4781-482.50Q4829-509 4885-509Q4966-509 5013-461Q5060-413 5060-337L5060-55Q5060-22 5038.50-6.50Q5017 9 4973 9L4973-328Q4973-376 4946-404Q4919-432 4864-432Q4827-432 4794.50-416.50Q4762-401 4742.50-374.50Q4723-348 4723-317L4723-55Q4723-22 4701.50-6.50Q4680 9 4636 9M5389 9Q5318 9 5283-31.50Q5248-72 5248-138L5248-430L5155-430Q5155-464 5170-482Q5185-500 5211-500L5249-500L5249-595Q5249-628 5270.50-643.50Q5292-659 5335-659L5335-500L5468-500Q5468-430 5405-430L5336-430L5336-141Q5336-101 5350.50-84.50Q5365-68 5403-68Q5438-68 5469-86Q5482-73 5482-51Q5482-27 5457-9Q5432 9 5389 9M5768 9Q5717 9 5672-6.50Q5627-22 5599.50-51Q5572-80 5572-119Q5572-167 5630-171Q5640-115 5677.50-88.50Q5715-62 5773-62Q5831-62 5863-79Q5895-96 5895-131Q5895-156 5882-171.50Q5869-187 5840.50-198.50Q5812-210 5759-221Q5693-236 5654-253Q5615-270 5594.50-298Q5574-326 5574-372Q5574-411 5598-442.50Q5622-474 5664.50-491.50Q5707-509 5761-509Q5811-509 5855.50-495Q5900-481 5927.50-455Q5955-429 5955-395Q5955-372 5937-358.50Q5919-345 5887-343Q5884-387 5851.50-412.50Q5819-438 5761-438Q5713-438 5685-420Q5657-402 5657-372Q5657-340 5683.50-324.50Q5710-309 5774-295Q5879-274 5928.50-237.50Q5978-201 5978-134Q5978-66 5923-28.50Q5868 9 5768 9";
222
68
 
223
- /** Cap height is half the icon. Caps are 7 of the 11 viewBox rows. */
224
- function wordmarkHeight(iconH: number) {
225
- return Math.round(iconH * (1 / 2) * (11 / 7));
226
- }
227
-
228
- /** Plus Jakarta Sans caps are 0.7em, so this em size makes them half the icon. */
229
- function jakartaSize(iconH: number) {
230
- return (iconH / 2) / 0.7;
231
- }
232
-
233
- function LogoJakarta({ iconH, color }: { iconH: number; color?: string }) {
234
- return (
235
- <span
236
- aria-hidden
237
- className="shrink-0 font-bold leading-none tracking-[-0.02em]"
238
- style={{ fontFamily: '"Plus Jakarta Sans Variable", sans-serif', fontSize: jakartaSize(iconH), color }}
239
- >
240
- {WORDMARK}
241
- </span>
242
- );
243
- }
244
-
245
- function LogoWordmark({ height, color }: { height: number; color?: string }) {
69
+ function LogoWordmark({ iconH, color }: { iconH: number; color?: string }) {
70
+ const scale = (iconH * 4) / 10 / WORD_CAP;
246
71
  return (
247
72
  <svg
248
73
  xmlns="http://www.w3.org/2000/svg"
249
- viewBox={`0 0 ${WORD_W} ${WORD_H}`}
250
- width={Math.round(height * (WORD_W / WORD_H))}
251
- height={height}
74
+ viewBox={`${WORD_X} ${WORD_Y} ${WORD_W} ${WORD_H}`}
75
+ width={WORD_W * scale}
76
+ height={WORD_H * scale}
252
77
  aria-hidden
253
78
  className="shrink-0"
254
- shapeRendering="crispEdges"
255
79
  >
256
- <g transform="translate(20 20)" fill={color ?? "currentColor"}>
257
- {WORD_CELLS.map(([x, y]) => (
258
- <rect key={`${x}-${y}`} x={x} y={y} width={15.2} height={15.2} />
259
- ))}
260
- </g>
80
+ <path fill={color ?? "currentColor"} d={WORD_PATH} />
261
81
  </svg>
262
82
  );
263
83
  }
264
84
 
265
- export function Logo({ variant = "full", size = 32, face = "pixel", color, className, style }: LogoProps) {
85
+ export function Logo({ variant = "full", size = 32, color, className, style }: LogoProps) {
266
86
  const iconH = size;
267
87
  const mark = <LogoMark height={iconH} color={color} />;
268
- const word = face === "jakarta" ? <LogoJakarta iconH={iconH} color={color} /> : <LogoWordmark height={wordmarkHeight(iconH)} color={color} />;
269
- const root = cn("inline-flex items-center text-foreground", variant === "full" && "gap-2", className);
88
+ const word = <LogoWordmark iconH={iconH} color={color} />;
89
+ const root = cn("inline-flex items-center text-foreground", variant === "full" && "gap-3", className);
270
90
 
271
91
  return (
272
92
  <span role="img" aria-label={WORDMARK} className={root} style={style}>
@@ -57,7 +57,7 @@ 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-[15px] leading-7 text-foreground shadow-none outline-none ring-0 placeholder:text-placeholder focus:outline-none focus:ring-0",
60
+ "block w-full resize-none overflow-hidden border-0 bg-transparent p-0 text-[14px] leading-[22px] text-foreground shadow-none outline-none ring-0 placeholder:text-placeholder focus:outline-none focus:ring-0",
61
61
  mono && "font-mono text-[13px] leading-5",
62
62
  className,
63
63
  )}
@@ -11,13 +11,13 @@ import { ReactCode } from "./ReactCode";
11
11
  import { ReactCodeSandbox } from "./ReactCodeSandbox";
12
12
 
13
13
  const documentClass = cn(
14
- "min-w-0 wrap-anywhere text-[15px] leading-7 text-foreground",
14
+ "min-w-0 wrap-anywhere text-[14px] leading-[22px] text-foreground",
15
15
  "[&_h1]:my-0 [&_h1]:text-[32px] [&_h1]:leading-tight [&_h1]:font-bold [&_h1]:tracking-tight",
16
16
  "[&_h2]:my-0 [&_h2]:text-[24px] [&_h2]:leading-tight [&_h2]:font-bold [&_h2]:tracking-tight",
17
17
  "[&_h3]:my-0 [&_h3]:text-[20px] [&_h3]:leading-snug [&_h3]:font-semibold",
18
18
  "[&_h4]:my-0 [&_h4]:text-[18px] [&_h4]:leading-snug [&_h4]:font-semibold",
19
19
  "[&_h5]:my-0 [&_h5]:text-[16px] [&_h5]:leading-snug [&_h5]:font-semibold",
20
- "[&_h6]:my-0 [&_h6]:text-[15px] [&_h6]:leading-snug [&_h6]:font-semibold",
20
+ "[&_h6]:my-0 [&_h6]:text-[14px] [&_h6]:leading-snug [&_h6]:font-semibold",
21
21
  "[&_p]:my-0",
22
22
  "[&_ul]:my-1 [&_ul]:list-disc [&_ul]:pl-6",
23
23
  "[&_ol]:my-1 [&_ol]:list-decimal [&_ol]:pl-6",
@@ -39,7 +39,7 @@ const previewComponents: Components = {
39
39
  const codeText = String(children).replace(/\n$/, "");
40
40
  const isBlock = codeText.includes("\n") || !!match;
41
41
  if (!isBlock) {
42
- return <code className="rounded-sm bg-secondary px-1 py-0.5 font-mono text-[0.9em]">{children}</code>;
42
+ return <code className="rounded-sm bg-secondary px-1 py-0.5 font-mono text-[0.9em] shadow-button-outline">{children}</code>;
43
43
  }
44
44
  if (lang.toLowerCase() === "mermaid") return <MermaidView code={codeText} />;
45
45
  return <CodeBlock code={codeText} language={lang || undefined} className="my-2" />;
@@ -57,7 +57,7 @@ const previewComponents: Components = {
57
57
  input({ type, checked }) {
58
58
  if (type !== "checkbox") return <input type={type} checked={checked} readOnly />;
59
59
  return (
60
- <span className="nonla-md-task-check pointer-events-none inline-flex h-7 items-center">
60
+ <span className="nonla-md-task-check pointer-events-none inline-flex h-[22px] items-center">
61
61
  <Checkbox checked={Boolean(checked)} tabIndex={-1} />
62
62
  </span>
63
63
  );
@@ -77,7 +77,7 @@ export function headingClass(level: number): string {
77
77
  if (level === 3) return "text-[20px] font-semibold leading-snug";
78
78
  if (level === 4) return "text-[18px] font-semibold leading-snug";
79
79
  if (level === 5) return "text-[16px] font-semibold leading-snug";
80
- return "text-[15px] font-semibold leading-snug";
80
+ return "text-[14px] font-semibold leading-snug";
81
81
  }
82
82
 
83
83
  type MdNode = {
@@ -139,13 +139,13 @@ export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind:
139
139
  return (
140
140
  <div className="flex items-start gap-1.5" style={level > 0 ? { marginLeft: `${level * 1.25}rem` } : undefined}>
141
141
  {view.task ? (
142
- <span className="pointer-events-none inline-flex h-7 w-5 shrink-0 items-center justify-center">
142
+ <span className="pointer-events-none inline-flex h-[22px] w-5 shrink-0 items-center justify-center">
143
143
  <Checkbox checked={view.checked} tabIndex={-1} />
144
144
  </span>
145
145
  ) : view.ordered ? (
146
- <span className="w-6 shrink-0 text-right text-[15px] leading-7 tabular-nums">{ordinal}.</span>
146
+ <span className="w-6 shrink-0 text-right text-[14px] leading-[22px] tabular-nums">{ordinal}.</span>
147
147
  ) : (
148
- <span className="flex h-7 w-5 shrink-0 items-center justify-center" aria-hidden>
148
+ <span className="flex h-[22px] w-5 shrink-0 items-center justify-center" aria-hidden>
149
149
  <span className="size-1.5 rounded-full bg-current" />
150
150
  </span>
151
151
  )}
@@ -35,12 +35,14 @@ export function mountReactCodeRunner(root: HTMLElement, modules: Record<string,
35
35
  const reactRoot = createRoot(root);
36
36
  const report: Report = (message) => window.parent.postMessage({ source: REACT_CODE_SOURCE, ...message }, "*");
37
37
 
38
+ let waitingForRun = true;
38
39
  const onMessage = (event: MessageEvent) => {
39
40
  if (event.source !== window.parent) return;
40
41
  const msg = readHostMessage(event.data);
41
42
  if (!msg) return;
42
43
  applyColorMode(msg.mode);
43
44
  if (msg.type === "mode") return;
45
+ waitingForRun = false;
44
46
  try {
45
47
  const Demo = compileReactCode(msg.code, modules);
46
48
  flushSync(() =>
@@ -64,8 +66,15 @@ export function mountReactCodeRunner(root: HTMLElement, modules: Record<string,
64
66
 
65
67
  window.addEventListener("message", onMessage);
66
68
  report({ type: "ready" });
69
+ // Host effect may miss the first ping (React Strict Mode remounts the listener).
70
+ const readyBeat = window.setInterval(() => {
71
+ if (waitingForRun) report({ type: "ready" });
72
+ else window.clearInterval(readyBeat);
73
+ }, 250);
67
74
 
68
75
  return () => {
76
+ waitingForRun = false;
77
+ window.clearInterval(readyBeat);
69
78
  window.removeEventListener("message", onMessage);
70
79
  observer.disconnect();
71
80
  reactRoot.unmount();
@@ -1,19 +1,32 @@
1
- import { type ReactNode, useEffect, useRef, useState } from "react";
1
+ import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { SolarIcon } from "../icon/SolarIcon";
3
- import { getColorMode, subscribeColorMode } from "../theme";
3
+ import { cn } from "../lib/cn";
4
+ import { getColorMode, type NonlaColorMode, subscribeColorMode } from "../theme";
4
5
  import { ReactCodeFrame } from "./ReactCodeFrame";
5
6
  import { type HostMessage, REACT_CODE_SOURCE, readRunnerMessage } from "./reactCodeProtocol";
6
7
 
8
+ /** Keep `mode` on the runner URL without dropping a query the caller already set. */
9
+ function withColorMode(src: string, mode: NonlaColorMode): string {
10
+ const hashAt = src.indexOf("#");
11
+ const hash = hashAt >= 0 ? src.slice(hashAt) : "";
12
+ const beforeHash = hashAt >= 0 ? src.slice(0, hashAt) : src;
13
+ const queryAt = beforeHash.indexOf("?");
14
+ const path = queryAt >= 0 ? beforeHash.slice(0, queryAt) : beforeHash;
15
+ const params = new URLSearchParams(queryAt >= 0 ? beforeHash.slice(queryAt + 1) : "");
16
+ params.set("mode", mode);
17
+ return `${path}?${params.toString()}${hash}`;
18
+ }
19
+
7
20
  /** The runner page must report `ready` within this time. */
8
- const READY_TIMEOUT_MS = 4000;
21
+ const READY_TIMEOUT_MS = 20000;
9
22
  /** After the code is sent, the runner must report `rendered` within this time. */
10
- const RENDER_TIMEOUT_MS = 5000;
23
+ const RENDER_TIMEOUT_MS = 15000;
11
24
  const MIN_HEIGHT = 32;
12
25
  const MAX_HEIGHT = 1200;
13
26
 
14
27
  export type ReactCodeSandboxProps = {
15
28
  code: string;
16
- /** URL of a page that calls `mountReactCodeRunner`. Serve it from its own origin. */
29
+ /** URL of a page that calls `mountReactCodeRunner`. Serve it from its own origin. Loaded with `?mode=light|dark` so the runner can paint before its script. */
17
30
  src: string;
18
31
  /** Header above the result. Default `true`. */
19
32
  showHeader?: boolean;
@@ -31,41 +44,73 @@ export type ReactCodeSandboxProps = {
31
44
  * Runs untrusted `live-react` source in a sandboxed iframe.
32
45
  *
33
46
  * `sandbox="allow-scripts"` without `allow-same-origin` gives the frame an opaque origin,
34
- * so it cannot read this page's cookies, storage, or DOM. Hang or error removes the frame.
47
+ * so it cannot read this page's cookies, storage, or DOM.
35
48
  */
36
49
  export function ReactCodeSandbox({ code, src, showHeader = true, showCode = true, title = "Sandbox", icon, className }: ReactCodeSandboxProps) {
37
50
  const frameRef = useRef<HTMLIFrameElement>(null);
38
51
  const [height, setHeight] = useState(MIN_HEIGHT);
39
52
  const [error, setError] = useState<string | null>(null);
53
+ const [mode, setMode] = useState(getColorMode);
54
+ const [painted, setPainted] = useState(false);
55
+ // Mode stays out of the URL after first load. A later theme change is a message, so the frame does not reload.
56
+ const modeOnLoad = useRef(getColorMode());
57
+ const frameSrc = useMemo(() => withColorMode(src, modeOnLoad.current), [src]);
58
+
59
+ useEffect(() => subscribeColorMode(() => setMode(getColorMode())), []);
60
+
61
+ useEffect(() => {
62
+ setPainted(false);
63
+ setError(null);
64
+ }, [frameSrc, code]);
40
65
 
41
66
  useEffect(() => {
42
67
  const frame = frameRef.current;
43
68
  if (!frame) return;
44
- let readyTimer: ReturnType<typeof setTimeout> | undefined = setTimeout(() => setError("The sandbox did not start."), READY_TIMEOUT_MS);
69
+ let alive = true;
70
+ // Once the runner has painted, a late timer must not replace the preview with an error.
71
+ let didRender = false;
45
72
  let renderTimer: ReturnType<typeof setTimeout> | undefined;
73
+ const readyTimer = setTimeout(() => {
74
+ if (alive && !didRender) setError("The sandbox did not start.");
75
+ }, READY_TIMEOUT_MS);
76
+
77
+ const postRun = () => {
78
+ const run: HostMessage = { source: REACT_CODE_SOURCE, type: "run", code, mode: getColorMode() };
79
+ frame.contentWindow?.postMessage(run, "*");
80
+ };
81
+
82
+ const expectRender = () => {
83
+ clearTimeout(renderTimer);
84
+ renderTimer = setTimeout(() => {
85
+ if (alive && !didRender) setError("The code took too long to run.");
86
+ }, RENDER_TIMEOUT_MS);
87
+ };
46
88
 
47
89
  const onMessage = (event: MessageEvent) => {
48
90
  // Only the frame we created. Its origin is opaque, so compare the window, not the origin.
49
91
  if (event.source !== frame.contentWindow) return;
50
92
  const msg = readRunnerMessage(event.data);
51
93
  if (!msg) return;
52
- if (msg.type === "ready" && readyTimer) {
94
+ if (msg.type === "ready") {
53
95
  clearTimeout(readyTimer);
54
- readyTimer = undefined;
55
- const run: HostMessage = { source: REACT_CODE_SOURCE, type: "run", code, mode: getColorMode() };
56
- frame.contentWindow?.postMessage(run, "*");
57
- renderTimer = setTimeout(() => setError("The code took too long to run."), RENDER_TIMEOUT_MS);
96
+ // A runner that restarts after paint (HMR) still needs the code, but must not restart the failure clock.
97
+ if (didRender) {
98
+ postRun();
99
+ return;
100
+ }
101
+ setError(null);
102
+ postRun();
103
+ expectRender();
58
104
  } else if (msg.type === "rendered") {
105
+ didRender = true;
59
106
  clearTimeout(renderTimer);
60
- renderTimer = undefined;
107
+ setError(null);
108
+ setPainted(true);
61
109
  } else if (msg.type === "resize") {
62
110
  setHeight(Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, Math.ceil(msg.height))));
63
111
  } else if (msg.type === "error") {
64
- // The real error wins over a timeout that has not fired yet.
65
112
  clearTimeout(readyTimer);
66
113
  clearTimeout(renderTimer);
67
- readyTimer = undefined;
68
- renderTimer = undefined;
69
114
  setError(msg.message);
70
115
  }
71
116
  };
@@ -77,7 +122,10 @@ export function ReactCodeSandbox({ code, src, showHeader = true, showCode = true
77
122
  });
78
123
 
79
124
  window.addEventListener("message", onMessage);
125
+ // Strict Mode remounts this listener after the frame already posted `ready`.
126
+ postRun();
80
127
  return () => {
128
+ alive = false;
81
129
  unsubscribeMode();
82
130
  window.removeEventListener("message", onMessage);
83
131
  clearTimeout(readyTimer);
@@ -93,19 +141,16 @@ export function ReactCodeSandbox({ code, src, showHeader = true, showCode = true
93
141
  code={showCode ? code : undefined}
94
142
  className={className}
95
143
  >
96
- {error ? (
97
- <p className="m-0 text-sm text-destructive">{error}</p>
98
- ) : (
99
- <iframe
100
- ref={frameRef}
101
- src={src}
102
- title="React example"
103
- sandbox="allow-scripts"
104
- referrerPolicy="no-referrer"
105
- className="block w-full border-0 bg-transparent"
106
- style={{ height }}
107
- />
108
- )}
144
+ {error ? <p className="m-0 text-sm text-destructive">{error}</p> : null}
145
+ <iframe
146
+ ref={frameRef}
147
+ src={frameSrc}
148
+ title="React example"
149
+ sandbox="allow-scripts"
150
+ referrerPolicy="no-referrer"
151
+ className={cn("block w-full border-0 bg-background", (!painted || error) && "opacity-0")}
152
+ style={{ height, colorScheme: mode }}
153
+ />
109
154
  </ReactCodeFrame>
110
155
  );
111
156
  }
@@ -98,9 +98,9 @@ function SidebarList({
98
98
  }
99
99
  if (isGroup(item)) {
100
100
  return (
101
- <div key={key} className="mb-4">
101
+ <div key={key} className="mb-5 last:mb-0">
102
102
  {item.label != null && item.label !== "" ? (
103
- <div className={cn("px-2.5 pb-1.5 pt-2 text-[11px] font-bold uppercase tracking-wider text-quaternary-foreground", item.className)}>
103
+ <div className={cn("px-3 pb-2 pt-3 text-[11px] font-bold uppercase tracking-wider text-quaternary-foreground", item.className)}>
104
104
  {item.label}
105
105
  </div>
106
106
  ) : null}
@@ -113,9 +113,9 @@ function SidebarList({
113
113
 
114
114
  const active = selected != null && key === selected;
115
115
  const className = cn(
116
- "nonla-sidebar-item flex w-full items-center gap-2.5 px-2.5 text-left text-base no-underline",
116
+ "nonla-sidebar-item flex w-full items-center gap-3 px-3 text-left text-[13px] font-normal no-underline",
117
117
  item.disabled ? "pointer-events-none cursor-not-allowed opacity-40" : "cursor-pointer",
118
- active ? "font-medium text-foreground" : "text-foreground/80 hover:text-foreground",
118
+ active ? "text-foreground" : "text-foreground/80 hover:text-foreground",
119
119
  item.className,
120
120
  );
121
121
 
@@ -184,13 +184,13 @@ export function Sidebar({
184
184
  <div className={cn("flex h-full min-h-0 flex-col", className)}>
185
185
  {header}
186
186
  {searchable ? (
187
- <div className={cn("shrink-0 px-3 pb-2", header ? "pt-1" : "pt-3")}>
187
+ <div className={cn("shrink-0 px-3 pb-3", header ? "pt-1" : "pt-3")}>
188
188
  <SearchInput size="small" wait={0} placeholder={searchPlaceholder} onChange={setQuery} />
189
189
  </div>
190
190
  ) : null}
191
- <OverlayScroll className="min-h-0 flex-1" innerClassName={cn("px-2 pb-6", !searchable && !header && "pt-2")}>
191
+ <OverlayScroll className="min-h-0 flex-1" innerClassName={cn("px-3 pb-6", !searchable && !header && "pt-3")}>
192
192
  <nav aria-label={ariaLabel}>
193
- {visible.length === 0 ? <p className="px-2 py-4 text-sm text-muted-foreground">{emptyText}</p> : <SidebarList items={visible} selected={selected} onSelect={handleSelect} />}
193
+ {visible.length === 0 ? <p className="px-3 py-4 text-sm text-muted-foreground">{emptyText}</p> : <SidebarList items={visible} selected={selected} onSelect={handleSelect} />}
194
194
  </nav>
195
195
  </OverlayScroll>
196
196
  {footer}
package/src/theme.ts CHANGED
@@ -206,8 +206,8 @@ function isColorPreference(value: string | null): value is NonlaColorPreference
206
206
  }
207
207
 
208
208
  function readStoredPreference(): NonlaColorPreference | null {
209
- if (typeof localStorage === "undefined") return null;
210
209
  try {
210
+ // Sandboxed iframes throw on the property access itself, before getItem.
211
211
  const value = localStorage.getItem(NONLA_COLOR_MODE_KEY);
212
212
  return isColorPreference(value) ? value : null;
213
213
  } catch {
@@ -43,7 +43,7 @@ const TITLE_CLASS: Record<TitleLevel, string> = {
43
43
  5: "text-[16px] leading-[24px] font-semibold",
44
44
  };
45
45
 
46
- const TITLE_SPACE = "nonla-typo mt-0 mb-[0.5em] [.nonla-typo+&]:mt-[1.2em]";
46
+ const TITLE_SPACE = "nonla-typo m-0";
47
47
 
48
48
  function decorationLine(underline?: boolean, deleted?: boolean) {
49
49
  if (underline && deleted) return "underline line-through";
@@ -58,7 +58,7 @@ function wrapDecorations(children: ReactNode, props: Decorations) {
58
58
  node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-yellow)_40%,transparent)] px-0.5 text-inherit">{node}</mark>;
59
59
  }
60
60
  if (props.code) {
61
- node = <code className="rounded-sm bg-secondary px-1 py-px font-mono text-[0.9em]">{node}</code>;
61
+ node = <code className="rounded-sm bg-secondary px-1 py-px font-mono text-[0.9em] shadow-button-outline">{node}</code>;
62
62
  }
63
63
  if (props.keyboard) {
64
64
  node = <kbd className="inline-block rounded-md border border-b-2 border-border bg-muted px-1.5 font-mono text-[0.85em] leading-5">{node}</kbd>;