devnonla-ui 0.14.0 → 0.16.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 (51) hide show
  1. package/package.json +5 -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 +33 -0
  30. package/src/icon/glyphs.ts +42 -0
  31. package/src/index.ts +8 -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 +67 -13
  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/sortable-tree/SortableTree.tsx +599 -0
  46. package/src/styles.css +36 -16
  47. package/src/tabs/Tabs.tsx +75 -13
  48. package/src/theme-switcher/ThemeSwitcher.tsx +6 -6
  49. package/src/typography/Typography.tsx +4 -4
  50. package/src/icon/SolarIcon.tsx +0 -39
  51. package/src/icon/solar.ts +0 -172
package/src/tabs/Tabs.tsx CHANGED
@@ -1,6 +1,5 @@
1
- import { type CSSProperties, type KeyboardEvent, type ReactNode, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
2
- import { SolarIcon } from "../icon/SolarIcon";
3
- import { solarIconName } from "../icon/solar";
1
+ import { type CSSProperties, type KeyboardEvent, type MouseEvent as ReactMouseEvent, type ReactNode, type PointerEvent as ReactPointerEvent, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
2
+ import { Icon, isIconName } from "../icon/Icon";
4
3
  import { cn } from "../lib/cn";
5
4
 
6
5
  export type TabsItem = {
@@ -8,7 +7,7 @@ export type TabsItem = {
8
7
  label: ReactNode;
9
8
  children?: ReactNode;
10
9
  disabled?: boolean;
11
- /** Solar icon name (`settings`), a legacy Fluent Color id (`settings-24`), or a node. */
10
+ /** An `Icon` name, or a node. */
12
11
  icon?: ReactNode;
13
12
  };
14
13
 
@@ -26,6 +25,12 @@ export type TabsProps = {
26
25
  const FADE = 32;
27
26
  const EDGE = 64;
28
27
  const TAB_HEIGHT = 40;
28
+ /** Mouse wheel multiplier. Raise for faster wheel scrolling. */
29
+ const WHEEL_SPEED = 2;
30
+ /** Pointer travel (px) before a press becomes a drag instead of a click. */
31
+ const DRAG_THRESHOLD = 4;
32
+
33
+ type DragState = { id: number; startX: number; startLeft: number; moved: boolean };
29
34
 
30
35
  type Ink = { left: number; width: number };
31
36
  type Overflow = { left: boolean; right: boolean };
@@ -56,7 +61,8 @@ function scrollToX(el: HTMLElement, target: number) {
56
61
 
57
62
  function TabIcon({ icon, size }: { icon?: ReactNode; size: number }) {
58
63
  if (icon == null || icon === false) return null;
59
- if (typeof icon === "string") return <SolarIcon name={solarIconName(icon)} size={size} />;
64
+ if (isIconName(icon)) return <Icon name={icon} size={size} />;
65
+ if (typeof icon === "string") return null;
60
66
  return <span className="inline-flex shrink-0 items-center justify-center">{icon}</span>;
61
67
  }
62
68
 
@@ -71,7 +77,7 @@ function ScrollButton({ dir, onClick }: { dir: "left" | "right"; onClick: () =>
71
77
  )}
72
78
  onClick={onClick}
73
79
  >
74
- <SolarIcon name={dir === "left" ? "alt-arrow-left-linear" : "alt-arrow-right-linear"} size={16} />
80
+ <Icon name={dir === "left" ? "arrow-left" : "arrow-right"} size={16} />
75
81
  </button>
76
82
  );
77
83
  }
@@ -87,6 +93,8 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
87
93
  const rowRef = useRef<HTMLDivElement>(null);
88
94
  const tabRefs = useRef(new Map<string, HTMLButtonElement>());
89
95
  const focusKey = useRef<string | null>(null);
96
+ const drag = useRef<DragState | null>(null);
97
+ const suppressClick = useRef(false);
90
98
 
91
99
  const [ink, setInk] = useState<Ink | null>(null);
92
100
  const [overflow, setOverflow] = useState<Overflow>({ left: false, right: false });
@@ -151,9 +159,10 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
151
159
  const onWheel = (event: WheelEvent) => {
152
160
  if (el.scrollWidth <= el.clientWidth + 1) return;
153
161
  if (Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
154
- if (event.deltaY === 0) return;
162
+ const raw = event.deltaY * (event.deltaMode === 1 ? 16 : 1) * WHEEL_SPEED;
163
+ if (raw === 0) return;
155
164
  const max = el.scrollWidth - el.clientWidth;
156
- const next = Math.min(max, Math.max(0, el.scrollLeft + event.deltaY));
165
+ const next = Math.min(max, Math.max(0, el.scrollLeft + raw));
157
166
  if (next === el.scrollLeft) return;
158
167
  el.scrollLeft = next;
159
168
  updateOverflow();
@@ -163,6 +172,49 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
163
172
  return () => el.removeEventListener("wheel", onWheel);
164
173
  }, [itemsKey, updateOverflow]);
165
174
 
175
+ function onPointerDown(event: ReactPointerEvent<HTMLDivElement>) {
176
+ const el = scrollerRef.current;
177
+ if (!el || el.scrollWidth <= el.clientWidth + 1) return;
178
+ if (event.pointerType === "mouse" && event.button !== 0) return;
179
+ suppressClick.current = false;
180
+ drag.current = { id: event.pointerId, startX: event.clientX, startLeft: el.scrollLeft, moved: false };
181
+ }
182
+
183
+ function onPointerMove(event: ReactPointerEvent<HTMLDivElement>) {
184
+ const state = drag.current;
185
+ const el = scrollerRef.current;
186
+ if (!state || !el || event.pointerId !== state.id) return;
187
+ if (event.pointerType === "mouse" && event.buttons === 0) {
188
+ drag.current = null;
189
+ return;
190
+ }
191
+ const dx = event.clientX - state.startX;
192
+ if (!state.moved) {
193
+ if (Math.abs(dx) < DRAG_THRESHOLD) return;
194
+ state.moved = true;
195
+ el.setPointerCapture(event.pointerId);
196
+ }
197
+ scrollToX(el, state.startLeft - dx);
198
+ }
199
+
200
+ function endDrag(event: ReactPointerEvent<HTMLDivElement>) {
201
+ const state = drag.current;
202
+ if (!state || event.pointerId !== state.id) return;
203
+ drag.current = null;
204
+ if (!state.moved) return;
205
+ suppressClick.current = true;
206
+ const el = scrollerRef.current;
207
+ if (el?.hasPointerCapture(event.pointerId)) el.releasePointerCapture(event.pointerId);
208
+ }
209
+
210
+ /** A drag that moved should not also activate the tab under the pointer. */
211
+ function onClickCapture(event: ReactMouseEvent<HTMLDivElement>) {
212
+ if (!suppressClick.current) return;
213
+ suppressClick.current = false;
214
+ event.stopPropagation();
215
+ event.preventDefault();
216
+ }
217
+
166
218
  function select(key: string, fromKeyboard = false) {
167
219
  if (fromKeyboard) focusKey.current = key;
168
220
  if (activeKey === undefined) setInner(key);
@@ -203,9 +255,19 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
203
255
  <div aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 h-px bg-border" />
204
256
  <div
205
257
  ref={scrollerRef}
206
- className="relative overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0"
207
- style={mask ? { maskImage: mask, WebkitMaskImage: mask } : undefined}
258
+ className="relative overflow-x-auto overflow-y-hidden overscroll-x-contain touch-pan-y select-none [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0"
259
+ style={{
260
+ // Inline on purpose: the unlayered `* { scrollbar-width: thin }` in styles.css beats the layered utility class.
261
+ scrollbarWidth: "none",
262
+ msOverflowStyle: "none",
263
+ ...(mask ? { maskImage: mask, WebkitMaskImage: mask } : null),
264
+ }}
208
265
  onScroll={updateOverflow}
266
+ onPointerDown={onPointerDown}
267
+ onPointerMove={onPointerMove}
268
+ onPointerUp={endDrag}
269
+ onPointerCancel={endDrag}
270
+ onClickCapture={onClickCapture}
209
271
  >
210
272
  <div ref={rowRef} role="tablist" aria-label={ariaLabel} aria-orientation="horizontal" className="relative flex w-max gap-3" onKeyDown={onKeyDown}>
211
273
  {ink ? <span aria-hidden className="pointer-events-none absolute bottom-0 left-0 z-1 h-0.5 rounded-t-xs bg-brand transition-[transform,width] duration-380 ease-[cubic-bezier(0.3,1.25,0.5,1)] motion-reduce:transition-none" style={{ width: ink.width, transform: `translateX(${ink.left}px)` }} /> : null}
@@ -226,10 +288,10 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
226
288
  tabIndex={selected ? 0 : -1}
227
289
  disabled={item.disabled}
228
290
  className={cn(
229
- "relative z-10 inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 bg-transparent font-normal text-tertiary-foreground transition-colors select-none",
230
- "hover:text-foreground focus-visible:ring-brand/55 focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset",
291
+ "relative z-10 inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 bg-transparent font-normal transition-colors select-none",
292
+ "focus-visible:ring-brand/55 focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset",
231
293
  "disabled:cursor-not-allowed disabled:opacity-40",
232
- selected && "text-foreground",
294
+ selected ? "text-brand" : "text-(--nonla-text-main) hover:text-foreground",
233
295
  )}
234
296
  style={{
235
297
  height: TAB_HEIGHT,
@@ -1,12 +1,12 @@
1
1
  import { useLayoutEffect, useSyncExternalStore } from "react";
2
- import { SolarIcon } from "../icon/SolarIcon";
2
+ import { Icon, type IconName } from "../icon/Icon";
3
3
  import { cn } from "../lib/cn";
4
4
  import { getColorPreference, initColorMode, type NonlaColorPreference, setColorPreference, subscribeColorPreference } from "../theme";
5
5
 
6
- const OPTIONS: { value: NonlaColorPreference; label: string; icon: string }[] = [
7
- { value: "system", label: "System", icon: "monitor-linear" },
8
- { value: "light", label: "Light", icon: "sun-linear" },
9
- { value: "dark", label: "Dark", icon: "moon-linear" },
6
+ const OPTIONS: { value: NonlaColorPreference; label: string; icon: IconName }[] = [
7
+ { value: "system", label: "System", icon: "monitor" },
8
+ { value: "light", label: "Light", icon: "sun" },
9
+ { value: "dark", label: "Dark", icon: "moon" },
10
10
  ];
11
11
 
12
12
  export function useColorPreference(): NonlaColorPreference {
@@ -46,7 +46,7 @@ export function ThemeSwitcher({ className }: ThemeSwitcherProps) {
46
46
  selected ? "bg-ink-active text-foreground" : "hover:bg-ink-hover hover:text-foreground",
47
47
  )}
48
48
  >
49
- <SolarIcon name={option.icon} size={12} />
49
+ <Icon name={option.icon} size={12} />
50
50
  </button>
51
51
  );
52
52
  })}
@@ -1,6 +1,6 @@
1
1
  import { type AnchorHTMLAttributes, type CSSProperties, createElement, type HTMLAttributes, type ReactNode } from "react";
2
2
  import { cn } from "../lib/cn";
3
- import { headingClass, markdownBodyClass, markdownParagraphClass, markdownVariantStyle, pageTitleClass } from "../markdown-editor/markdownScale";
3
+ import { headingClass, markdownBodyClass, markdownParagraphClass, markdownScaleStyle, pageTitleClass } from "../markdown-editor/markdownScale";
4
4
 
5
5
  export type TypographyType = "secondary" | "success" | "warning" | "danger";
6
6
 
@@ -40,10 +40,10 @@ const TITLE_TAG = {
40
40
  6: "h6",
41
41
  } as const;
42
42
 
43
- /** Same scale as MarkdownViewer `docs`. Body size is `--nonla-base-text-size`. Inline code reads `--md-inline-size` (14px). */
43
+ /** Same scale as MarkdownViewer. Body size is `text-md`. Inline code reads `--nonla-mono-text-size`. */
44
44
  const BODY = markdownBodyClass;
45
45
 
46
- const INLINE_CODE = "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]";
46
+ const INLINE_CODE = "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]";
47
47
 
48
48
  const TITLE_SPACE = "nonla-typo";
49
49
 
@@ -82,7 +82,7 @@ function rankColor(role: InkRole, props: Decorations): string | undefined {
82
82
  function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"], role: InkRole = "body") {
83
83
  const line = decorationLine(props.underline, props.delete);
84
84
  const color = rankColor(role, props);
85
- const scale: CSSProperties = { ...markdownVariantStyle("docs"), ...(color ? { color } : null), ...(line ? { textDecorationLine: line } : null), ...style };
85
+ const scale: CSSProperties = { ...markdownScaleStyle, ...(color ? { color } : null), ...(line ? { textDecorationLine: line } : null), ...style };
86
86
  return {
87
87
  className: cn(base, props.disabled && "cursor-not-allowed", props.strong && "font-(--md-strong-weight,600)", props.italic && "italic", props.underline && "underline-offset-[3px]", className),
88
88
  style: scale,
@@ -1,39 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import { cn } from "../lib/cn";
3
- import { ensureSolarIcons, getSolarSvg } from "./solar";
4
-
5
- export function SolarIcon({ name, size = 16, className }: { name: string; size?: number; className?: string }) {
6
- const [svg, setSvg] = useState<string | null>(() => getSolarSvg(name));
7
-
8
- useEffect(() => {
9
- const cached = getSolarSvg(name);
10
- if (cached) {
11
- setSvg(cached);
12
- return;
13
- }
14
- let cancelled = false;
15
- void ensureSolarIcons().then(() => {
16
- if (!cancelled) setSvg(getSolarSvg(name));
17
- });
18
- return () => {
19
- cancelled = true;
20
- };
21
- }, [name]);
22
-
23
- if (!svg) {
24
- return <span aria-hidden className={cn("inline-block shrink-0", className)} style={{ width: size, height: size }} />;
25
- }
26
-
27
- return (
28
- <span
29
- aria-hidden
30
- className={cn("inline-flex shrink-0 select-none text-current pointer-events-none [&_svg]:size-full", className)}
31
- style={{ width: size, height: size }}
32
- // biome-ignore lint/security/noDangerouslySetInnerHtml: Solar SVG comes from the vendored icon pack, keyed by name
33
- dangerouslySetInnerHTML={{ __html: svg }}
34
- />
35
- );
36
- }
37
-
38
- /** @deprecated Use SolarIcon. Same component — Solar icons, not Fluent Color. */
39
- export const FluentIcon = SolarIcon;
package/src/icon/solar.ts DELETED
@@ -1,172 +0,0 @@
1
- export const ICON_PREFIX = "solar";
2
- export const DEFAULT_ICON_STYLE = "linear";
3
- export const DEFAULT_ICON_NAME = "bot-linear";
4
- export const DEFAULT_TOOL_ICON = `${ICON_PREFIX}:${DEFAULT_ICON_NAME}`;
5
-
6
- const STYLE_SUFFIXES = ["bold-duotone", "line-duotone", "linear", "outline", "broken", "bold"] as const;
7
-
8
- export type SolarIconStyle = (typeof STYLE_SUFFIXES)[number];
9
-
10
- /** Fluent Color ids that do not share a Solar stem. Values are full Solar icon ids. */
11
- const LEGACY_NAMES: Record<string, string> = {
12
- alert: "bell-linear",
13
- apps: "widget-4-linear",
14
- "apps-list": "list-linear",
15
- "apps-list-detail": "sidebar-minimalistic-linear",
16
- "arrow-square-down": "alt-arrow-down-linear",
17
- "arrow-sync": "refresh-linear",
18
- board: "kanban-linear",
19
- "book-open": "book-2-linear",
20
- "bot-sparkle": "magic-stick-3-linear",
21
- "calendar-clock": "calendar-mark-linear",
22
- chat: "chat-round-linear",
23
- "chat-bubbles-question": "chat-round-question-mark-linear",
24
- "chat-more": "chat-round-dots-linear",
25
- "chat-multiple": "dialog-2-linear",
26
- checkbox: "check-square-linear",
27
- clock: "clock-circle-linear",
28
- "code-block": "code-square-linear",
29
- comment: "dialog-linear",
30
- "content-view": "window-frame-linear",
31
- "data-bar-vertical-ascending": "chart-linear",
32
- "dismiss-circle": "close-circle-linear",
33
- drafts: "notes-linear",
34
- edit: "pen-linear",
35
- "fast-forward-circle": "round-double-alt-arrow-right-linear",
36
- form: "clipboard-text-linear",
37
- "image-off": "gallery-remove-linear",
38
- "lightbulb-filament": "lightbulb-linear",
39
- "list-bar": "hamburger-menu-linear",
40
- "number-symbol-square": "hashtag-square-linear",
41
- options: "tuning-2-linear",
42
- "people-community": "users-group-rounded-linear",
43
- person: "user-rounded-linear",
44
- "search-sparkle": "magnifer-linear",
45
- "share-android": "share-linear",
46
- "share-ios": "square-share-line-linear",
47
- sparkle: "stars-linear",
48
- "text-edit-style": "text-field-linear",
49
- vault: "safe-square-linear",
50
- "wrench-screwdriver": "toolbox-linear",
51
- };
52
-
53
- type IconifyIcon = { body: string; width?: number; height?: number; left?: number; top?: number };
54
- type IconifyAlias = { parent: string };
55
- type IconifyPack = {
56
- icons?: Record<string, IconifyIcon>;
57
- aliases?: Record<string, IconifyAlias>;
58
- width?: number;
59
- height?: number;
60
- };
61
-
62
- let pack: IconifyPack | null = null;
63
- let memoryNames: string[] | null = null;
64
- const svgByName = new Map<string, string>();
65
- const imgSrcByName = new Map<string, string>();
66
- let inflight: Promise<string[]> | null = null;
67
-
68
- function hasStyle(name: string) {
69
- return STYLE_SUFFIXES.some((style) => name.endsWith(`-${style}`));
70
- }
71
-
72
- function stripStyle(name: string) {
73
- for (const style of STYLE_SUFFIXES) {
74
- const suffix = `-${style}`;
75
- if (name.endsWith(suffix)) return name.slice(0, -suffix.length);
76
- }
77
- return name;
78
- }
79
-
80
- function bareName(value: string) {
81
- let name = value.trim();
82
- if (name.startsWith(`${ICON_PREFIX}:`)) name = name.slice(ICON_PREFIX.length + 1);
83
- if (name.startsWith("fluent-color:")) name = name.slice("fluent-color:".length);
84
- return name;
85
- }
86
-
87
- /** Solar icon id. Accepts `solar:…`, a styled id, or a legacy Fluent Color id such as `settings-24`. Pass `style` to force a weight such as `bold-duotone`. */
88
- export function solarIconName(value: string, style?: SolarIconStyle): string {
89
- const name = bareName(value);
90
- const stem = name.replace(/-24$/, "");
91
- const resolved = hasStyle(name) ? name : (LEGACY_NAMES[stem] ?? LEGACY_NAMES[name] ?? `${stem}-${DEFAULT_ICON_STYLE}`);
92
- if (!style || resolved.endsWith(`-${style}`)) return resolved;
93
- return `${stripStyle(resolved)}-${style}`;
94
- }
95
-
96
- export function solarIconRef(name: string): string {
97
- return `${ICON_PREFIX}:${solarIconName(name)}`;
98
- }
99
-
100
- function lookup(name: string): IconifyIcon | null {
101
- if (!pack) return null;
102
- const seen = new Set<string>();
103
- let current = name;
104
- while (current && !seen.has(current)) {
105
- seen.add(current);
106
- const icon = pack.icons?.[current];
107
- if (icon?.body) return icon;
108
- const parent = pack.aliases?.[current]?.parent;
109
- if (!parent) return null;
110
- current = parent;
111
- }
112
- return null;
113
- }
114
-
115
- function toSvg(icon: IconifyIcon): string {
116
- const left = icon.left ?? 0;
117
- const top = icon.top ?? 0;
118
- const width = icon.width ?? pack?.width ?? 24;
119
- const height = icon.height ?? pack?.height ?? 24;
120
- return `<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="${left} ${top} ${width} ${height}">${icon.body}</svg>`;
121
- }
122
-
123
- /** Loads the vendored Solar pack (code-split). No network. */
124
- export function ensureSolarIcons(): Promise<string[]> {
125
- if (memoryNames) return Promise.resolve(memoryNames);
126
- if (inflight) return inflight;
127
- inflight = import("@iconify-json/solar/icons.json")
128
- .then((mod) => {
129
- pack = (mod.default ?? mod) as IconifyPack;
130
- memoryNames = [...Object.keys(pack.icons ?? {}), ...Object.keys(pack.aliases ?? {})];
131
- return memoryNames;
132
- })
133
- .finally(() => {
134
- inflight = null;
135
- });
136
- return inflight;
137
- }
138
-
139
- export function getIconNames(): string[] {
140
- return memoryNames ?? [];
141
- }
142
-
143
- export function getSolarSvg(name: string): string | null {
144
- if (!pack) return null;
145
- const resolved = solarIconName(name);
146
- const cached = svgByName.get(resolved);
147
- if (cached) return cached;
148
- const icon = lookup(resolved);
149
- if (!icon) return null;
150
- const svg = toSvg(icon);
151
- svgByName.set(resolved, svg);
152
- return svg;
153
- }
154
-
155
- export function getSolarImgSrc(name: string): string | null {
156
- const resolved = solarIconName(name);
157
- const hit = imgSrcByName.get(resolved);
158
- if (hit) return hit;
159
- const svg = getSolarSvg(name);
160
- if (!svg) return null;
161
- const src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
162
- imgSrcByName.set(resolved, src);
163
- return src;
164
- }
165
-
166
- export function isSvgIcon(value?: string | null): boolean {
167
- return !!value && value.trimStart().startsWith("<svg");
168
- }
169
-
170
- export function isSolarIcon(value?: string | null): boolean {
171
- return !!value && (value.startsWith(`${ICON_PREFIX}:`) || value.startsWith("fluent-color:"));
172
- }