nish-ui 1.9.0 → 2.0.1

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 (152) hide show
  1. package/README.md +218 -58
  2. package/dist/base-tailwind.css +1757 -0
  3. package/dist/base.css +1590 -1445
  4. package/dist/chart.d.ts +4 -1
  5. package/dist/chart.js +122 -49
  6. package/dist/elements-all.d.ts +8 -0
  7. package/dist/elements-all.js +178 -0
  8. package/dist/elements-charts.d.ts +71 -0
  9. package/dist/elements-charts.js +56 -57
  10. package/dist/elements-data.d.ts +71 -0
  11. package/dist/elements-data.js +5 -6
  12. package/dist/elements-forms.d.ts +71 -0
  13. package/dist/elements-forms.js +24 -25
  14. package/dist/elements.d.ts +71 -0
  15. package/dist/elements.js +4 -5
  16. package/dist/esm/chart-values.js +58 -0
  17. package/dist/esm/chart.js +10 -0
  18. package/dist/esm/cn.js +19 -0
  19. package/dist/esm/combobox-filter.js +13 -0
  20. package/dist/esm/components/accordion.js +166 -0
  21. package/dist/esm/components/app-shell.js +198 -0
  22. package/dist/esm/components/avatar-classes.js +28 -0
  23. package/dist/esm/components/avatar.js +113 -0
  24. package/dist/esm/components/breadcrumbs.js +154 -0
  25. package/dist/esm/components/canvas/follow-caption.js +32 -0
  26. package/dist/esm/components/canvas/follow.js +119 -0
  27. package/dist/esm/components/canvas/icons.js +70 -0
  28. package/dist/esm/components/canvas/index.js +10 -0
  29. package/dist/esm/components/canvas/layout.js +258 -0
  30. package/dist/esm/components/canvas/legend.js +93 -0
  31. package/dist/esm/components/canvas/minimap.js +127 -0
  32. package/dist/esm/components/canvas/node.js +87 -0
  33. package/dist/esm/components/canvas/route.js +262 -0
  34. package/dist/esm/components/canvas/system-canvas.js +837 -0
  35. package/dist/esm/components/canvas/types.js +10 -0
  36. package/dist/esm/components/canvas/view.js +47 -0
  37. package/dist/esm/components/chart-hooks.js +19 -0
  38. package/dist/esm/components/charts.js +467 -0
  39. package/dist/esm/components/client.js +24 -0
  40. package/dist/esm/components/combobox.js +343 -0
  41. package/dist/esm/components/command.js +403 -0
  42. package/dist/esm/components/data-classes.js +159 -0
  43. package/dist/esm/components/data.js +517 -0
  44. package/dist/esm/components/display-classes.js +130 -0
  45. package/dist/esm/components/display.js +755 -0
  46. package/dist/esm/components/error-boundary.js +64 -0
  47. package/dist/esm/components/feedback.js +136 -0
  48. package/dist/esm/components/file-dropzone.js +184 -0
  49. package/dist/esm/components/filters.js +108 -0
  50. package/dist/esm/components/flow.js +746 -0
  51. package/dist/esm/components/forms-classes.js +43 -0
  52. package/dist/esm/components/forms.js +581 -0
  53. package/dist/esm/components/hooks-classes.js +9 -0
  54. package/dist/esm/components/hooks.js +236 -0
  55. package/dist/esm/components/icons.js +96 -0
  56. package/dist/esm/components/inbox-classes.js +29 -0
  57. package/dist/esm/components/inbox.js +257 -0
  58. package/dist/esm/components/latest.js +13 -0
  59. package/dist/esm/components/layout-vars.js +96 -0
  60. package/dist/esm/components/layout.js +272 -0
  61. package/dist/esm/components/media.js +143 -0
  62. package/dist/esm/components/nav.js +614 -0
  63. package/dist/esm/components/overlay-classes.js +66 -0
  64. package/dist/esm/components/overlay.js +1461 -0
  65. package/dist/esm/components/pagination-classes.js +29 -0
  66. package/dist/esm/components/pagination.js +154 -0
  67. package/dist/esm/components/portal.js +16 -0
  68. package/dist/esm/components/primitives-classes.js +198 -0
  69. package/dist/esm/components/primitives.js +268 -0
  70. package/dist/esm/components/progress.js +77 -0
  71. package/dist/esm/components/provider.js +32 -0
  72. package/dist/esm/components/radio-group.js +186 -0
  73. package/dist/esm/components/resource-classes.js +133 -0
  74. package/dist/esm/components/resource.js +209 -0
  75. package/dist/esm/components/segmented.js +178 -0
  76. package/dist/esm/components/separator.js +38 -0
  77. package/dist/esm/components/service-tokens.js +221 -0
  78. package/dist/esm/components/settings.js +301 -0
  79. package/dist/esm/components/slider.js +262 -0
  80. package/dist/esm/components/split-classes.js +8 -0
  81. package/dist/esm/components/split.js +411 -0
  82. package/dist/esm/components/strings.js +119 -0
  83. package/dist/esm/components/table.js +144 -0
  84. package/dist/esm/components/tabs-classes.js +21 -0
  85. package/dist/esm/components/tabs.js +201 -0
  86. package/dist/esm/components/tag-input.js +257 -0
  87. package/dist/esm/components/theme-toggle.js +177 -0
  88. package/dist/esm/components/toast.js +361 -0
  89. package/dist/esm/components/url-state.js +118 -0
  90. package/dist/esm/components/visually-hidden.js +20 -0
  91. package/dist/esm/format.js +320 -0
  92. package/dist/esm/inbox-client.js +2 -0
  93. package/dist/esm/inbox-types.js +2 -0
  94. package/dist/esm/index.js +320 -0
  95. package/dist/esm/runtime.js +37 -0
  96. package/dist/esm/server/inbox/client.js +297 -0
  97. package/dist/esm/server/inbox/types.js +24 -0
  98. package/dist/esm/sparkline-path.js +59 -0
  99. package/dist/esm/split-layout.js +419 -0
  100. package/dist/esm/system-canvas.js +2 -0
  101. package/dist/esm/theme.js +804 -0
  102. package/dist/esm/tokens.mjs +425 -0
  103. package/dist/esm/url.js +20 -0
  104. package/dist/files.json +5 -1
  105. package/dist/fonts/LICENSE-Inter.txt +93 -0
  106. package/dist/format.d.ts +32 -18
  107. package/dist/format.js +227 -82
  108. package/dist/inbox-client.js +3 -1
  109. package/dist/index.d.ts +1686 -667
  110. package/dist/nish-components.css +4649 -4506
  111. package/dist/nish-components.min.css +1 -0
  112. package/dist/nish.css +1603 -1450
  113. package/dist/nish.min.css +1 -0
  114. package/dist/node/eslint.js +29 -14
  115. package/dist/node/th-check.js +29 -14
  116. package/dist/node/vite.d.ts +12 -0
  117. package/dist/node/vite.js +12 -2
  118. package/dist/server/hono.d.ts +15 -6
  119. package/dist/server/hono.js +30 -25
  120. package/dist/server/index.d.ts +3 -10
  121. package/dist/server/index.js +71 -38
  122. package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
  123. package/dist/system-canvas-BLuWd69H.d.ts +183 -0
  124. package/dist/system-canvas.d.ts +2 -168
  125. package/dist/tailwind-core.css +114 -0
  126. package/dist/tailwind.css +3 -7
  127. package/dist/theme-init.js +23 -9
  128. package/dist/theme-init.sha256 +1 -0
  129. package/dist/theme.d.ts +243 -4
  130. package/dist/theme.global.js +356 -89
  131. package/dist/theme.js +337 -67
  132. package/dist/tokens.css +14 -6
  133. package/dist/tokens.dtcg.json +1513 -0
  134. package/dist/tokens.js +29 -14
  135. package/dist/tokens.json +512 -0
  136. package/package.json +51 -13
  137. package/dist/chart.js.map +0 -1
  138. package/dist/elements-charts.js.map +0 -1
  139. package/dist/elements-data.js.map +0 -1
  140. package/dist/elements-forms.js.map +0 -1
  141. package/dist/elements.js.map +0 -1
  142. package/dist/format.js.map +0 -1
  143. package/dist/inbox-client.js.map +0 -1
  144. package/dist/index.js +0 -10260
  145. package/dist/index.js.map +0 -1
  146. package/dist/server/hono.js.map +0 -1
  147. package/dist/server/index.js.map +0 -1
  148. package/dist/split-layout.js.map +0 -1
  149. package/dist/system-canvas.js +0 -2204
  150. package/dist/system-canvas.js.map +0 -1
  151. package/dist/theme.global.js.map +0 -1
  152. package/dist/theme.js.map +0 -1
@@ -0,0 +1,517 @@
1
+ "use client";
2
+
3
+ // src/components/data.tsx
4
+ import {
5
+ memo,
6
+ useCallback,
7
+ useId,
8
+ useMemo,
9
+ useRef,
10
+ useState
11
+ } from "react";
12
+ import { cn } from "../cn.js";
13
+ import { safeUrl } from "../url.js";
14
+ import { useIsoLayoutEffect } from "./client.js";
15
+ import {
16
+ FAVICON_HUES,
17
+ getFaviconResolver,
18
+ hashString,
19
+ hostnameOf,
20
+ mergeRefs,
21
+ sortRows,
22
+ warnOnce
23
+ } from "./data-classes.js";
24
+ import { useMediaQuery } from "./hooks.js";
25
+ import { StatusDot } from "./display.js";
26
+ import { CardListSkeleton, EmptyState, ErrorState, SkeletonRows } from "./feedback.js";
27
+ import { useLatest } from "./latest.js";
28
+ import { useNishStrings } from "./provider.js";
29
+ import { Table, TableWrap, Td, Th, Tr } from "./table.js";
30
+ import { cardClass, IconButton, Select } from "./primitives.js";
31
+ import { configureFavicons, googleFavicon } from "./data-classes.js";
32
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
33
+ function Glyph({ size = 16, children, ...rest }) {
34
+ return /* @__PURE__ */ jsx(
35
+ "svg",
36
+ {
37
+ width: size,
38
+ height: size,
39
+ viewBox: "0 0 24 24",
40
+ fill: "none",
41
+ stroke: "currentColor",
42
+ strokeWidth: 2,
43
+ strokeLinecap: "round",
44
+ strokeLinejoin: "round",
45
+ "aria-hidden": "true",
46
+ focusable: "false",
47
+ ...rest,
48
+ children
49
+ }
50
+ );
51
+ }
52
+ var ChevronRight = (p) => /* @__PURE__ */ jsx(Glyph, { ...p, className: cn("rtl:-scale-x-100", p.className), children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" }) });
53
+ var ExternalGlyph = (p) => /* @__PURE__ */ jsx(Glyph, { ...p, children: /* @__PURE__ */ jsx("path", { d: "M15 3h6v6M10 14 21 3M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }) });
54
+ var ArrowUp = (p) => /* @__PURE__ */ jsx(Glyph, { ...p, children: /* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7M12 19V5" }) });
55
+ var ArrowDown = (p) => /* @__PURE__ */ jsx(Glyph, { ...p, children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M19 12l-7 7-7-7" }) });
56
+ function fromInteractive(e) {
57
+ const el = e.target?.closest?.('a,button,input,select,textarea,label,summary,[role="button"],[role="link"]');
58
+ return !!el && el !== e.currentTarget && e.currentTarget.contains(el);
59
+ }
60
+ var TABLE_SHOW = { sm: "hidden sm:block", md: "hidden md:block", lg: "hidden lg:block" };
61
+ var BP_PX = { sm: 640, md: 768, lg: 1024 };
62
+ var CARDS_SHOW = { sm: "sm:hidden", md: "md:hidden", lg: "lg:hidden" };
63
+ var HIDE_BELOW = {
64
+ sm: "hidden sm:table-cell",
65
+ md: "hidden md:table-cell",
66
+ lg: "hidden lg:table-cell"
67
+ };
68
+ var TONE_EDGE = {
69
+ ok: "border-s-[3px] border-s-[var(--nish-ok-fill)]",
70
+ warn: "border-s-[3px] border-s-[var(--nish-warn-fill)]",
71
+ loss: "border-s-[3px] border-s-[var(--nish-loss-fill)]"
72
+ };
73
+ var DEFAULT_SORT_TEXT = {
74
+ announce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
75
+ toggle: (dir) => dir === "desc" ? "Sorted descending, switch to ascending" : "Sorted ascending, switch to descending"
76
+ };
77
+ var BodyRow = /* @__PURE__ */ memo(function BodyRow2({ row, columns, tone, interactive, onGo }) {
78
+ return /* @__PURE__ */ jsx(
79
+ Tr,
80
+ {
81
+ tone,
82
+ interactive,
83
+ tabIndex: interactive ? 0 : void 0,
84
+ onClick: interactive ? (e) => {
85
+ if (!fromInteractive(e)) onGo(row, e);
86
+ } : void 0,
87
+ onKeyDown: interactive ? (e) => {
88
+ if (e.target !== e.currentTarget) return;
89
+ if (e.key === "Enter" || e.key === " ") {
90
+ e.preventDefault();
91
+ onGo(row, e);
92
+ }
93
+ } : void 0,
94
+ children: columns.map((c) => /* @__PURE__ */ jsx(Td, { numeric: c.numeric, className: cn(c.hideBelow && HIDE_BELOW[c.hideBelow]), children: c.cell(row) }, c.key))
95
+ }
96
+ );
97
+ });
98
+ function ResponsiveTable({
99
+ rows,
100
+ columns,
101
+ rowKey,
102
+ cardsBelow = "md",
103
+ onRowClick,
104
+ rowHref,
105
+ onNavigate,
106
+ rowTone,
107
+ sort,
108
+ onSortChange,
109
+ minWidth = 640,
110
+ stickyHeader,
111
+ maxHeight,
112
+ stickyFirstColumn,
113
+ loading = false,
114
+ empty,
115
+ error,
116
+ label,
117
+ renderCard,
118
+ sortText,
119
+ className,
120
+ ref,
121
+ ...rest
122
+ }) {
123
+ const t = useNishStrings();
124
+ const text = { ...DEFAULT_SORT_TEXT, ...sortText };
125
+ const [innerSort, setInnerSort] = useState(null);
126
+ const [announcement, setAnnouncement] = useState("");
127
+ const sortId = useId();
128
+ const wide = useMediaQuery(`(min-width: ${BP_PX[cardsBelow]}px)`);
129
+ const external = sort !== void 0 || onSortChange !== void 0;
130
+ const current = sort !== void 0 ? sort : innerSort;
131
+ const sortKey = current?.key;
132
+ const sortDir = current?.dir;
133
+ const changeSort = (next) => {
134
+ setInnerSort(next);
135
+ onSortChange?.(next);
136
+ const header = columns.find((c) => c.key === next?.key)?.header ?? "";
137
+ setAnnouncement(text.announce(header, next ? next.dir : null));
138
+ };
139
+ const sorted = useMemo(() => {
140
+ if (external || !sortKey || !sortDir) return rows;
141
+ const get = columns.find((c) => c.key === sortKey)?.sortValue;
142
+ return get ? sortRows(rows, get, sortDir) : rows;
143
+ }, [rows, sortKey, sortDir, external]);
144
+ const sortable = columns.filter((c) => c.sortValue);
145
+ const toggle = (key) => changeSort(current?.key === key ? { key, dir: current.dir === "asc" ? "desc" : "asc" } : { key, dir: "asc" });
146
+ const interactive = !!(onRowClick || rowHref);
147
+ const latest = useLatest({ onRowClick, rowHref, onNavigate });
148
+ const go = useCallback((row, e) => {
149
+ const { onRowClick: click, rowHref: hrefOf, onNavigate: navigate } = latest.current;
150
+ if (!hrefOf) return click?.(row);
151
+ const raw = hrefOf(row);
152
+ const href = safeUrl(raw);
153
+ if (href === null) {
154
+ warnOnce("table-href", `ResponsiveTable ignored an unsafe rowHref (${JSON.stringify(raw)}).`);
155
+ return;
156
+ }
157
+ if (e.metaKey || e.ctrlKey || e.shiftKey || "button" in e && e.button === 1) window.open(href, "_blank", "noopener");
158
+ else if (navigate) navigate(href);
159
+ else window.location.assign(href);
160
+ }, [latest]);
161
+ if (error) return /* @__PURE__ */ jsx(ErrorState, { message: error.message, onRetry: error.onRetry, className });
162
+ const emptyNode = empty ?? /* @__PURE__ */ jsx(EmptyState, { title: t.nothingHere });
163
+ const hasRows = sorted.length > 0;
164
+ const table = !wide ? null : loading ? /* @__PURE__ */ jsx(SkeletonRows, { rows: 5, height: 44, label: t.loadingNamed(label) }) : !hasRows ? emptyNode : /* @__PURE__ */ jsx(TableWrap, { minWidth, stickyHeader, maxHeight, stickyFirstColumn, label, children: /* @__PURE__ */ jsxs(Table, { "aria-label": label, children: [
165
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((c) => /* @__PURE__ */ jsx(
166
+ Th,
167
+ {
168
+ numeric: c.numeric,
169
+ sort: c.sortValue ? current?.key === c.key ? current.dir : false : void 0,
170
+ onSort: c.sortValue ? () => toggle(c.key) : void 0,
171
+ className: cn(c.hideBelow && HIDE_BELOW[c.hideBelow]),
172
+ style: c.width ? { width: c.width } : void 0,
173
+ children: c.header
174
+ },
175
+ c.key
176
+ )) }) }),
177
+ /* @__PURE__ */ jsx("tbody", { children: sorted.map((row) => /* @__PURE__ */ jsx(BodyRow, { row, columns, tone: rowTone?.(row), interactive, onGo: go }, rowKey(row))) })
178
+ ] }) });
179
+ const primary = columns.find((c) => c.primary) ?? columns[0];
180
+ const secondary = columns.find((c) => c.secondary && c !== primary);
181
+ const rest2 = columns.filter((c) => c !== primary && c !== secondary);
182
+ const cardBody = (row) => renderCard ? renderCard(row) : /* @__PURE__ */ jsxs(Fragment, { children: [
183
+ /* @__PURE__ */ jsxs("span", { className: "block min-w-0", children: [
184
+ /* @__PURE__ */ jsx("span", { className: "block truncate font-semibold text-th-hi", children: primary?.cell(row) }),
185
+ secondary ? /* @__PURE__ */ jsx("span", { className: "mt-0.5 block text-sm text-th-hi3", children: secondary.cell(row) }) : null
186
+ ] }),
187
+ rest2.length > 0 ? /* @__PURE__ */ jsx("span", { className: "mt-2 grid grid-cols-2 gap-x-4 gap-y-1.5 text-sm", children: rest2.map((c) => /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-baseline justify-between gap-2", children: [
188
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs text-th-hi3", children: c.header }),
189
+ /* @__PURE__ */ jsx("span", { className: cn("min-w-0 text-th-hi2", c.numeric && "whitespace-nowrap text-end tabular-nums"), children: c.cell(row) })
190
+ ] }, c.key)) }) : null
191
+ ] });
192
+ const cardClassFor = (tone, live) => cardClass({
193
+ padding: "sm",
194
+ interactive: live,
195
+ className: cn("block min-h-11 w-full text-start", tone && TONE_EDGE[tone])
196
+ });
197
+ const cardItem = (row) => {
198
+ const tone = rowTone?.(row);
199
+ const href = rowHref ? safeUrl(rowHref(row)) : null;
200
+ if (rowHref && href === null) warnOnce("table-href", `ResponsiveTable ignored an unsafe rowHref (${JSON.stringify(rowHref(row))}).`);
201
+ if (href !== null) {
202
+ return /* @__PURE__ */ jsx("a", { href, className: cardClassFor(tone, true), children: cardBody(row) });
203
+ }
204
+ if (onRowClick) {
205
+ return /* @__PURE__ */ jsx("button", { type: "button", onClick: () => onRowClick(row), className: cardClassFor(tone, true), children: cardBody(row) });
206
+ }
207
+ return /* @__PURE__ */ jsx("div", { className: cardClassFor(tone, false), children: cardBody(row) });
208
+ };
209
+ const cards = wide ? null : loading ? /* @__PURE__ */ jsx(CardListSkeleton, { count: 3, lines: 2 }) : !hasRows ? emptyNode : /* @__PURE__ */ jsxs(Fragment, { children: [
210
+ sortable.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center gap-2", children: [
211
+ /* @__PURE__ */ jsx("label", { className: "shrink-0 text-xs text-th-hi3", htmlFor: sortId, children: t.sortBy }),
212
+ /* @__PURE__ */ jsxs(
213
+ Select,
214
+ {
215
+ id: sortId,
216
+ size: "sm",
217
+ className: "min-w-0 flex-1",
218
+ value: current?.key ?? "",
219
+ onChange: (e) => changeSort(e.target.value ? { key: e.target.value, dir: current?.dir ?? "asc" } : null),
220
+ children: [
221
+ /* @__PURE__ */ jsx("option", { value: "", children: t.sortDefault }),
222
+ sortable.map((c) => /* @__PURE__ */ jsx("option", { value: c.key, children: c.header }, c.key))
223
+ ]
224
+ }
225
+ ),
226
+ /* @__PURE__ */ jsx(
227
+ IconButton,
228
+ {
229
+ label: text.toggle(current ? current.dir : null),
230
+ variant: "subtle",
231
+ disabled: !current,
232
+ onClick: () => current && changeSort({ key: current.key, dir: current.dir === "asc" ? "desc" : "asc" }),
233
+ children: current?.dir === "desc" ? /* @__PURE__ */ jsx(ArrowDown, { size: 16 }) : /* @__PURE__ */ jsx(ArrowUp, { size: 16 })
234
+ }
235
+ )
236
+ ] }) : null,
237
+ /* @__PURE__ */ jsx("ul", { "aria-label": label, className: "grid gap-2", children: sorted.map((row) => /* @__PURE__ */ jsx("li", { children: cardItem(row) }, rowKey(row))) })
238
+ ] });
239
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, className, children: [
240
+ wide ? /* @__PURE__ */ jsx("div", { className: TABLE_SHOW[cardsBelow], children: table }) : /* @__PURE__ */ jsx("div", { className: CARDS_SHOW[cardsBelow], children: cards }),
241
+ /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", className: "sr-only", children: announcement })
242
+ ] });
243
+ }
244
+ function ListRow({
245
+ icon,
246
+ title,
247
+ titleLines = 1,
248
+ subtitle,
249
+ meta,
250
+ trailing,
251
+ href,
252
+ onClick,
253
+ active = false,
254
+ tone,
255
+ chevron,
256
+ dense = false,
257
+ compact = false,
258
+ external = false,
259
+ className,
260
+ as: wrapperTag = "li",
261
+ ref,
262
+ ...rest
263
+ }) {
264
+ const Wrapper = wrapperTag;
265
+ const url = href === void 0 ? null : safeUrl(href);
266
+ const interactive = !!(url || onClick);
267
+ const showChevron = chevron ?? !!url;
268
+ const rowClass = cn(
269
+ "flex w-full items-center rounded-[var(--nish-radius-sm)] px-3 text-start",
270
+ compact ? "gap-2.5" : "gap-3",
271
+ dense || compact ? "min-h-11" : "min-h-[52px]",
272
+ !subtitle && "py-1",
273
+ subtitle && (compact ? "py-1.5" : "py-2"),
274
+ interactive && "transition-colors hover:bg-th-elevated focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-th-accent",
275
+ // The active row is shown by a tint; forced colors drop it, so it gets an outline.
276
+ active && "bg-th-accent-soft forced-colors:outline forced-colors:outline-2 forced-colors:outline-[color:Highlight]",
277
+ className
278
+ );
279
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
280
+ icon ? /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-center text-th-hi3 [&>svg]:size-5", children: icon }) : null,
281
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
282
+ /* @__PURE__ */ jsx(
283
+ "span",
284
+ {
285
+ className: cn(
286
+ "block",
287
+ titleLines === 2 ? "line-clamp-2 break-words" : "truncate",
288
+ compact && "text-2xs font-medium leading-snug",
289
+ tone === "danger" ? "text-th-loss" : "text-th-hi"
290
+ ),
291
+ children: title
292
+ }
293
+ ),
294
+ subtitle ? /* @__PURE__ */ jsx("span", { className: cn("line-clamp-2 block", compact ? "mt-0.5 text-3xs" : "text-sm", active ? "text-th-hi2" : "text-th-hi3"), children: subtitle }) : null
295
+ ] }),
296
+ meta ? /* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-end tabular-nums", compact ? "text-3xs" : "text-xs", active ? "text-th-hi2" : "text-th-hi3"), children: meta }) : null,
297
+ trailing ? /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-center", children: trailing }) : null,
298
+ external ? /* @__PURE__ */ jsx(ExternalGlyph, { size: 14, className: "shrink-0 text-th-hi3" }) : null,
299
+ showChevron && !external ? /* @__PURE__ */ jsx(ChevronRight, { size: compact ? 13 : 16, className: "shrink-0 text-th-ghost" }) : null
300
+ ] });
301
+ let inner;
302
+ if (url) {
303
+ inner = /* @__PURE__ */ jsx(
304
+ "a",
305
+ {
306
+ href: url,
307
+ className: rowClass,
308
+ "aria-current": active ? "true" : void 0,
309
+ ...external ? { target: "_blank", rel: "noopener noreferrer" } : null,
310
+ children: body
311
+ }
312
+ );
313
+ } else if (onClick) {
314
+ inner = /* @__PURE__ */ jsx("button", { type: "button", onClick, className: rowClass, "aria-current": active ? "true" : void 0, children: body });
315
+ } else {
316
+ inner = /* @__PURE__ */ jsx("div", { className: rowClass, children: body });
317
+ }
318
+ return /* @__PURE__ */ jsx(Wrapper, { ...rest, ref, className: "min-w-0", children: inner });
319
+ }
320
+ function Favicon({ url, size = 16, label, src, resolve, className, style, ref, ...rest }) {
321
+ const host = hostnameOf(url);
322
+ const imgSrc = useMemo(() => {
323
+ const own = src !== void 0 ? safeUrl(src) : host ? (resolve ?? getFaviconResolver())(host, size) : null;
324
+ return own === null ? null : safeUrl(own);
325
+ }, [src, host, resolve, size]);
326
+ const [seen, setSeen] = useState(null);
327
+ const status = imgSrc && seen?.src === imgSrc ? seen.status : "loading";
328
+ const box = { width: size, height: size };
329
+ if (!imgSrc || status === "failed") {
330
+ const seed = label ?? host ?? url;
331
+ const n = hashString(seed) % FAVICON_HUES + 1;
332
+ const letter = (seed.replace(/^www\./, "").match(/[\p{L}\p{N}]/u)?.[0] ?? "?").toUpperCase();
333
+ return /* @__PURE__ */ jsx(
334
+ "span",
335
+ {
336
+ "aria-hidden": "true",
337
+ ...rest,
338
+ ref,
339
+ className: cn("inline-flex shrink-0 select-none items-center justify-center rounded-sm font-semibold leading-none", className),
340
+ style: {
341
+ ...box,
342
+ fontSize: Math.round(size * 0.6),
343
+ color: `var(--nish-chart-${n})`,
344
+ background: `color-mix(in srgb, var(--nish-chart-${n}) 20%, transparent)`,
345
+ ...style
346
+ },
347
+ children: letter
348
+ }
349
+ );
350
+ }
351
+ return /* @__PURE__ */ jsx(
352
+ "img",
353
+ {
354
+ "aria-hidden": "true",
355
+ ...rest,
356
+ ref,
357
+ src: imgSrc,
358
+ width: size,
359
+ height: size,
360
+ alt: "",
361
+ loading: "lazy",
362
+ decoding: "async",
363
+ referrerPolicy: "no-referrer",
364
+ onLoad: () => setSeen({ src: imgSrc, status: "loaded" }),
365
+ onError: () => setSeen({ src: imgSrc, status: "failed" }),
366
+ className: cn("inline-block shrink-0 rounded-sm transition-opacity duration-150 motion-reduce:transition-none", status === "loaded" ? "opacity-100" : "opacity-0", className),
367
+ style: { ...box, ...style }
368
+ }
369
+ );
370
+ }
371
+ var AUTO_BREAK = 600;
372
+ var widthWatches = /* @__PURE__ */ new WeakMap();
373
+ function watchWidth(el, fn) {
374
+ fn(el.clientWidth);
375
+ if (typeof ResizeObserver === "undefined") return () => {
376
+ };
377
+ let w = widthWatches.get(el);
378
+ if (!w) {
379
+ const subs = /* @__PURE__ */ new Set();
380
+ const ro = new ResizeObserver(() => {
381
+ const width = el.clientWidth;
382
+ subs.forEach((f) => f(width));
383
+ });
384
+ ro.observe(el);
385
+ w = { ro, subs };
386
+ widthWatches.set(el, w);
387
+ }
388
+ w.subs.add(fn);
389
+ const watch = w;
390
+ return () => {
391
+ watch.subs.delete(fn);
392
+ if (!watch.subs.size) {
393
+ watch.ro.disconnect();
394
+ widthWatches.delete(el);
395
+ }
396
+ };
397
+ }
398
+ function LinkCard({
399
+ href,
400
+ title,
401
+ blurb,
402
+ icon,
403
+ favicon = false,
404
+ accent = "accent",
405
+ meta,
406
+ status,
407
+ badge,
408
+ disabled = false,
409
+ layout = "auto",
410
+ external = false,
411
+ className,
412
+ ref: forwardedRef,
413
+ ...rest
414
+ }) {
415
+ const ref = useRef(null);
416
+ const [wide, setWide] = useState(false);
417
+ const url = safeUrl(href);
418
+ const dead = disabled || url === null;
419
+ if (!disabled && url === null) warnOnce("linkcard-href", `LinkCard ignored an unsafe href (${JSON.stringify(href)}).`);
420
+ useIsoLayoutEffect(() => {
421
+ if (layout !== "auto") return;
422
+ const parent = ref.current?.parentElement;
423
+ if (!parent) return;
424
+ return watchWidth(parent, (w) => setWide(w >= AUTO_BREAK));
425
+ }, [layout]);
426
+ const isCard = layout === "card" || layout === "auto" && wide;
427
+ const color = accent === "accent" ? "var(--nish-accent)" : `var(--nish-${accent})`;
428
+ const glyph = icon ?? (favicon ? /* @__PURE__ */ jsx(Favicon, { url: href, size: 20, label: title }) : null);
429
+ const tile = glyph ? /* @__PURE__ */ jsx(
430
+ "span",
431
+ {
432
+ "aria-hidden": "true",
433
+ className: cn("flex shrink-0 items-center justify-center rounded-[var(--nish-radius-sm)] [&>svg]:size-5", isCard ? "size-10" : "size-9"),
434
+ style: { color, background: `color-mix(in srgb, ${color} 16%, transparent)` },
435
+ children: glyph
436
+ }
437
+ ) : null;
438
+ const statusEl = status ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5 text-xs text-th-hi3", children: [
439
+ /* @__PURE__ */ jsx(StatusDot, { tone: status.tone, size: "xs" }),
440
+ status.label
441
+ ] }) : null;
442
+ const base = cn(
443
+ "group/link @container flex min-h-11 rounded-xl border bg-th-surface text-start",
444
+ dead ? "border-dashed border-th-line-strong text-th-hi3" : "border-th-line shadow-card",
445
+ !dead && "transition-[transform,box-shadow,border-color,background-color] duration-150 hover:border-th-line-strong hover:bg-th-elevated/60 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent [@media(hover:hover)]:hover:-translate-y-0.5 [@media(hover:hover)]:hover:shadow-pop",
446
+ isCard ? "flex-col gap-3 p-4" : "min-h-16 items-center gap-3 px-3 py-2",
447
+ className
448
+ );
449
+ const content = isCard ? /* @__PURE__ */ jsxs(Fragment, { children: [
450
+ /* @__PURE__ */ jsxs("span", { className: "flex items-start justify-between gap-2", children: [
451
+ tile ?? /* @__PURE__ */ jsx("span", {}),
452
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
453
+ badge,
454
+ external ? /* @__PURE__ */ jsx(ExternalGlyph, { size: 14, className: "text-th-hi3" }) : null
455
+ ] })
456
+ ] }),
457
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0", children: [
458
+ /* @__PURE__ */ jsx("span", { className: cn("block font-semibold", dead ? "text-th-hi2" : "text-th-hi"), children: title }),
459
+ blurb ? /* @__PURE__ */ jsx("span", { className: "mt-1 line-clamp-3 block text-sm text-th-hi3", children: blurb }) : null
460
+ ] }),
461
+ meta || statusEl ? /* @__PURE__ */ jsxs("span", { className: "mt-auto flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-th-hi3", children: [
462
+ statusEl,
463
+ meta
464
+ ] }) : null
465
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
466
+ tile,
467
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
468
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
469
+ /* @__PURE__ */ jsx("span", { className: cn("truncate font-semibold", dead ? "text-th-hi2" : "text-th-hi"), children: title }),
470
+ status ? /* @__PURE__ */ jsx(StatusDot, { tone: status.tone, size: "xs", label: status.label }) : null
471
+ ] }),
472
+ blurb ? /* @__PURE__ */ jsx("span", { className: "line-clamp-1 block text-sm text-th-hi3", children: blurb }) : null
473
+ ] }),
474
+ badge,
475
+ external ? /* @__PURE__ */ jsx(ExternalGlyph, { size: 14, className: "shrink-0 text-th-hi3" }) : /* @__PURE__ */ jsx(ChevronRight, { size: 16, className: "shrink-0 text-th-ghost" })
476
+ ] });
477
+ if (dead) {
478
+ return /* @__PURE__ */ jsx("span", { ...rest, ref: mergeRefs(ref, forwardedRef), "aria-disabled": "true", className: base, children: content });
479
+ }
480
+ return /* @__PURE__ */ jsx(
481
+ "a",
482
+ {
483
+ ...rest,
484
+ ref: mergeRefs(ref, forwardedRef),
485
+ href: url,
486
+ className: base,
487
+ ...external ? { target: "_blank", rel: "noopener noreferrer" } : null,
488
+ children: content
489
+ }
490
+ );
491
+ }
492
+ function AsyncPanel({ status, skeleton, error, empty, children, className, ref, ...rest }) {
493
+ const t = useNishStrings();
494
+ let body;
495
+ if (status === "loading") body = skeleton ?? /* @__PURE__ */ jsx(SkeletonRows, {});
496
+ else if (status === "error")
497
+ body = /* @__PURE__ */ jsx(
498
+ ErrorState,
499
+ {
500
+ message: error?.title ? `${error.title}: ${error.message}` : error?.message ?? t.failedToLoad,
501
+ onRetry: error?.onRetry
502
+ }
503
+ );
504
+ else if (status === "empty")
505
+ body = /* @__PURE__ */ jsx(EmptyState, { title: empty?.title ?? t.nothingHere, detail: empty?.description, action: empty?.action });
506
+ else body = children;
507
+ return /* @__PURE__ */ jsx("div", { ...rest, ref, "aria-busy": status === "loading" || void 0, className, children: body });
508
+ }
509
+ export {
510
+ AsyncPanel,
511
+ Favicon,
512
+ LinkCard,
513
+ ListRow,
514
+ ResponsiveTable,
515
+ configureFavicons,
516
+ googleFavicon
517
+ };
@@ -0,0 +1,130 @@
1
+ // src/components/display-classes.ts
2
+ var warned = /* @__PURE__ */ new Set();
3
+ function warnDev(message) {
4
+ if (warned.has(message)) return;
5
+ try {
6
+ if (process.env.NODE_ENV !== "production") {
7
+ warned.add(message);
8
+ console.warn(message);
9
+ }
10
+ } catch {
11
+ }
12
+ }
13
+ var FILL = {
14
+ ok: "bg-th-ok-fill",
15
+ warn: "bg-th-warn-fill",
16
+ loss: "bg-th-loss-fill",
17
+ info: "bg-th-info-fill",
18
+ accent: "bg-th-accent",
19
+ neutral: "bg-th-ghost"
20
+ };
21
+ var CALLOUT_TONE = {
22
+ neutral: { box: "border-th-line bg-th-elevated", bar: "border-th-line bg-th-elevated", icon: "text-th-hi3" },
23
+ accent: { box: "border-th-accent/30 bg-th-accent-soft", bar: "border-th-accent/30 bg-th-accent-soft-solid", icon: "text-th-accent" },
24
+ info: { box: "border-th-info/30 bg-th-info-soft", bar: "border-th-info/30 bg-th-info-soft-solid", icon: "text-th-info" },
25
+ ok: { box: "border-th-ok/30 bg-th-ok-soft", bar: "border-th-ok/30 bg-th-ok-soft-solid", icon: "text-th-ok" },
26
+ warn: { box: "border-th-warn/30 bg-th-warn-soft", bar: "border-th-warn/30 bg-th-warn-soft-solid", icon: "text-th-warn" },
27
+ loss: { box: "border-th-loss/30 bg-th-loss-soft", bar: "border-th-loss/30 bg-th-loss-soft-solid", icon: "text-th-loss" }
28
+ };
29
+ var CALLOUT_CLAMP = { 1: "line-clamp-1", 2: "line-clamp-2", 3: "line-clamp-3" };
30
+ var DOT_SIZE = { xs: "size-1.5", sm: "size-2", md: "size-2.5", lg: "size-3.5" };
31
+ var HALO = {
32
+ ok: "ring-4 ring-th-ok-fill/25",
33
+ warn: "ring-4 ring-th-warn-fill/25",
34
+ loss: "ring-4 ring-th-loss-fill/25",
35
+ info: "ring-4 ring-th-info-fill/25",
36
+ accent: "ring-4 ring-th-accent/25",
37
+ neutral: "ring-4 ring-th-ghost/25"
38
+ };
39
+ function signTone(n) {
40
+ if (n == null || Number.isNaN(n) || n === 0) return "neutral";
41
+ return n > 0 ? "ok" : "loss";
42
+ }
43
+ var STAT_VALUE_SIZE = { sm: "text-base", md: "text-xl", lg: "text-2xl" };
44
+ var STAT_SKELETON = { sm: "h-6", md: "h-7", lg: "h-8" };
45
+ var STAT_TONE = { ok: "text-th-ok", loss: "text-th-loss", warn: "text-th-warn", neutral: "text-th-hi" };
46
+ var GRID_BASE = { 1: "grid-cols-1", 2: "grid-cols-2", 3: "grid-cols-3", 4: "grid-cols-4" };
47
+ var GRID_MD = {
48
+ 2: "md:grid-cols-2",
49
+ 3: "md:grid-cols-3",
50
+ 4: "md:grid-cols-4",
51
+ 5: "md:grid-cols-5",
52
+ 6: "md:grid-cols-6"
53
+ };
54
+ function toneFor(value, t) {
55
+ if (t.loss >= t.warn) return value >= t.loss ? "loss" : value >= t.warn ? "warn" : "ok";
56
+ return value <= t.loss ? "loss" : value <= t.warn ? "warn" : "ok";
57
+ }
58
+ var METER_FILL = {
59
+ accent: "bg-th-accent",
60
+ ok: "bg-th-ok-fill",
61
+ warn: "bg-th-warn-fill",
62
+ loss: "bg-th-loss-fill",
63
+ info: "bg-th-info-fill",
64
+ neutral: "bg-th-hi3",
65
+ "chart-1": "bg-th-chart-1",
66
+ "chart-2": "bg-th-chart-2",
67
+ "chart-3": "bg-th-chart-3",
68
+ "chart-4": "bg-th-chart-4",
69
+ "chart-5": "bg-th-chart-5",
70
+ "chart-6": "bg-th-chart-6",
71
+ "chart-7": "bg-th-chart-7",
72
+ "chart-8": "bg-th-chart-8"
73
+ };
74
+ var METER_THICK = { xs: "h-1", sm: "h-1.5", md: "h-2.5" };
75
+ var METER_THICK_V = { xs: "w-1", sm: "w-1.5", md: "w-2.5" };
76
+ var SPARK_TONE = {
77
+ accent: "text-th-accent",
78
+ ok: "text-th-ok-fill",
79
+ warn: "text-th-warn-fill",
80
+ loss: "text-th-loss-fill",
81
+ info: "text-th-info-fill",
82
+ "chart-1": "text-th-chart-1",
83
+ "chart-2": "text-th-chart-2",
84
+ "chart-3": "text-th-chart-3",
85
+ "chart-4": "text-th-chart-4",
86
+ "chart-5": "text-th-chart-5",
87
+ "chart-6": "text-th-chart-6",
88
+ "chart-7": "text-th-chart-7",
89
+ "chart-8": "text-th-chart-8"
90
+ };
91
+ var LEGEND_FILL = {
92
+ "chart-1": "bg-th-chart-1",
93
+ "chart-2": "bg-th-chart-2",
94
+ "chart-3": "bg-th-chart-3",
95
+ "chart-4": "bg-th-chart-4",
96
+ "chart-5": "bg-th-chart-5",
97
+ "chart-6": "bg-th-chart-6",
98
+ "chart-7": "bg-th-chart-7",
99
+ "chart-8": "bg-th-chart-8",
100
+ accent: "bg-th-accent",
101
+ ok: "bg-th-ok-fill",
102
+ warn: "bg-th-warn-fill",
103
+ loss: "bg-th-loss-fill",
104
+ info: "bg-th-info-fill"
105
+ };
106
+ var displayInternals = {
107
+ FILL,
108
+ CALLOUT_TONE,
109
+ CALLOUT_CLAMP,
110
+ DOT_SIZE,
111
+ HALO,
112
+ STAT_VALUE_SIZE,
113
+ STAT_SKELETON,
114
+ STAT_TONE,
115
+ GRID_BASE,
116
+ GRID_MD,
117
+ METER_FILL,
118
+ METER_THICK,
119
+ METER_THICK_V,
120
+ SPARK_TONE,
121
+ LEGEND_FILL
122
+ };
123
+ var FORCED_MARK = "forced-colors:forced-color-adjust-none forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]";
124
+ export {
125
+ FORCED_MARK,
126
+ displayInternals,
127
+ signTone,
128
+ toneFor,
129
+ warnDev
130
+ };