@hanzo/ui 8.0.22 → 8.0.23

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.
@@ -1,2235 +1,8 @@
1
1
  'use client';
2
- import { ThemeToggle } from '../chunk-77AMCLN4.js';
2
+ export { AnimatedLogo, AppHeader, BRANDS, BarChart, BarRows, BrandMark, CHART_OTHER, CHART_PALETTE, ComboBox, CommerceResource, ConfirmDelete, ContextMenu, Boxes as CustomModelMark, Donut, Donut2 as DonutRing, DropdownMenu, FadeIn, FloatingMenu, GenericLogo, HANZO, HANZO_MARK_CONTENT, HanzoMark, HintButton, LUX, LegendDot, LineChart, MenuItemView, MenuLabelView, MenuPanel, MenuSeparatorView, MetricCard, Sparkline2 as MetricSparkline, MiniBars, OrgMark, OrgSwitcher, PARS, Panel, PortalTheme, ProductIcon, ProviderLogo, Reorder, SERIES, SURFACES, SearchInput, Segmented, SelectMenu, SiteFooter, SiteNav, Sparkline, ToastProvider, UtilBar, ZOO, colorForIndex, filterOptions, filterOrgs, isKnownOption, monogram, orgScope, otherSurfaces, providerInitials, renderMenuItems, resolveBrand, rowShift, targetIndex, useContainerWidth, useToast, utilColor } from '../chunk-7P7R7FC5.js';
3
3
  export { AgnosticThemeToggle, ThemeToggle, ThemeToggleNext } from '../chunk-77AMCLN4.js';
4
- import { classifyBackend, PageHeader, BackendStateCard, DataTable, asColor } from '../chunk-P2P6ST6J.js';
5
4
  export { BackendStateCard, COMPOSE_MODES, CampaignCard, ChannelBadge, DataTable, EmptyState, FieldRow, FieldSelect, FieldSlider, FieldSwitch, FieldText, FieldTextArea, HostProvider, PageHeader, PostAgenda, PostCard, PostComposer, PrimaryButton, ProviderReadinessList, LG as SLIDEOVER_LG, SlideOver, SocialResource, SocialSummaryBar, StatusTag, ViewToggle, accentFor, asColor, classifyBackend, classifyRead, contrastText, formatPostTime, isHexColor, parsePostTime, postDayBucket, postPreview, resolveAccent, setOrgAccent, useAccent, useHost } from '../chunk-P2P6ST6J.js';
6
- import { useEmit, textSize, labelOf } from '../chunk-FVQXROBK.js';
7
5
  export { InstrumentSurface, emit, labelOf, textSize, useEmit, useSurface } from '../chunk-FVQXROBK.js';
8
6
  export { ACCOUNT_STATUSES, POST_STATUSES, PROVIDERS, createSocialApi, normalizeAccount, normalizeAccounts, normalizePost, normalizePosts, normalizeProviderCapability, normalizeProviders, normalizeSummary } from '../chunk-ZGTJCJ55.js';
9
- import { createContext, useRef, useState, useEffect, useCallback, useLayoutEffect, useMemo, cloneElement, useContext } from 'react';
10
- import { useTheme, XStack, Text, YStack, Card, Theme, useThemeName, Portal, Input, Button, Spinner, Popover, Separator, useControllableState } from '@hanzo/gui';
11
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
12
- import { Check, ChevronRight, ChevronDown, RefreshCw, Grip, CreditCard, Users, Bot, MessageCircle, AppWindow, LayoutGrid, Sparkles, UserRound, Settings2, LogOut, ChevronsUpDown, Plus, Search, Trash2, Cpu, Globe, Server, Info, CircleX, CircleCheck, X } from '@hanzogui/lucide-icons-2';
13
- export { Boxes as CustomModelMark } from '@hanzogui/lucide-icons-2';
14
- import { surfaceById } from '@hanzo/products';
15
- import { HanzoLogo } from '@hanzo/logo/react';
16
- import { createPortal } from 'react-dom';
17
-
18
- var CHART_PALETTE = [
19
- "#7c5cff",
20
- "#23c562",
21
- "#ff9f45",
22
- "#3aa0ff",
23
- "#ff5d8f",
24
- "#16c0c8",
25
- "#c084fc",
26
- "#f4c245"
27
- ];
28
- var CHART_OTHER = "#64748b";
29
- var ACCENT = CHART_PALETTE[0];
30
- var GRID = "rgba(148,163,184,0.16)";
31
- var AXIS = "rgba(148,163,184,0.85)";
32
- var tone = (theme, key, fallback) => {
33
- const v = theme[key];
34
- const got = v?.get?.();
35
- return typeof got === "string" ? got : fallback;
36
- };
37
- var rampOpacity = (i, n) => n <= 1 ? 0.9 : 0.95 - i / (n - 1) * 0.62;
38
- function useContainerWidth() {
39
- const ref = useRef(null);
40
- const [w, setW] = useState(0);
41
- useEffect(() => {
42
- const el = ref.current;
43
- if (!el) return;
44
- const measure = () => setW(el.clientWidth);
45
- measure();
46
- const ro = new ResizeObserver(measure);
47
- ro.observe(el);
48
- return () => ro.disconnect();
49
- }, []);
50
- return { ref, w };
51
- }
52
- function Sparkline({
53
- values,
54
- width = 120,
55
- height = 36,
56
- color
57
- }) {
58
- const theme = useTheme();
59
- const clean = (values ?? []).filter((v) => Number.isFinite(v));
60
- if (clean.length < 2) return null;
61
- const stroke = color ?? tone(theme, "color11", "currentColor");
62
- const max = Math.max(...clean);
63
- const min = Math.min(...clean);
64
- const span = max - min || 1;
65
- const n = clean.length;
66
- const px = (i) => i / (n - 1) * (width - 2) + 1;
67
- const py = (v) => height - 2 - (v - min) / span * (height - 4);
68
- const line = clean.map((v, i) => `${i === 0 ? "M" : "L"}${px(i).toFixed(1)},${py(v).toFixed(1)}`).join(" ");
69
- const area = `${line} L${(width - 1).toFixed(1)},${height} L1,${height} Z`;
70
- return /* @__PURE__ */ jsxs("svg", { width, height, "aria-hidden": true, style: { display: "block" }, children: [
71
- /* @__PURE__ */ jsx("path", { d: area, fill: stroke, fillOpacity: 0.12 }),
72
- /* @__PURE__ */ jsx("path", { d: line, fill: "none", stroke, strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" })
73
- ] });
74
- }
75
- function Tooltip({ x, height, label, value }) {
76
- const left = Math.max(0, x - 60);
77
- return /* @__PURE__ */ jsx(
78
- "div",
79
- {
80
- style: {
81
- position: "absolute",
82
- left,
83
- top: 0,
84
- height,
85
- pointerEvents: "none",
86
- display: "flex",
87
- alignItems: "flex-start"
88
- },
89
- children: /* @__PURE__ */ jsxs(
90
- "div",
91
- {
92
- style: {
93
- background: "rgba(15,17,21,0.94)",
94
- border: "1px solid rgba(148,163,184,0.25)",
95
- borderRadius: 8,
96
- padding: "6px 9px",
97
- fontSize: 11,
98
- lineHeight: 1.35,
99
- color: "#e2e8f0",
100
- whiteSpace: "nowrap",
101
- boxShadow: "0 4px 16px rgba(0,0,0,0.4)"
102
- },
103
- children: [
104
- /* @__PURE__ */ jsx("div", { style: { color: AXIS }, children: label }),
105
- /* @__PURE__ */ jsx("div", { style: { fontWeight: 700 }, children: value })
106
- ]
107
- }
108
- )
109
- }
110
- );
111
- }
112
- function nearestIndex(clientX, rect, padL, innerW, n) {
113
- if (n <= 1) return 0;
114
- const mx = clientX - rect.left - padL;
115
- const i = Math.round(mx / (innerW || 1) * (n - 1));
116
- return Math.max(0, Math.min(n - 1, i));
117
- }
118
- function axisTicks(data) {
119
- const n = data.length;
120
- if (n === 0) return [];
121
- if (n === 1) return [{ i: 0, label: data[0].label, anchor: "middle" }];
122
- const mid = Math.floor((n - 1) / 2);
123
- const out = [
124
- { i: 0, label: data[0].label, anchor: "start" },
125
- { i: n - 1, label: data[n - 1].label, anchor: "end" }
126
- ];
127
- if (n >= 5) out.splice(1, 0, { i: mid, label: data[mid].label, anchor: "middle" });
128
- return out;
129
- }
130
- function LineChart({
131
- data,
132
- height = 210,
133
- color = ACCENT,
134
- formatValue = (v) => String(v)
135
- }) {
136
- const { ref, w } = useContainerWidth();
137
- const [hover, setHover] = useState(null);
138
- const padL = 10;
139
- const padR = 10;
140
- const padT = 12;
141
- const padB = 24;
142
- const n = data.length;
143
- const innerW = Math.max(1, w - padL - padR);
144
- const innerH = Math.max(1, height - padT - padB);
145
- const max = Math.max(...data.map((d) => d.value), 1);
146
- const x = (i) => padL + (n <= 1 ? innerW / 2 : i / (n - 1) * innerW);
147
- const y = (v) => padT + innerH - v / max * innerH;
148
- const line = data.map((d, i) => `${i === 0 ? "M" : "L"}${x(i).toFixed(1)},${y(d.value).toFixed(1)}`).join(" ");
149
- const area = n >= 2 ? `${line} L${x(n - 1).toFixed(1)},${(padT + innerH).toFixed(1)} L${x(0).toFixed(1)},${(padT + innerH).toFixed(1)} Z` : "";
150
- const ticks = axisTicks(data);
151
- return /* @__PURE__ */ jsxs("div", { ref, style: { position: "relative", width: "100%" }, children: [
152
- w > 0 ? /* @__PURE__ */ jsxs(
153
- "svg",
154
- {
155
- width: w,
156
- height,
157
- style: { display: "block" },
158
- onMouseMove: (e) => setHover(nearestIndex(e.clientX, e.currentTarget.getBoundingClientRect(), padL, innerW, n)),
159
- onMouseLeave: () => setHover(null),
160
- children: [
161
- [0, 0.5, 1].map((g) => /* @__PURE__ */ jsx("line", { x1: padL, x2: w - padR, y1: padT + innerH * g, y2: padT + innerH * g, stroke: GRID, strokeWidth: 1 }, g)),
162
- area ? /* @__PURE__ */ jsx("path", { d: area, fill: color, fillOpacity: 0.1 }) : null,
163
- n >= 2 ? /* @__PURE__ */ jsx("path", { d: line, fill: "none", stroke: color, strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round" }) : null,
164
- hover != null && data[hover] ? /* @__PURE__ */ jsxs(Fragment, { children: [
165
- /* @__PURE__ */ jsx("line", { x1: x(hover), x2: x(hover), y1: padT, y2: padT + innerH, stroke: AXIS, strokeWidth: 1, strokeDasharray: "3 3" }),
166
- /* @__PURE__ */ jsx("circle", { cx: x(hover), cy: y(data[hover].value), r: 4, fill: color, stroke: "#0f1115", strokeWidth: 2 })
167
- ] }) : null,
168
- ticks.map((t) => /* @__PURE__ */ jsx("text", { x: x(t.i), y: height - 7, fontSize: 10, fill: AXIS, textAnchor: t.anchor, children: t.label }, t.i))
169
- ]
170
- }
171
- ) : null,
172
- hover != null && data[hover] ? /* @__PURE__ */ jsx(Tooltip, { x: x(hover), height, label: data[hover].label, value: formatValue(data[hover].value) }) : null
173
- ] });
174
- }
175
- function BarChart({
176
- data,
177
- height = 210,
178
- color = ACCENT,
179
- formatValue = (v) => String(v)
180
- }) {
181
- const { ref, w } = useContainerWidth();
182
- const [hover, setHover] = useState(null);
183
- const padL = 10;
184
- const padR = 10;
185
- const padT = 12;
186
- const padB = 24;
187
- const n = data.length;
188
- const innerW = Math.max(1, w - padL - padR);
189
- const innerH = Math.max(1, height - padT - padB);
190
- const max = Math.max(...data.map((d) => d.value), 1);
191
- const slot = innerW / Math.max(1, n);
192
- const barW = Math.max(1, Math.min(slot * 0.62, 36));
193
- const cx = (i) => padL + slot * i + slot / 2;
194
- const ticks = axisTicks(data);
195
- return /* @__PURE__ */ jsxs("div", { ref, style: { position: "relative", width: "100%" }, children: [
196
- w > 0 ? /* @__PURE__ */ jsxs(
197
- "svg",
198
- {
199
- width: w,
200
- height,
201
- style: { display: "block" },
202
- onMouseMove: (e) => {
203
- const rect = e.currentTarget.getBoundingClientRect();
204
- const i = Math.floor((e.clientX - rect.left - padL) / (slot || 1));
205
- setHover(Math.max(0, Math.min(n - 1, i)));
206
- },
207
- onMouseLeave: () => setHover(null),
208
- children: [
209
- [0, 0.5, 1].map((g) => /* @__PURE__ */ jsx("line", { x1: padL, x2: w - padR, y1: padT + innerH * g, y2: padT + innerH * g, stroke: GRID, strokeWidth: 1 }, g)),
210
- data.map((d, i) => {
211
- const h = d.value / max * innerH;
212
- return /* @__PURE__ */ jsx(
213
- "rect",
214
- {
215
- x: cx(i) - barW / 2,
216
- y: padT + innerH - h,
217
- width: barW,
218
- height: Math.max(0, h),
219
- rx: Math.min(3, barW / 2),
220
- fill: color,
221
- fillOpacity: hover === i ? 1 : 0.78
222
- },
223
- i
224
- );
225
- }),
226
- ticks.map((t) => /* @__PURE__ */ jsx("text", { x: cx(t.i), y: height - 7, fontSize: 10, fill: AXIS, textAnchor: "middle", children: t.label }, t.i))
227
- ]
228
- }
229
- ) : null,
230
- hover != null && data[hover] ? /* @__PURE__ */ jsx(Tooltip, { x: cx(hover), height, label: data[hover].label, value: formatValue(data[hover].value) }) : null
231
- ] });
232
- }
233
- function Donut({
234
- slices,
235
- size = 160,
236
- thickness = 22,
237
- center,
238
- legend = false
239
- }) {
240
- const theme = useTheme();
241
- const fg = tone(theme, "color12", "currentColor");
242
- const positive = slices.filter((s) => s.value > 0);
243
- const total = positive.reduce((sum, s) => sum + s.value, 0);
244
- const r = size / 2;
245
- const rInner = r - thickness;
246
- const mid = (r + rInner) / 2;
247
- if (total <= 0) {
248
- return /* @__PURE__ */ jsx(XStack, { items: "center", justify: "center", height: size, children: /* @__PURE__ */ jsx(Text, { fontSize: "$6", color: "$color10", children: "\u2014" }) });
249
- }
250
- const ring = /* @__PURE__ */ jsxs("div", { style: { position: "relative", width: size, height: size }, children: [
251
- /* @__PURE__ */ jsx("svg", { width: size, height: size, style: { display: "block" }, children: positive.length === 1 ? /* @__PURE__ */ jsx(
252
- "circle",
253
- {
254
- cx: r,
255
- cy: r,
256
- r: mid,
257
- fill: "none",
258
- stroke: positive[0].color ?? fg,
259
- strokeOpacity: positive[0].color ? 1 : 0.9,
260
- strokeWidth: thickness
261
- }
262
- ) : renderArcs(positive, total, r, rInner, fg) }),
263
- center ? /* @__PURE__ */ jsx(
264
- "div",
265
- {
266
- style: {
267
- position: "absolute",
268
- inset: 0,
269
- display: "flex",
270
- flexDirection: "column",
271
- alignItems: "center",
272
- justifyContent: "center",
273
- textAlign: "center",
274
- pointerEvents: "none"
275
- },
276
- children: center
277
- }
278
- ) : null
279
- ] });
280
- if (!legend) return ring;
281
- return /* @__PURE__ */ jsxs(XStack, { gap: "$4", items: "center", flexWrap: "wrap", children: [
282
- ring,
283
- /* @__PURE__ */ jsx(YStack, { gap: "$1.5", flex: 1, minW: 150, children: positive.map((s, i) => /* @__PURE__ */ jsxs(XStack, { gap: "$2", items: "center", children: [
284
- /* @__PURE__ */ jsx(
285
- "div",
286
- {
287
- style: {
288
- width: 10,
289
- height: 10,
290
- borderRadius: 2,
291
- backgroundColor: s.color ?? AXIS,
292
- opacity: s.color ? 1 : rampOpacity(i, positive.length)
293
- }
294
- }
295
- ),
296
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", flex: 1, numberOfLines: 1, children: s.label }),
297
- /* @__PURE__ */ jsxs(Text, { fontSize: "$2", color: "$color12", fontWeight: "600", children: [
298
- Math.round(s.value / total * 100),
299
- "%"
300
- ] })
301
- ] }, s.label)) })
302
- ] });
303
- }
304
- function renderArcs(slices, total, rOuter, rInner, fg) {
305
- let a0 = -Math.PI / 2;
306
- const paths = [];
307
- slices.forEach((s, idx) => {
308
- const frac = Math.max(0, s.value) / total;
309
- if (frac <= 0) return;
310
- const a1 = a0 + frac * Math.PI * 2;
311
- paths.push(
312
- /* @__PURE__ */ jsx(
313
- "path",
314
- {
315
- d: annularArc(rOuter, rOuter, rOuter, rInner, a0, Math.min(a1, a0 + Math.PI * 1.9999)),
316
- fill: s.color ?? fg,
317
- fillOpacity: s.color ? 1 : rampOpacity(idx, slices.length)
318
- },
319
- s.label || idx
320
- )
321
- );
322
- a0 = a1;
323
- });
324
- return /* @__PURE__ */ jsx(Fragment, { children: paths });
325
- }
326
- function polar(cx, cy, rad, a) {
327
- return [cx + rad * Math.cos(a), cy + rad * Math.sin(a)];
328
- }
329
- function annularArc(cx, cy, rOuter, rInner, a0, a1) {
330
- const large = a1 - a0 > Math.PI ? 1 : 0;
331
- const [x0, y0] = polar(cx, cy, rOuter, a0);
332
- const [x1, y1] = polar(cx, cy, rOuter, a1);
333
- const [x2, y2] = polar(cx, cy, rInner, a1);
334
- const [x3, y3] = polar(cx, cy, rInner, a0);
335
- return `M${x0},${y0} A${rOuter},${rOuter} 0 ${large} 1 ${x1},${y1} L${x2},${y2} A${rInner},${rInner} 0 ${large} 0 ${x3},${y3} Z`;
336
- }
337
- function BarRows({ bars }) {
338
- const max = Math.max(0, ...bars.map((b) => b.value));
339
- if (max <= 0) {
340
- return /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color10", children: "\u2014" });
341
- }
342
- return /* @__PURE__ */ jsx(YStack, { gap: "$2.5", children: bars.map((b) => /* @__PURE__ */ jsxs(XStack, { gap: "$3", items: "center", children: [
343
- /* @__PURE__ */ jsx(Text, { width: 64, fontSize: "$2", color: "$color11", text: "right", children: b.label }),
344
- /* @__PURE__ */ jsx(YStack, { flex: 1, height: 10, bg: "$color3", rounded: "$2", overflow: "hidden", children: /* @__PURE__ */ jsx(YStack, { height: 10, width: `${Math.max(2, b.value / max * 100)}%`, bg: "$color9", rounded: "$2" }) }),
345
- /* @__PURE__ */ jsx(Text, { width: 56, fontSize: "$2", color: "$color12", fontWeight: "600", children: b.value.toLocaleString() })
346
- ] }, b.label)) });
347
- }
348
- var SERIES = ["#6ea8fe", "#7ee787", "#f0a868", "#c792ea", "#56d4c4", "#e879a6", "#d6c15a", "#8b9bb4"];
349
- var colorForIndex = (i) => SERIES[i % SERIES.length];
350
- var TRACK = "rgba(128,128,128,0.18)";
351
- function utilColor(pct) {
352
- if (pct >= 90) return "#e5534b";
353
- if (pct >= 70) return "#f0a868";
354
- return "#7ee787";
355
- }
356
- function Sparkline2({
357
- points,
358
- width = 104,
359
- height = 30,
360
- color = SERIES[0]
361
- }) {
362
- if (!points || points.length < 2) return null;
363
- const min = Math.min(...points);
364
- const max = Math.max(...points);
365
- const span = max - min || 1;
366
- const stepX = width / (points.length - 1);
367
- const y = (v) => height - 2 - (v - min) / span * (height - 4);
368
- const d = points.map((p, i) => `${i === 0 ? "M" : "L"}${(i * stepX).toFixed(1)},${y(p).toFixed(1)}`).join(" ");
369
- return /* @__PURE__ */ jsx("svg", { width, height, viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": "trend", children: /* @__PURE__ */ jsx("path", { d, fill: "none", stroke: color, strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" }) });
370
- }
371
- function MiniBars({
372
- bars,
373
- width = 320,
374
- height = 96,
375
- color = SERIES[0]
376
- }) {
377
- if (!bars.length) return null;
378
- const max = Math.max(...bars.map((b) => b.value), 1);
379
- const gap = 4;
380
- const bw = (width - gap * (bars.length - 1)) / bars.length;
381
- return /* @__PURE__ */ jsx("svg", { width: "100%", height, viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", role: "img", "aria-label": "bars", children: bars.map((b, i) => {
382
- const h = Math.max(1, b.value / max * (height - 2));
383
- return /* @__PURE__ */ jsx("rect", { x: i * (bw + gap), y: height - h, width: bw, height: h, rx: 2, fill: color, opacity: 0.85, children: /* @__PURE__ */ jsx("title", { children: `${b.label}: ${b.value}` }) }, b.label + i);
384
- }) });
385
- }
386
- function UtilBar({ value, width = 120, color }) {
387
- const v = Math.max(0, Math.min(100, value));
388
- return /* @__PURE__ */ jsxs("svg", { width, height: 8, viewBox: `0 0 ${width} 8`, role: "img", "aria-label": `${Math.round(v)}%`, children: [
389
- /* @__PURE__ */ jsx("rect", { x: 0, y: 1, width, height: 6, rx: 3, fill: TRACK }),
390
- /* @__PURE__ */ jsx("rect", { x: 0, y: 1, width: v / 100 * width, height: 6, rx: 3, fill: color ?? utilColor(v) })
391
- ] });
392
- }
393
- function LegendDot({ color, label, value }) {
394
- return /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", justify: "space-between", children: [
395
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
396
- /* @__PURE__ */ jsx(YStack, { width: 10, height: 10, rounded: "$1", bg: color }),
397
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: label })
398
- ] }),
399
- value != null ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", fontWeight: "500", className: "hz-mono", children: value }) : null
400
- ] });
401
- }
402
- function MetricCard({
403
- icon,
404
- label,
405
- value,
406
- caption,
407
- spark,
408
- sparkColor,
409
- delta
410
- }) {
411
- const up = delta ? delta.pct >= 0 : false;
412
- return /* @__PURE__ */ jsxs(Card, { p: "$3.5", gap: "$2", borderWidth: 1, borderColor: "$borderColor", flex: 1, minW: 172, children: [
413
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", justify: "space-between", children: [
414
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", children: [
415
- icon,
416
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", fontWeight: "500", children: label })
417
- ] }),
418
- delta ? /* @__PURE__ */ jsxs(Text, { fontSize: "$1", color: up ? "#7ee787" : "#e5534b", children: [
419
- up ? "\u25B2" : "\u25BC",
420
- " ",
421
- Math.abs(delta.pct),
422
- "%"
423
- ] }) : null
424
- ] }),
425
- /* @__PURE__ */ jsxs(XStack, { items: "flex-end", justify: "space-between", gap: "$2", children: [
426
- /* @__PURE__ */ jsx(Text, { fontSize: "$8", fontWeight: "500", color: "$color12", numberOfLines: 1, className: "hz-mono", children: value }),
427
- spark && spark.length >= 2 ? /* @__PURE__ */ jsx(Sparkline2, { points: spark, color: sparkColor ?? SERIES[0] }) : null
428
- ] }),
429
- caption ? /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", numberOfLines: 1, children: caption }) : null
430
- ] });
431
- }
432
- function HintButton({
433
- icon,
434
- iconAfter,
435
- children,
436
- onPress,
437
- disabled,
438
- hint,
439
- theme
440
- }) {
441
- const btn = /* @__PURE__ */ jsx(
442
- Button,
443
- {
444
- size: "$2",
445
- theme,
446
- icon,
447
- iconAfter,
448
- disabled,
449
- onPress: disabled ? void 0 : onPress,
450
- children
451
- }
452
- );
453
- if (!hint) return btn;
454
- return /* @__PURE__ */ jsx("span", { title: hint, style: { display: "inline-flex" }, children: btn });
455
- }
456
- function Panel({
457
- title,
458
- right,
459
- children,
460
- minW = 280,
461
- grow = true
462
- }) {
463
- return /* @__PURE__ */ jsxs(Card, { p: "$4", gap: "$3", borderWidth: 1, borderColor: "$borderColor", flex: grow ? 1 : void 0, minW, width: grow ? void 0 : "100%", children: [
464
- /* @__PURE__ */ jsxs(XStack, { items: "center", justify: "space-between", gap: "$2", children: [
465
- /* @__PURE__ */ jsx(Text, { fontSize: "$4", fontWeight: "500", color: "$color12", children: title }),
466
- right
467
- ] }),
468
- children
469
- ] });
470
- }
471
- function Donut2({
472
- segments,
473
- size = 160,
474
- thickness = 18,
475
- centerValue,
476
- centerLabel,
477
- trackColor = "#2a2d2e",
478
- valueColor = "#ecedee",
479
- labelColor = "#9ba1a6"
480
- }) {
481
- const total = segments.reduce((n, s) => n + Math.max(0, s.value), 0);
482
- if (total <= 0) return null;
483
- const r = (size - thickness) / 2;
484
- const cx = size / 2;
485
- const cy = size / 2;
486
- const circ = 2 * Math.PI * r;
487
- let offset = 0;
488
- const arcs = segments.filter((s) => s.value > 0).map((s) => {
489
- const frac = s.value / total;
490
- const dash = frac * circ;
491
- const node = /* @__PURE__ */ jsx(
492
- "circle",
493
- {
494
- cx,
495
- cy,
496
- r,
497
- fill: "none",
498
- stroke: s.color,
499
- strokeWidth: thickness,
500
- strokeDasharray: `${dash} ${circ - dash}`,
501
- strokeDashoffset: -offset
502
- },
503
- s.label
504
- );
505
- offset += dash;
506
- return node;
507
- });
508
- return /* @__PURE__ */ jsxs("svg", { width: size, height: size, viewBox: `0 0 ${size} ${size}`, role: "img", "aria-label": "Donut chart", children: [
509
- /* @__PURE__ */ jsx("circle", { cx, cy, r, fill: "none", stroke: trackColor, strokeWidth: thickness }),
510
- /* @__PURE__ */ jsx("g", { transform: `rotate(-90 ${cx} ${cy})`, children: arcs }),
511
- centerValue ? /* @__PURE__ */ jsx("text", { x: cx, y: cy - 2, textAnchor: "middle", fontSize: size * 0.2, fontWeight: "800", fill: valueColor, children: centerValue }) : null,
512
- centerLabel ? /* @__PURE__ */ jsx("text", { x: cx, y: cy + size * 0.13, textAnchor: "middle", fontSize: size * 0.08, fill: labelColor, children: centerLabel }) : null
513
- ] });
514
- }
515
-
516
- // src/product/combobox/filter.ts
517
- var hay = (o) => `${o.value} ${o.label ?? ""} ${o.hint ?? ""}`.toLowerCase();
518
- function filterOptions(options, query) {
519
- const q = query.trim().toLowerCase();
520
- if (!q) return options;
521
- return options.filter((o) => hay(o).includes(q));
522
- }
523
- function isKnownOption(options, value) {
524
- return options.some((o) => o.value === value);
525
- }
526
- var ITEM_MIN_HEIGHT = 30;
527
- var ITEM_RADIUS = 7;
528
- var ITEM_PX = 8;
529
- var ITEM_GAP = 8;
530
- var ICON_SLOT = 16;
531
- var PANEL_RADIUS = 12;
532
- var PANEL_PAD = 4;
533
- var PANEL_GAP = 2;
534
- var SEP_MARGIN = 4;
535
- var FONT_LABEL = 13;
536
- var FONT_MUTED = 11;
537
- var FONT_SHORTCUT = 12;
538
- var ACCENT2 = "var(--hanzo-accent, #8b5cf6)";
539
- var ACCENT_SOFT = "var(--hanzo-accent-soft, rgba(139,92,246,0.16))";
540
- var DANGER = "var(--hanzo-danger, #ef4444)";
541
- function MenuPanel({
542
- children,
543
- minWidth = 200,
544
- maxHeight = 360,
545
- onKeyDown,
546
- panelRef,
547
- ...rest
548
- }) {
549
- return /* @__PURE__ */ jsx(
550
- YStack,
551
- {
552
- ref: panelRef,
553
- role: "menu",
554
- bg: "$color2",
555
- borderColor: "$borderColor",
556
- borderWidth: 1,
557
- rounded: PANEL_RADIUS,
558
- p: PANEL_PAD,
559
- gap: PANEL_GAP,
560
- minW: minWidth,
561
- maxH: maxHeight,
562
- overflow: "scroll",
563
- shadowColor: "rgba(0,0,0,0.45)",
564
- shadowRadius: 20,
565
- shadowOffset: { width: 0, height: 10 },
566
- onKeyDown,
567
- ...rest,
568
- children
569
- }
570
- );
571
- }
572
- function MenuItemView({
573
- icon,
574
- label,
575
- description,
576
- shortcut,
577
- selected = false,
578
- disabled = false,
579
- destructive = false,
580
- hasSubmenu = false,
581
- onSelect
582
- }) {
583
- const track = useEmit();
584
- const choose = () => {
585
- track({ component: "MenuItem", action: "select", id: labelOf(label), value: selected });
586
- onSelect();
587
- };
588
- const press = () => {
589
- if (!disabled) choose();
590
- };
591
- const onKeyDown = (e) => {
592
- if (disabled) return;
593
- if (e.key === "Enter" || e.key === " ") {
594
- e.preventDefault();
595
- choose();
596
- }
597
- };
598
- const labelColor = destructive ? DANGER : "$color12";
599
- return /* @__PURE__ */ jsxs(
600
- XStack,
601
- {
602
- role: "menuitem",
603
- tabIndex: disabled ? -1 : 0,
604
- "aria-disabled": disabled || void 0,
605
- items: "center",
606
- gap: ITEM_GAP,
607
- px: ITEM_PX,
608
- minH: ITEM_MIN_HEIGHT,
609
- rounded: ITEM_RADIUS,
610
- cursor: disabled ? "default" : "pointer",
611
- opacity: disabled ? 0.4 : 1,
612
- select: "none",
613
- style: { outline: "none" },
614
- hoverStyle: disabled ? {} : { bg: ACCENT_SOFT },
615
- pressStyle: disabled ? {} : { bg: ACCENT_SOFT },
616
- focusStyle: disabled ? {} : { bg: ACCENT_SOFT },
617
- onPress: press,
618
- onKeyDown,
619
- children: [
620
- /* @__PURE__ */ jsx(XStack, { width: ICON_SLOT, height: ICON_SLOT, items: "center", justify: "center", shrink: 0, children: icon ? /* @__PURE__ */ jsx(XStack, { items: "center", justify: "center", opacity: destructive ? 1 : 0.9, style: destructive ? { color: DANGER } : void 0, children: icon }) : null }),
621
- /* @__PURE__ */ jsxs(YStack, { flex: 1, minW: 0, children: [
622
- /* @__PURE__ */ jsx(Text, { fontSize: FONT_LABEL, lineHeight: 18, color: labelColor, numberOfLines: 1, children: label }),
623
- description ? /* @__PURE__ */ jsx(Text, { fontSize: FONT_MUTED, lineHeight: 14, color: "$color11", numberOfLines: 1, children: description }) : null
624
- ] }),
625
- shortcut ? /* @__PURE__ */ jsx(Text, { fontSize: FONT_SHORTCUT, color: "$color11", shrink: 0, children: shortcut }) : null,
626
- selected ? /* @__PURE__ */ jsx(Check, { size: 14, color: ACCENT2 }) : null,
627
- hasSubmenu ? /* @__PURE__ */ jsx(ChevronRight, { size: 14, color: "var(--hanzo-muted, currentColor)", opacity: 0.6 }) : null
628
- ]
629
- }
630
- );
631
- }
632
- function MenuSeparatorView() {
633
- return /* @__PURE__ */ jsx(YStack, { height: 1, bg: "$borderColor", my: SEP_MARGIN, mx: SEP_MARGIN, role: "separator" });
634
- }
635
- function MenuLabelView({ children }) {
636
- return /* @__PURE__ */ jsx(
637
- Text,
638
- {
639
- fontSize: FONT_MUTED,
640
- color: "$color11",
641
- px: ITEM_PX,
642
- py: SEP_MARGIN,
643
- textTransform: "uppercase",
644
- letterSpacing: 0.4,
645
- select: "none",
646
- children
647
- }
648
- );
649
- }
650
- function renderMenuItems(items, close) {
651
- return items.map((it, i) => {
652
- if (it.type === "separator") return /* @__PURE__ */ jsx(MenuSeparatorView, {}, it.key ?? `sep-${i}`);
653
- if (it.type === "label") return /* @__PURE__ */ jsx(MenuLabelView, { children: it.label }, it.key ?? `lbl-${i}`);
654
- const { key, onSelect, closeOnSelect = true, ...rest } = it;
655
- return /* @__PURE__ */ jsx(
656
- MenuItemView,
657
- {
658
- ...rest,
659
- onSelect: () => {
660
- onSelect();
661
- if (closeOnSelect) close?.();
662
- }
663
- },
664
- key
665
- );
666
- });
667
- }
668
- function PortalTheme({ name, children }) {
669
- return /* @__PURE__ */ jsx(Theme, { name, children });
670
- }
671
-
672
- // src/product/menu/roving.ts
673
- function menuKeyDown(e, onClose) {
674
- if (e.key === "Escape") {
675
- onClose?.();
676
- return;
677
- }
678
- if (e.key !== "ArrowDown" && e.key !== "ArrowUp" && e.key !== "Home" && e.key !== "End") return;
679
- if (typeof document === "undefined") return;
680
- const panel = e.currentTarget;
681
- const items = Array.from(
682
- panel.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])')
683
- );
684
- if (items.length === 0) return;
685
- e.preventDefault();
686
- const active = document.activeElement;
687
- const current = active ? items.indexOf(active) : -1;
688
- let next;
689
- if (e.key === "Home") next = 0;
690
- else if (e.key === "End") next = items.length - 1;
691
- else if (e.key === "ArrowDown") next = current < 0 ? 0 : (current + 1) % items.length;
692
- else next = current <= 0 ? items.length - 1 : current - 1;
693
- items[next]?.focus();
694
- }
695
- var EDGE = 8;
696
- function FloatingMenu({
697
- open,
698
- onClose,
699
- anchorRect,
700
- anchorEl,
701
- gap = 4,
702
- minWidth = 200,
703
- maxHeight,
704
- autoFocus = true,
705
- children
706
- }) {
707
- const themeName = useThemeName();
708
- const panelRef = useRef(null);
709
- const [pos, setPos] = useState(null);
710
- const setPanel = useCallback((n) => {
711
- panelRef.current = n;
712
- }, []);
713
- const place = useCallback(() => {
714
- if (typeof window === "undefined") return;
715
- const a = anchorRect();
716
- if (!a) return;
717
- const node = panelRef.current;
718
- const w = node?.offsetWidth || minWidth;
719
- const h = node?.offsetHeight || 0;
720
- let left = a.left;
721
- let top = a.bottom + gap;
722
- if (left + w > window.innerWidth - EDGE) left = Math.max(EDGE, window.innerWidth - w - EDGE);
723
- if (h && top + h > window.innerHeight - EDGE) {
724
- const above = a.top - gap - h;
725
- top = above >= EDGE ? above : Math.max(EDGE, window.innerHeight - h - EDGE);
726
- }
727
- setPos({ left, top });
728
- }, [anchorRect, gap, minWidth]);
729
- useLayoutEffect(() => {
730
- if (!open) {
731
- setPos(null);
732
- return;
733
- }
734
- place();
735
- if (autoFocus) panelRef.current?.focus?.();
736
- }, [open, place, autoFocus]);
737
- useEffect(() => {
738
- if (!open || typeof document === "undefined") return;
739
- const onPointerDown = (e) => {
740
- const t = e.target;
741
- if (panelRef.current?.contains(t)) return;
742
- const anchor = anchorEl?.();
743
- if (anchor && anchor.contains(t)) return;
744
- onClose();
745
- };
746
- const onKey = (e) => {
747
- if (e.key === "Escape") onClose();
748
- };
749
- document.addEventListener("pointerdown", onPointerDown, true);
750
- document.addEventListener("keydown", onKey, true);
751
- window.addEventListener("scroll", onClose, true);
752
- window.addEventListener("resize", onClose);
753
- window.addEventListener("blur", onClose);
754
- return () => {
755
- document.removeEventListener("pointerdown", onPointerDown, true);
756
- document.removeEventListener("keydown", onKey, true);
757
- window.removeEventListener("scroll", onClose, true);
758
- window.removeEventListener("resize", onClose);
759
- window.removeEventListener("blur", onClose);
760
- };
761
- }, [open, onClose, anchorEl]);
762
- if (!open) return null;
763
- return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(PortalTheme, { name: themeName, children: /* @__PURE__ */ jsx(
764
- MenuPanel,
765
- {
766
- panelRef: setPanel,
767
- minWidth,
768
- maxHeight,
769
- tabIndex: -1,
770
- onKeyDown: (e) => menuKeyDown(e, onClose),
771
- style: {
772
- position: "fixed",
773
- left: pos?.left ?? 0,
774
- top: pos?.top ?? 0,
775
- zIndex: 1e5,
776
- visibility: pos ? "visible" : "hidden"
777
- },
778
- children
779
- }
780
- ) }) });
781
- }
782
- function ComboBox({
783
- value,
784
- onChange,
785
- options,
786
- loading = false,
787
- error = null,
788
- onRetry,
789
- placeholder,
790
- disabled,
791
- emptyText = "No matches \u2014 press to use what you typed.",
792
- minWidth = 240
793
- }) {
794
- const [open, setOpen] = useState(false);
795
- const rowRef = useRef(null);
796
- const anchorRect = useCallback(() => rowRef.current?.getBoundingClientRect() ?? null, []);
797
- const anchorEl = useCallback(() => rowRef.current, []);
798
- const filtered = useMemo(() => filterOptions(options, value), [options, value]);
799
- const track = useEmit();
800
- const pick = (v) => {
801
- track({ component: "ComboBox", action: "select", id: v, value: filtered.length });
802
- onChange(v);
803
- setOpen(false);
804
- };
805
- return /* @__PURE__ */ jsxs(Fragment, { children: [
806
- /* @__PURE__ */ jsxs(XStack, { ref: rowRef, items: "center", gap: "$2", minW: minWidth, children: [
807
- /* @__PURE__ */ jsx(
808
- Input,
809
- {
810
- flex: 1,
811
- value,
812
- onChangeText: (v) => {
813
- onChange(v);
814
- if (!open) setOpen(true);
815
- },
816
- onFocus: () => setOpen(true),
817
- disabled,
818
- placeholder,
819
- autoCapitalize: "none"
820
- }
821
- ),
822
- /* @__PURE__ */ jsx(
823
- Button,
824
- {
825
- size: "$2",
826
- chromeless: true,
827
- disabled,
828
- icon: /* @__PURE__ */ jsx(ChevronDown, { size: 16, opacity: 0.7 }),
829
- onPress: () => {
830
- track({ component: "ComboBox", action: open ? "close" : "open" });
831
- setOpen((o) => !o);
832
- },
833
- "aria-label": "Show options"
834
- }
835
- )
836
- ] }),
837
- /* @__PURE__ */ jsx(
838
- FloatingMenu,
839
- {
840
- open,
841
- onClose: () => setOpen(false),
842
- anchorRect,
843
- anchorEl,
844
- autoFocus: false,
845
- minWidth,
846
- maxHeight: 300,
847
- children: loading ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$2", py: "$2", children: [
848
- /* @__PURE__ */ jsx(Spinner, { size: "small", color: "$color11" }),
849
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", children: "Loading options\u2026" })
850
- ] }) : error ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$2", py: "$2", children: [
851
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", flex: 1, numberOfLines: 2, children: error }),
852
- onRetry ? /* @__PURE__ */ jsx(Button, { size: "$1", chromeless: true, icon: /* @__PURE__ */ jsx(RefreshCw, { size: 12 }), onPress: onRetry, "aria-label": "Retry" }) : null
853
- ] }) : filtered.length === 0 ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", px: "$2", py: "$2", children: emptyText }) : filtered.map((o) => /* @__PURE__ */ jsx(
854
- MenuItemView,
855
- {
856
- label: o.label ?? o.value,
857
- description: o.hint,
858
- selected: o.value === value,
859
- onSelect: () => pick(o.value)
860
- },
861
- o.value
862
- ))
863
- }
864
- )
865
- ] });
866
- }
867
- var ORDER = ["ai", "console", "app", "chat", "bot", "team", "billing"];
868
- var SURFACES = ORDER.map((id) => {
869
- const s = surfaceById(id);
870
- return { id, label: s.label, href: s.href, hint: s.domain };
871
- });
872
- function otherSurfaces(current) {
873
- return current ? SURFACES.filter((s) => s.id !== current) : SURFACES;
874
- }
875
- function HanzoMark({ size = 22, color = "currentColor" }) {
876
- return /* @__PURE__ */ jsxs(
877
- "svg",
878
- {
879
- width: size,
880
- height: size,
881
- viewBox: "0 0 67 67",
882
- role: "img",
883
- "aria-label": "Hanzo",
884
- fill: color,
885
- style: { display: "block", flexShrink: 0 },
886
- children: [
887
- /* @__PURE__ */ jsx("path", { d: "M22.21 67V44.6369H0V67H22.21Z" }),
888
- /* @__PURE__ */ jsx("path", { opacity: 0.55, d: "M0 44.6369L22.21 46.8285V44.6369H0Z" }),
889
- /* @__PURE__ */ jsx("path", { d: "M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z" }),
890
- /* @__PURE__ */ jsx("path", { d: "M22.21 0H0V22.3184H22.21V0Z" }),
891
- /* @__PURE__ */ jsx("path", { d: "M66.7198 0H44.5098V22.3184H66.7198V0Z" }),
892
- /* @__PURE__ */ jsx("path", { opacity: 0.55, d: "M66.6753 22.3185L44.5098 20.0822V22.3185H66.6753Z" }),
893
- /* @__PURE__ */ jsx("path", { d: "M66.7198 67V44.6369H44.5098V67H66.7198Z" })
894
- ]
895
- }
896
- );
897
- }
898
- function BrandMark({
899
- size = 20,
900
- wordmark = "Hanzo",
901
- animated = true
902
- }) {
903
- if (!animated) return /* @__PURE__ */ jsx(HanzoMark, { size });
904
- return /* @__PURE__ */ jsx(HanzoLogo, { animated: true, size, wordmark });
905
- }
906
- var SURFACE_ICON = {
907
- ai: Sparkles,
908
- console: LayoutGrid,
909
- app: AppWindow,
910
- chat: MessageCircle,
911
- bot: Bot,
912
- team: Users,
913
- billing: CreditCard
914
- };
915
- var openHref = (href) => {
916
- if (typeof window !== "undefined") window.open(href, "_blank", "noopener");
917
- };
918
- function MenuRow({ icon, label, onPress }) {
919
- return /* @__PURE__ */ jsxs(XStack, { onPress, cursor: "pointer", items: "center", gap: "$2.5", px: "$2", py: "$2", rounded: "$3", hoverStyle: { bg: "$color5" }, children: [
920
- icon,
921
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", children: label })
922
- ] });
923
- }
924
- function AppHeader({
925
- brand,
926
- wordmark = "Hanzo",
927
- onBrand,
928
- org,
929
- children,
930
- current,
931
- surfaces,
932
- open,
933
- user,
934
- menu,
935
- theme,
936
- onProfile,
937
- onTeam,
938
- onBilling,
939
- onSignOut
940
- }) {
941
- const [appsOpen, setAppsOpen] = useState(false);
942
- const [menuOpen, setMenuOpen] = useState(false);
943
- const items = surfaces ?? otherSurfaces(current);
944
- const launch = (s) => {
945
- setAppsOpen(false);
946
- if (open) open(s);
947
- else openHref(s.href);
948
- };
949
- return /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$3", height: 52, borderBottomWidth: 1, borderColor: "$borderColor", bg: "$background", children: [
950
- /* @__PURE__ */ jsx(XStack, { items: "center", cursor: onBrand ? "pointer" : void 0, onPress: onBrand, children: brand ?? /* @__PURE__ */ jsx(BrandMark, { wordmark }) }),
951
- org ? /* @__PURE__ */ jsx(XStack, { items: "center", minW: 0, children: org }) : null,
952
- /* @__PURE__ */ jsx(XStack, { flex: 1, items: "center", minW: 0, children }),
953
- items.length > 0 ? /* @__PURE__ */ jsxs(Popover, { open: appsOpen, onOpenChange: setAppsOpen, placement: "bottom-end", children: [
954
- /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "$2", chromeless: true, icon: /* @__PURE__ */ jsx(Grip, { size: 16 }), "aria-label": "Apps" }) }),
955
- /* @__PURE__ */ jsx(Popover.Content, { bordered: true, elevate: true, p: "$2", width: 230, bg: "$color2", borderColor: "$borderColor", children: /* @__PURE__ */ jsx(YStack, { gap: "$1", children: items.map((s) => {
956
- const Icon = SURFACE_ICON[s.id];
957
- return /* @__PURE__ */ jsxs(XStack, { onPress: () => launch(s), cursor: "pointer", items: "center", gap: "$2.5", px: "$2", py: "$2", rounded: "$3", hoverStyle: { bg: "$color5" }, children: [
958
- /* @__PURE__ */ jsx(Icon, { size: 16 }),
959
- /* @__PURE__ */ jsx(Text, { flex: 1, fontSize: "$2", fontWeight: "600", color: "$color12", children: s.label }),
960
- s.hint ? /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", children: s.hint }) : null
961
- ] }, s.id);
962
- }) }) })
963
- ] }) : null,
964
- /* @__PURE__ */ jsxs(Popover, { open: menuOpen, onOpenChange: setMenuOpen, placement: "bottom-end", children: [
965
- /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "$2", chromeless: true, icon: /* @__PURE__ */ jsx(UserRound, { size: 16 }), "aria-label": "Account", children: user ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", numberOfLines: 1, maxW: 140, children: user }) : null }) }),
966
- /* @__PURE__ */ jsx(Popover.Content, { bordered: true, elevate: true, p: "$2", width: 220, bg: "$color2", borderColor: "$borderColor", children: menu ?? /* @__PURE__ */ jsxs(YStack, { gap: "$1", children: [
967
- onProfile ? /* @__PURE__ */ jsx(MenuRow, { icon: /* @__PURE__ */ jsx(UserRound, { size: 15 }), label: "Profile", onPress: () => (setMenuOpen(false), onProfile()) }) : null,
968
- theme !== null ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2.5", px: "$2", py: "$1", rounded: "$3", children: [
969
- /* @__PURE__ */ jsx(Text, { flex: 1, fontSize: "$2", color: "$color12", children: "Theme" }),
970
- theme ?? /* @__PURE__ */ jsx(ThemeToggle, {})
971
- ] }) : null,
972
- onTeam ? /* @__PURE__ */ jsx(MenuRow, { icon: /* @__PURE__ */ jsx(Settings2, { size: 15 }), label: "Team settings", onPress: () => (setMenuOpen(false), onTeam()) }) : null,
973
- onBilling ? /* @__PURE__ */ jsx(MenuRow, { icon: /* @__PURE__ */ jsx(CreditCard, { size: 15 }), label: "Billing", onPress: () => (setMenuOpen(false), onBilling()) }) : null,
974
- onSignOut ? /* @__PURE__ */ jsxs(Fragment, { children: [
975
- /* @__PURE__ */ jsx(Separator, { borderColor: "$borderColor", my: "$1" }),
976
- /* @__PURE__ */ jsx(MenuRow, { icon: /* @__PURE__ */ jsx(LogOut, { size: 15 }), label: "Sign out", onPress: () => (setMenuOpen(false), onSignOut()) })
977
- ] }) : null
978
- ] }) })
979
- ] })
980
- ] });
981
- }
982
- function monogram(name) {
983
- const words = name.trim().split(/[\s._/-]+/).filter(Boolean);
984
- const letters = words.slice(0, 2).map((w) => w[0] ?? "").join("");
985
- return (letters || name.trim().slice(0, 2)).toUpperCase();
986
- }
987
- function OrgMark({ org, size = 22, maxW }) {
988
- if (org.logo) {
989
- return /* @__PURE__ */ jsx(
990
- "img",
991
- {
992
- src: org.logo,
993
- alt: "",
994
- style: {
995
- height: size,
996
- width: maxW ? "auto" : size,
997
- maxWidth: maxW ?? size,
998
- objectFit: "contain",
999
- display: "block",
1000
- borderRadius: 6,
1001
- flexShrink: 0
1002
- }
1003
- }
1004
- );
1005
- }
1006
- return /* @__PURE__ */ jsx(
1007
- YStack,
1008
- {
1009
- width: size,
1010
- height: size,
1011
- rounded: "$3",
1012
- bg: "$color4",
1013
- items: "center",
1014
- justify: "center",
1015
- style: { flexShrink: 0 },
1016
- children: /* @__PURE__ */ jsx(Text, { fontSize: Math.round(size * 0.4), fontWeight: "800", color: "$color12", children: monogram(org.displayName || org.name) })
1017
- }
1018
- );
1019
- }
1020
-
1021
- // src/product/scope.ts
1022
- function browserStorage() {
1023
- if (typeof window === "undefined") return null;
1024
- try {
1025
- return window.localStorage;
1026
- } catch {
1027
- return null;
1028
- }
1029
- }
1030
- function orgScope(config) {
1031
- const key = config.key ?? "hanzo.org";
1032
- const selectedKey = `${key}.selected`;
1033
- const store = () => config.storage ?? browserStorage();
1034
- const read = (k) => {
1035
- try {
1036
- return store()?.getItem(k) ?? null;
1037
- } catch {
1038
- return null;
1039
- }
1040
- };
1041
- const write = (k, v) => {
1042
- try {
1043
- if (v === null) store()?.removeItem(k);
1044
- else store()?.setItem(k, v);
1045
- } catch {
1046
- }
1047
- };
1048
- const goHome = () => {
1049
- if (config.navigate) return config.navigate("/");
1050
- if (typeof window !== "undefined") window.location.assign("/");
1051
- };
1052
- const doReload = () => {
1053
- if (config.reload) return config.reload();
1054
- if (typeof window !== "undefined") window.location.reload();
1055
- };
1056
- const scope = {
1057
- currentOrg: () => read(key) || config.brandOrg,
1058
- setCurrentOrg: (org) => write(key, !org || org === config.brandOrg ? null : org),
1059
- isScopedAway: () => scope.currentOrg() !== config.brandOrg,
1060
- hasSelectedOrg: () => read(selectedKey) === "1",
1061
- enterOrg: (org) => {
1062
- if (!org) return;
1063
- scope.setCurrentOrg(org);
1064
- write(selectedKey, "1");
1065
- goHome();
1066
- },
1067
- leaveOrg: () => {
1068
- write(selectedKey, null);
1069
- scope.setCurrentOrg(config.brandOrg);
1070
- goHome();
1071
- },
1072
- switchOrg: (org) => {
1073
- if (!org || org === scope.currentOrg()) return;
1074
- scope.setCurrentOrg(org);
1075
- write(selectedKey, "1");
1076
- doReload();
1077
- }
1078
- };
1079
- return scope;
1080
- }
1081
- function filterOrgs(orgs, query) {
1082
- const q = query.trim().toLowerCase();
1083
- if (!q) return orgs;
1084
- return orgs.filter(
1085
- (o) => o.name.toLowerCase().includes(q) || (o.displayName ?? "").toLowerCase().includes(q)
1086
- );
1087
- }
1088
- var titleCase = (s) => s ? s[0].toUpperCase() + s.slice(1) : s;
1089
- function OrgSwitcher({ scope, orgs, pageSize = 20, current: given, create, picker = false }) {
1090
- const currentId = scope.currentOrg();
1091
- const [open, setOpen] = useState(false);
1092
- const [query, setQuery] = useState("");
1093
- const [debounced, setDebounced] = useState("");
1094
- const [rows, setRows] = useState([]);
1095
- const [loading, setLoading] = useState(false);
1096
- const [loadingMore, setLoadingMore] = useState(false);
1097
- const [hasMore, setHasMore] = useState(false);
1098
- const [creating, setCreating] = useState(false);
1099
- const [newName, setNewName] = useState("");
1100
- const [busy, setBusy] = useState(false);
1101
- const [err, setErr] = useState(null);
1102
- const pageRef = useRef(0);
1103
- const reqRef = useRef(0);
1104
- useEffect(() => {
1105
- const id = setTimeout(() => setDebounced(query.trim()), 250);
1106
- return () => clearTimeout(id);
1107
- }, [query]);
1108
- const fetchPage = useCallback(
1109
- async (page, q, append) => {
1110
- if (!orgs) return;
1111
- const token = ++reqRef.current;
1112
- append ? setLoadingMore(true) : setLoading(true);
1113
- try {
1114
- const incoming = await orgs(page, q);
1115
- if (token !== reqRef.current) return;
1116
- pageRef.current = page;
1117
- setRows((prev) => {
1118
- const merged = append ? [...prev] : [];
1119
- const seen = new Set(merged.map((o) => o.name));
1120
- for (const o of incoming) if (!seen.has(o.name)) merged.push(o);
1121
- return merged;
1122
- });
1123
- setHasMore(incoming.length >= pageSize);
1124
- } catch {
1125
- if (token !== reqRef.current) return;
1126
- if (!append) setRows([]);
1127
- setHasMore(false);
1128
- } finally {
1129
- if (token === reqRef.current) {
1130
- setLoading(false);
1131
- setLoadingMore(false);
1132
- }
1133
- }
1134
- },
1135
- [orgs, pageSize]
1136
- );
1137
- useEffect(() => {
1138
- if (!open || !orgs) return;
1139
- void fetchPage(0, debounced, false);
1140
- }, [open, debounced, fetchPage, orgs]);
1141
- const loadMore = useCallback(() => {
1142
- if (loading || loadingMore || !hasMore) return;
1143
- void fetchPage(pageRef.current + 1, debounced, true);
1144
- }, [loading, loadingMore, hasMore, debounced, fetchPage]);
1145
- const visible = useMemo(() => {
1146
- if (orgs) return filterOrgs(rows, query);
1147
- return [{ name: currentId, displayName: titleCase(currentId) }];
1148
- }, [orgs, rows, query, currentId]);
1149
- const current = useMemo(() => {
1150
- if (given && given.name === currentId) return given;
1151
- return rows.find((o) => o.name === currentId) ?? { name: currentId, displayName: titleCase(currentId) };
1152
- }, [given, rows, currentId]);
1153
- const currentLabel = current.displayName || titleCase(current.name);
1154
- const track = useEmit();
1155
- const select = useCallback(
1156
- (org) => {
1157
- track({ component: "OrgSwitcher", action: "select", id: org });
1158
- setOpen(false);
1159
- scope.switchOrg(org);
1160
- },
1161
- [scope, track]
1162
- );
1163
- const submitCreate = async () => {
1164
- const name = newName.trim();
1165
- if (!name || !create) return;
1166
- setBusy(true);
1167
- setErr(null);
1168
- try {
1169
- const org = await create(name);
1170
- scope.switchOrg(org);
1171
- } catch (e) {
1172
- setErr(e instanceof Error ? e.message : "Could not create the organization.");
1173
- setBusy(false);
1174
- }
1175
- };
1176
- return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, placement: "bottom-start", children: [
1177
- /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { chromeless: true, height: 44, px: "$2", justify: "flex-start", "aria-label": `${currentLabel} \xB7 switch organization`, children: /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2.5", flex: 1, minW: 0, children: [
1178
- /* @__PURE__ */ jsx(OrgMark, { org: current, size: 30 }),
1179
- /* @__PURE__ */ jsx(Text, { flex: 1, minW: 0, fontSize: "$4", fontWeight: "800", color: "$color12", numberOfLines: 1, children: currentLabel }),
1180
- /* @__PURE__ */ jsx(ChevronsUpDown, { size: 15, color: "$color9" })
1181
- ] }) }) }),
1182
- /* @__PURE__ */ jsx(Popover.Content, { bordered: true, elevate: true, p: "$2", width: 300, bg: "$color2", borderColor: "$borderColor", children: creating ? /* @__PURE__ */ jsxs(YStack, { gap: "$2", children: [
1183
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", fontWeight: "700", children: "Create organization" }),
1184
- /* @__PURE__ */ jsx(
1185
- Input,
1186
- {
1187
- size: "$3",
1188
- placeholder: "Organization name",
1189
- value: newName,
1190
- onChangeText: setNewName,
1191
- autoCapitalize: "words",
1192
- onSubmitEditing: () => void submitCreate()
1193
- }
1194
- ),
1195
- err ? /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$red10", children: err }) : null,
1196
- /* @__PURE__ */ jsxs(XStack, { gap: "$2", justify: "flex-end", children: [
1197
- /* @__PURE__ */ jsx(Button, { size: "$2", chromeless: true, onPress: () => setCreating(false), disabled: busy, children: "Cancel" }),
1198
- /* @__PURE__ */ jsx(
1199
- Button,
1200
- {
1201
- size: "$2",
1202
- onPress: () => void submitCreate(),
1203
- disabled: busy || !newName.trim(),
1204
- icon: busy ? /* @__PURE__ */ jsx(Spinner, { size: "small" }) : /* @__PURE__ */ jsx(Plus, { size: 14 }),
1205
- children: "Create"
1206
- }
1207
- )
1208
- ] })
1209
- ] }) : /* @__PURE__ */ jsxs(YStack, { gap: "$1", children: [
1210
- orgs ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$2", py: "$1", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", children: [
1211
- /* @__PURE__ */ jsx(Search, { size: 13, opacity: 0.6 }),
1212
- /* @__PURE__ */ jsx(
1213
- Input,
1214
- {
1215
- flex: 1,
1216
- size: "$2",
1217
- borderWidth: 0,
1218
- bg: "transparent",
1219
- placeholder: "Find organization\u2026",
1220
- value: query,
1221
- onChangeText: setQuery,
1222
- autoCapitalize: "none",
1223
- autoCorrect: false
1224
- }
1225
- )
1226
- ] }) : null,
1227
- /* @__PURE__ */ jsxs(
1228
- "div",
1229
- {
1230
- style: { maxHeight: 300, overflowY: "auto", display: "flex", flexDirection: "column" },
1231
- onScroll: (e) => {
1232
- const el = e.currentTarget;
1233
- if (el.scrollHeight - el.scrollTop - el.clientHeight < 48) loadMore();
1234
- },
1235
- children: [
1236
- loading ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$2", py: "$3", children: [
1237
- /* @__PURE__ */ jsx(Spinner, { size: "small", color: "$color11" }),
1238
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color10", children: "Loading organizations\u2026" })
1239
- ] }) : visible.length === 0 ? /* @__PURE__ */ jsx(Text, { px: "$2", py: "$2", fontSize: "$2", color: "$color10", children: query.trim() ? `No organizations match \u201C${query.trim()}\u201D.` : "No organizations yet." }) : visible.map((org) => /* @__PURE__ */ jsxs(
1240
- XStack,
1241
- {
1242
- onPress: () => select(org.name),
1243
- cursor: "pointer",
1244
- items: "center",
1245
- gap: "$2.5",
1246
- px: "$2",
1247
- py: "$2",
1248
- rounded: "$3",
1249
- bg: org.name === currentId ? "$color4" : "transparent",
1250
- hoverStyle: { bg: "$color5" },
1251
- children: [
1252
- /* @__PURE__ */ jsx(OrgMark, { org }),
1253
- /* @__PURE__ */ jsx(Text, { flex: 1, fontSize: "$2", color: "$color12", numberOfLines: 1, children: org.displayName || org.name }),
1254
- org.name === currentId ? /* @__PURE__ */ jsx(Check, { size: 15 }) : null
1255
- ]
1256
- },
1257
- org.name
1258
- )),
1259
- loadingMore ? /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", px: "$2", py: "$2", children: [
1260
- /* @__PURE__ */ jsx(Spinner, { size: "small", color: "$color11" }),
1261
- /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color10", children: "Loading more\u2026" })
1262
- ] }) : hasMore ? /* @__PURE__ */ jsx(XStack, { onPress: loadMore, cursor: "pointer", items: "center", justify: "center", px: "$2", py: "$1.5", rounded: "$3", hoverStyle: { bg: "$color4" }, children: /* @__PURE__ */ jsx(Text, { fontSize: "$1", color: "$color11", fontWeight: "600", children: "Load more" }) }) : null
1263
- ]
1264
- }
1265
- ),
1266
- create ? /* @__PURE__ */ jsxs(
1267
- XStack,
1268
- {
1269
- onPress: () => {
1270
- setCreating(true);
1271
- setErr(null);
1272
- },
1273
- cursor: "pointer",
1274
- items: "center",
1275
- gap: "$2.5",
1276
- px: "$2",
1277
- py: "$2",
1278
- mt: "$1",
1279
- rounded: "$3",
1280
- borderTopWidth: 1,
1281
- borderColor: "$borderColor",
1282
- hoverStyle: { bg: "$color5" },
1283
- children: [
1284
- /* @__PURE__ */ jsx(YStack, { width: 22, height: 22, rounded: "$3", bg: "$color3", items: "center", justify: "center", children: /* @__PURE__ */ jsx(Plus, { size: 14 }) }),
1285
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", children: "Create organization" })
1286
- ]
1287
- }
1288
- ) : null,
1289
- picker ? /* @__PURE__ */ jsxs(
1290
- XStack,
1291
- {
1292
- onPress: () => {
1293
- setOpen(false);
1294
- scope.leaveOrg();
1295
- },
1296
- cursor: "pointer",
1297
- items: "center",
1298
- gap: "$2.5",
1299
- px: "$2",
1300
- py: "$2",
1301
- rounded: "$3",
1302
- hoverStyle: { bg: "$color5" },
1303
- children: [
1304
- /* @__PURE__ */ jsx(YStack, { width: 22, height: 22, rounded: "$3", bg: "$color3", items: "center", justify: "center", children: /* @__PURE__ */ jsx(LayoutGrid, { size: 14 }) }),
1305
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", children: "All organizations" })
1306
- ]
1307
- }
1308
- ) : null
1309
- ] }) })
1310
- ] });
1311
- }
1312
- function DropdownMenu({
1313
- trigger,
1314
- items,
1315
- open,
1316
- defaultOpen = false,
1317
- onOpenChange,
1318
- minWidth = 200,
1319
- maxHeight
1320
- }) {
1321
- const [isOpen, setOpen] = useControllableState({
1322
- prop: open,
1323
- defaultProp: defaultOpen,
1324
- onChange: onOpenChange
1325
- });
1326
- const anchorRef = useRef(null);
1327
- const anchorRect = useCallback(() => anchorRef.current?.getBoundingClientRect() ?? null, []);
1328
- const anchorEl = useCallback(() => anchorRef.current, []);
1329
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1330
- /* @__PURE__ */ jsx(XStack, { ref: anchorRef, self: "flex-start", cursor: "pointer", onPress: () => setOpen(!isOpen), children: trigger }),
1331
- /* @__PURE__ */ jsx(
1332
- FloatingMenu,
1333
- {
1334
- open: isOpen,
1335
- onClose: () => setOpen(false),
1336
- anchorRect,
1337
- anchorEl,
1338
- minWidth,
1339
- maxHeight,
1340
- children: renderMenuItems(items, () => setOpen(false))
1341
- }
1342
- )
1343
- ] });
1344
- }
1345
- function ContextMenu({ children, items, disabled, minWidth = 200, maxHeight }) {
1346
- const [state, setState] = useState({ open: false, x: 0, y: 0 });
1347
- const close = useCallback(() => setState((s) => s.open ? { ...s, open: false } : s), []);
1348
- const anchorRect = useCallback(
1349
- () => ({ left: state.x, top: state.y, right: state.x, bottom: state.y, width: 0, height: 0 }),
1350
- [state.x, state.y]
1351
- );
1352
- const childOnContextMenu = children.props.onContextMenu;
1353
- const target = cloneElement(children, {
1354
- onContextMenu: (e) => {
1355
- childOnContextMenu?.(e);
1356
- if (disabled) return;
1357
- e.preventDefault();
1358
- e.stopPropagation();
1359
- setState({ open: true, x: e.clientX, y: e.clientY });
1360
- }
1361
- });
1362
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1363
- target,
1364
- /* @__PURE__ */ jsx(FloatingMenu, { open: state.open, onClose: close, anchorRect, gap: 0, minWidth, maxHeight, children: renderMenuItems(items, close) })
1365
- ] });
1366
- }
1367
- var isExternal = (href) => /^https?:\/\//.test(href);
1368
- var defaultLink = ({ href, children, onNavigate }) => /* @__PURE__ */ jsx(
1369
- "a",
1370
- {
1371
- href,
1372
- onClick: onNavigate,
1373
- ...isExternal(href) ? { target: "_blank", rel: "noopener noreferrer" } : null,
1374
- style: { textDecoration: "none", color: "inherit", display: "block" },
1375
- children
1376
- }
1377
- );
1378
- function ProductCell({ product, link, icon, close }) {
1379
- const glyph = icon?.(product.id);
1380
- return /* @__PURE__ */ jsx(YStack, { minW: 200, flex: 1, flexBasis: 200, children: link({
1381
- href: product.url,
1382
- onNavigate: close,
1383
- children: /* @__PURE__ */ jsxs(XStack, { gap: "$2.5", items: "flex-start", p: "$2.5", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", hoverStyle: { bg: "$color4" }, children: [
1384
- glyph ? /* @__PURE__ */ jsx(YStack, { pt: "$0.5", children: glyph }) : null,
1385
- /* @__PURE__ */ jsxs(YStack, { minW: 0, gap: "$0.5", children: [
1386
- product.verb ? /* @__PURE__ */ jsx(Text, { fontSize: 11, color: "$color10", textTransform: "uppercase", letterSpacing: 0.4, children: product.verb }) : null,
1387
- /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color12", children: product.name }),
1388
- /* @__PURE__ */ jsx(Text, { fontSize: 12, color: "$color10", lineHeight: 16, children: product.job })
1389
- ] })
1390
- ] })
1391
- }) });
1392
- }
1393
- function Column({ title, links, link, icon, close }) {
1394
- return /* @__PURE__ */ jsxs(YStack, { minW: 160, flex: 1, gap: "$1", children: [
1395
- /* @__PURE__ */ jsx(Text, { fontSize: 11, color: "$color10", textTransform: "uppercase", letterSpacing: 0.5, px: "$2", pb: "$1", children: title }),
1396
- links.map((l) => /* @__PURE__ */ jsxs(XStack, { px: "$2", py: "$1", rounded: "$3", hoverStyle: { bg: "$color4" }, gap: "$2", items: "center", children: [
1397
- icon?.(l.id) ?? null,
1398
- link({
1399
- href: l.href,
1400
- onNavigate: close,
1401
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: l.label })
1402
- })
1403
- ] }, l.id))
1404
- ] });
1405
- }
1406
- function Launcher({ menu, link, icon, close }) {
1407
- return /* @__PURE__ */ jsxs(
1408
- YStack,
1409
- {
1410
- position: "absolute",
1411
- t: 52,
1412
- l: 0,
1413
- r: 0,
1414
- z: 50,
1415
- bg: "$background",
1416
- borderBottomWidth: 1,
1417
- borderColor: "$borderColor",
1418
- px: "$4",
1419
- py: "$4",
1420
- gap: "$3",
1421
- maxH: "80vh",
1422
- overflow: "scroll",
1423
- children: [
1424
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: [
1425
- /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: menu.eyebrow }),
1426
- /* @__PURE__ */ jsx(XStack, { ml: "auto", children: link({
1427
- href: menu.allProducts.href,
1428
- onNavigate: close,
1429
- children: /* @__PURE__ */ jsxs(Text, { fontSize: "$2", color: "$color12", children: [
1430
- menu.allProducts.label,
1431
- " \u2192"
1432
- ] })
1433
- }) })
1434
- ] }),
1435
- /* @__PURE__ */ jsx(XStack, { gap: "$2.5", flexWrap: "wrap", children: menu.products.map((p) => /* @__PURE__ */ jsx(ProductCell, { product: p, link, icon, close }, p.id)) }),
1436
- /* @__PURE__ */ jsx(Separator, {}),
1437
- /* @__PURE__ */ jsxs(XStack, { gap: "$4", flexWrap: "wrap", items: "flex-start", children: [
1438
- /* @__PURE__ */ jsx(Column, { title: "Platform", links: menu.utilities, link, icon, close }),
1439
- /* @__PURE__ */ jsx(Column, { title: "Install", links: menu.installs, link, icon, close })
1440
- ] })
1441
- ]
1442
- }
1443
- );
1444
- }
1445
- function Cta({ action, link }) {
1446
- return /* @__PURE__ */ jsx(XStack, { bg: "$color12", px: "$3", py: "$1.5", rounded: "$3", hoverStyle: { opacity: 0.9 }, children: link({
1447
- href: action.href,
1448
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$background", children: action.label })
1449
- }) });
1450
- }
1451
- function MobilePanel({ header, menu, link, icon, close }) {
1452
- return /* @__PURE__ */ jsxs(
1453
- YStack,
1454
- {
1455
- position: "absolute",
1456
- t: 52,
1457
- l: 0,
1458
- r: 0,
1459
- z: 50,
1460
- bg: "$background",
1461
- borderBottomWidth: 1,
1462
- borderColor: "$borderColor",
1463
- px: "$3",
1464
- py: "$3",
1465
- gap: "$3",
1466
- maxH: "80vh",
1467
- overflow: "scroll",
1468
- children: [
1469
- /* @__PURE__ */ jsx(YStack, { gap: "$1", children: header.localNav.map((l) => /* @__PURE__ */ jsx(XStack, { px: "$2", py: "$1.5", rounded: "$3", hoverStyle: { bg: "$color4" }, children: link({
1470
- href: l.href,
1471
- onNavigate: close,
1472
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color12", children: l.label })
1473
- }) }, l.id)) }),
1474
- menu ? /* @__PURE__ */ jsxs(Fragment, { children: [
1475
- /* @__PURE__ */ jsx(Separator, {}),
1476
- /* @__PURE__ */ jsx(YStack, { gap: "$1", children: menu.products.map((p) => /* @__PURE__ */ jsxs(XStack, { px: "$2", py: "$1.5", rounded: "$3", hoverStyle: { bg: "$color4" }, gap: "$2", items: "center", children: [
1477
- icon?.(p.id) ?? null,
1478
- link({
1479
- href: p.url,
1480
- onNavigate: close,
1481
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color12", children: p.name })
1482
- })
1483
- ] }, p.id)) }),
1484
- /* @__PURE__ */ jsx(Separator, {}),
1485
- /* @__PURE__ */ jsx(Column, { title: "Platform", links: menu.utilities, link, icon, close }),
1486
- /* @__PURE__ */ jsx(Column, { title: "Install", links: menu.installs, link, icon, close })
1487
- ] }) : null
1488
- ]
1489
- }
1490
- );
1491
- }
1492
- function SiteNav({ header, menu, brand, actions, link = defaultLink, icon, active, meetLabel = "Meet Hanzo" }) {
1493
- const [launcher, setLauncher] = useState(false);
1494
- const [mobile, setMobile] = useState(false);
1495
- const root = useRef(null);
1496
- useEffect(() => {
1497
- if (!launcher && !mobile) return;
1498
- const dismiss = () => {
1499
- setLauncher(false);
1500
- setMobile(false);
1501
- };
1502
- const onKey = (e) => {
1503
- if (e.key === "Escape") dismiss();
1504
- };
1505
- const onDown = (e) => {
1506
- if (root.current && !root.current.contains(e.target)) dismiss();
1507
- };
1508
- document.addEventListener("keydown", onKey);
1509
- document.addEventListener("mousedown", onDown);
1510
- return () => {
1511
- document.removeEventListener("keydown", onKey);
1512
- document.removeEventListener("mousedown", onDown);
1513
- };
1514
- }, [launcher, mobile]);
1515
- return /* @__PURE__ */ jsxs(YStack, { ref: root, position: "relative", bg: "$background", children: [
1516
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$1", px: "$3", height: 52, borderBottomWidth: 1, borderColor: "$borderColor", children: [
1517
- brand ? /* @__PURE__ */ jsx(XStack, { items: "center", pr: "$2", children: brand }) : null,
1518
- menu ? /* @__PURE__ */ jsx(
1519
- XStack,
1520
- {
1521
- cursor: "pointer",
1522
- px: "$2.5",
1523
- py: "$1.5",
1524
- rounded: "$3",
1525
- bg: launcher ? "$color4" : "transparent",
1526
- hoverStyle: { bg: "$color4" },
1527
- onPress: () => setLauncher(!launcher),
1528
- accessibilityRole: "button",
1529
- "aria-expanded": launcher,
1530
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", children: meetLabel })
1531
- }
1532
- ) : null,
1533
- /* @__PURE__ */ jsx(XStack, { items: "center", gap: "$0.5", flex: 1, minW: 0, $sm: { display: "none" }, children: header.localNav.map((l) => /* @__PURE__ */ jsx(
1534
- XStack,
1535
- {
1536
- px: "$2.5",
1537
- py: "$1.5",
1538
- rounded: "$3",
1539
- hoverStyle: { bg: "$color4" },
1540
- onMouseEnter: () => launcher && setLauncher(false),
1541
- children: link({
1542
- href: l.href,
1543
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: active === l.id ? "$color12" : "$color11", children: l.label })
1544
- })
1545
- },
1546
- l.id
1547
- )) }),
1548
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$2", ml: "auto", children: [
1549
- actions,
1550
- /* @__PURE__ */ jsx(Cta, { action: header.action, link }),
1551
- /* @__PURE__ */ jsx(
1552
- XStack,
1553
- {
1554
- display: "none",
1555
- $sm: { display: "flex" },
1556
- cursor: "pointer",
1557
- px: "$2",
1558
- py: "$1.5",
1559
- rounded: "$3",
1560
- hoverStyle: { bg: "$color4" },
1561
- onPress: () => setMobile(!mobile),
1562
- accessibilityRole: "button",
1563
- "aria-label": mobile ? "Close menu" : "Open menu",
1564
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", children: mobile ? "Close" : "Menu" })
1565
- }
1566
- )
1567
- ] })
1568
- ] }),
1569
- launcher && menu ? /* @__PURE__ */ jsx(Launcher, { menu, link, icon, close: () => setLauncher(false) }) : null,
1570
- mobile ? /* @__PURE__ */ jsx(MobilePanel, { header, menu, link, icon, close: () => setMobile(false) }) : null
1571
- ] });
1572
- }
1573
- var isExternal2 = (href) => /^https?:\/\//.test(href);
1574
- var defaultLink2 = ({ href, children }) => /* @__PURE__ */ jsx(
1575
- "a",
1576
- {
1577
- href,
1578
- ...isExternal2(href) ? { target: "_blank", rel: "noopener noreferrer" } : null,
1579
- style: { textDecoration: "none", color: "inherit" },
1580
- children
1581
- }
1582
- );
1583
- function SiteFooter({ footer, brand, tagline, meta, link = defaultLink2 }) {
1584
- return /* @__PURE__ */ jsxs(YStack, { borderTopWidth: 1, borderColor: "$borderColor", bg: "$background", px: "$4", py: "$5", gap: "$4", children: [
1585
- /* @__PURE__ */ jsxs(XStack, { gap: "$5", flexWrap: "wrap", items: "flex-start", children: [
1586
- brand || tagline ? /* @__PURE__ */ jsxs(YStack, { gap: "$2", minW: 200, flex: 1, children: [
1587
- brand,
1588
- tagline ? /* @__PURE__ */ jsx(Text, { fontSize: 12, color: "$color10", lineHeight: 18, maxW: 280, children: tagline }) : null
1589
- ] }) : null,
1590
- footer.columns.map((column) => /* @__PURE__ */ jsxs(YStack, { gap: "$1.5", minW: 140, children: [
1591
- /* @__PURE__ */ jsx(Text, { fontSize: 11, color: "$color10", textTransform: "uppercase", letterSpacing: 0.5, pb: "$1", children: column.title }),
1592
- column.links.map((l) => /* @__PURE__ */ jsx(XStack, { hoverStyle: { opacity: 0.7 }, children: link({
1593
- href: l.href,
1594
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: l.label })
1595
- }) }, l.id))
1596
- ] }, column.id))
1597
- ] }),
1598
- /* @__PURE__ */ jsx(Separator, {}),
1599
- /* @__PURE__ */ jsxs(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: [
1600
- /* @__PURE__ */ jsx(Text, { fontSize: 12, color: "$color10", children: footer.legal.copyright }),
1601
- /* @__PURE__ */ jsx(XStack, { items: "center", gap: "$3", flexWrap: "wrap", children: footer.legal.links.map((l) => /* @__PURE__ */ jsx(XStack, { hoverStyle: { opacity: 0.7 }, children: link({
1602
- href: l.href,
1603
- children: /* @__PURE__ */ jsx(Text, { fontSize: 12, color: "$color10", children: l.label })
1604
- }) }, l.id)) }),
1605
- meta ? /* @__PURE__ */ jsx(XStack, { ml: "auto", items: "center", gap: "$3", children: meta }) : null
1606
- ] })
1607
- ] });
1608
- }
1609
- function CommerceResource({
1610
- title,
1611
- subtitle,
1612
- load,
1613
- columns,
1614
- rowKey,
1615
- empty,
1616
- hint,
1617
- actions
1618
- }) {
1619
- const [state, setState] = useState({ phase: "loading" });
1620
- const loadRef = useRef(load);
1621
- loadRef.current = load;
1622
- const reload = useCallback(() => {
1623
- setState({ phase: "loading" });
1624
- loadRef.current().then((r) => setState({ phase: "ready", data: r.rows })).catch((e) => setState({ phase: "error", error: classifyBackend(e) }));
1625
- }, []);
1626
- useEffect(() => {
1627
- reload();
1628
- }, [reload]);
1629
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1630
- /* @__PURE__ */ jsx(
1631
- PageHeader,
1632
- {
1633
- title,
1634
- subtitle,
1635
- actions: /* @__PURE__ */ jsxs(XStack, { gap: "$2", children: [
1636
- actions?.(reload),
1637
- /* @__PURE__ */ jsx(Button, { size: "$2", icon: /* @__PURE__ */ jsx(RefreshCw, { size: 15 }), onPress: reload, children: "Refresh" })
1638
- ] })
1639
- }
1640
- ),
1641
- state.phase === "error" ? /* @__PURE__ */ jsx(BackendStateCard, { state: state.error, onRetry: reload, hint }) : /* @__PURE__ */ jsx(
1642
- DataTable,
1643
- {
1644
- columns,
1645
- rows: state.phase === "ready" ? state.data : [],
1646
- loading: state.phase === "loading",
1647
- rowKey,
1648
- empty
1649
- }
1650
- )
1651
- ] });
1652
- }
1653
- function ConfirmDelete({
1654
- message,
1655
- confirmLabel,
1656
- run,
1657
- onDone
1658
- }) {
1659
- const [busy, setBusy] = useState(false);
1660
- const [err, setErr] = useState(null);
1661
- const track = useEmit();
1662
- const go = async () => {
1663
- setBusy(true);
1664
- setErr(null);
1665
- track({ component: "ConfirmDelete", action: "confirm", id: confirmLabel });
1666
- try {
1667
- await run();
1668
- onDone();
1669
- } catch (e) {
1670
- const message2 = classifyBackend(e).message || "Failed to delete.";
1671
- track({ component: "ConfirmDelete", action: "error", id: confirmLabel, value: message2 });
1672
- setErr(message2);
1673
- setBusy(false);
1674
- }
1675
- };
1676
- return /* @__PURE__ */ jsxs(YStack, { gap: "$3", children: [
1677
- /* @__PURE__ */ jsx(Text, { fontSize: "$3", color: "$color11", children: message }),
1678
- err ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$red10", children: err }) : null,
1679
- /* @__PURE__ */ jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [
1680
- /* @__PURE__ */ jsx(
1681
- Button,
1682
- {
1683
- onPress: go,
1684
- disabled: busy,
1685
- icon: /* @__PURE__ */ jsx(Trash2, { size: 15 }),
1686
- style: { backgroundColor: "#dc2626", borderColor: "#dc2626", color: "#fff" },
1687
- children: busy ? "Deleting\u2026" : confirmLabel
1688
- }
1689
- ),
1690
- /* @__PURE__ */ jsx(
1691
- Button,
1692
- {
1693
- chromeless: true,
1694
- onPress: () => {
1695
- track({ component: "ConfirmDelete", action: "cancel", id: confirmLabel });
1696
- onDone();
1697
- },
1698
- disabled: busy,
1699
- children: "Cancel"
1700
- }
1701
- )
1702
- ] })
1703
- ] });
1704
- }
1705
- function Segmented({
1706
- options,
1707
- value,
1708
- onChange,
1709
- size = "$2",
1710
- name
1711
- }) {
1712
- const track = useEmit();
1713
- return /* @__PURE__ */ jsx(XStack, { gap: "$1", flexWrap: "wrap", items: "center", children: options.map((o) => {
1714
- const active = o.value === value;
1715
- return /* @__PURE__ */ jsx(
1716
- Button,
1717
- {
1718
- size,
1719
- bg: active ? "$color5" : "transparent",
1720
- borderWidth: 1,
1721
- borderColor: active ? "$color7" : "$borderColor",
1722
- "aria-pressed": active,
1723
- onPress: () => {
1724
- track({ component: "Segmented", action: "filter", id: name, value: o.value });
1725
- onChange(o.value);
1726
- },
1727
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", fontWeight: active ? "700" : "500", color: active ? "$color12" : "$color11", children: o.label })
1728
- },
1729
- o.value
1730
- );
1731
- }) });
1732
- }
1733
- function SearchInput({
1734
- value,
1735
- onChange,
1736
- placeholder,
1737
- name
1738
- }) {
1739
- const track = useEmit();
1740
- const onChangeTracked = (v) => {
1741
- track({ component: "SearchInput", action: "search", id: name, value: textSize(v) });
1742
- onChange(v);
1743
- };
1744
- return /* @__PURE__ */ jsxs(XStack, { flex: 1, minW: 180, items: "center", gap: "$2", px: "$3", borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$color1", children: [
1745
- /* @__PURE__ */ jsx(Search, { size: 15, color: "$color10" }),
1746
- /* @__PURE__ */ jsx(Input, { flex: 1, value, onChangeText: onChangeTracked, placeholder, borderWidth: 0, bg: "transparent", px: "$0", fontSize: "$3" })
1747
- ] });
1748
- }
1749
-
1750
- // src/product/brand.ts
1751
- var HANZO_MARK_CONTENT = '<path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/>';
1752
- var HANZO = {
1753
- id: "hanzo",
1754
- name: "Hanzo",
1755
- viewBox: "0 0 67 67",
1756
- content: HANZO_MARK_CONTENT,
1757
- href: "https://hanzo.ai"
1758
- };
1759
- var LUX = {
1760
- id: "lux",
1761
- name: "Lux",
1762
- viewBox: "0 0 100 100",
1763
- content: '<path d="M50 85 L15 25 L85 25 Z"/>',
1764
- href: "https://lux.network"
1765
- };
1766
- var ZOO = {
1767
- id: "zoo",
1768
- name: "Zoo",
1769
- viewBox: "0 0 1024 1024",
1770
- fullColor: true,
1771
- content: '<defs><clipPath id="zooClip"><circle cx="512" cy="511" r="270"/></clipPath><clipPath id="zooGClip"><circle cx="513" cy="369" r="234"/></clipPath><clipPath id="zooRClip"><circle cx="365" cy="595" r="234"/></clipPath></defs><g clip-path="url(#zooClip)"><circle cx="513" cy="369" r="234" fill="#00A652"/><circle cx="365" cy="595" r="234" fill="#ED1C24"/><circle cx="643" cy="595" r="234" fill="#2E3192"/><g clip-path="url(#zooGClip)"><circle cx="365" cy="595" r="234" fill="#FCF006"/><circle cx="643" cy="595" r="234" fill="#01ACF1"/></g><g clip-path="url(#zooRClip)"><circle cx="643" cy="595" r="234" fill="#EA018E"/></g><g clip-path="url(#zooGClip)"><g clip-path="url(#zooRClip)"><circle cx="643" cy="595" r="234" fill="#FFFFFF"/></g></g></g>',
1772
- href: "https://zoo.ngo"
1773
- };
1774
- var PARS = {
1775
- id: "pars",
1776
- name: "Pars",
1777
- viewBox: "-120 -120 240 240",
1778
- content: '<path d="M0,-100 L30,-60 L100,-40 L60,0 L100,40 L30,60 L0,100 L-30,60 L-100,40 L-60,0 L-100,-40 L-30,-60 Z" fill="none" stroke="currentColor" stroke-width="4" stroke-linejoin="round"/><path d="M0,-70 L22,-42 L70,-28 L42,0 L70,28 L22,42 L0,70 L-22,42 L-70,28 L-42,0 L-70,-28 L-22,-42 Z" fill="currentColor" fill-opacity="0.15" stroke="currentColor" stroke-width="3" stroke-linejoin="round"/><circle r="55" fill="none" stroke="currentColor" stroke-width="1.5" opacity="0.4"/><circle r="35" fill="none" stroke="currentColor" stroke-width="1.5" opacity="0.4"/><circle r="8" fill="currentColor"/>',
1779
- href: "https://pars.network"
1780
- };
1781
- var BRANDS = { hanzo: HANZO, lux: LUX, zoo: ZOO, pars: PARS };
1782
- function resolveBrand(id) {
1783
- return id && BRANDS[id] || HANZO;
1784
- }
1785
-
1786
- // src/product/animatedLogo.logic.ts
1787
- var HOUSE_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";
1788
- var DEFAULT_DURATION_MS = 360;
1789
- var DEFAULT_INTRO_MS = 1500;
1790
- var DEFAULT_GAP = 8;
1791
- function wordmarkText(name, surface) {
1792
- const s = surface?.trim();
1793
- return s ? `${name} ${s}` : name;
1794
- }
1795
- function isExpanded(s) {
1796
- return s.hovered || s.focused || s.introShowing;
1797
- }
1798
- function wordmarkStyle(i) {
1799
- return {
1800
- width: i.expanded ? i.naturalWidth ?? "auto" : 0,
1801
- opacity: i.expanded ? 1 : 0,
1802
- marginLeft: i.expanded ? i.gap : 0,
1803
- transition: i.reduce ? "none" : `width ${i.durationMs}ms ${i.easing}, opacity ${i.durationMs}ms ${i.easing}, margin-left ${i.durationMs}ms ${i.easing}`
1804
- };
1805
- }
1806
- function usePrefersReducedMotion() {
1807
- const [reduce, setReduce] = useState(false);
1808
- useEffect(() => {
1809
- if (typeof window === "undefined" || !window.matchMedia) return;
1810
- const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
1811
- const sync = () => setReduce(mq.matches);
1812
- sync();
1813
- mq.addEventListener("change", sync);
1814
- return () => mq.removeEventListener("change", sync);
1815
- }, []);
1816
- return reduce;
1817
- }
1818
- function AnimatedLogo({
1819
- surface,
1820
- brand = HANZO,
1821
- size = 22,
1822
- gap = DEFAULT_GAP,
1823
- introMs = DEFAULT_INTRO_MS,
1824
- durationMs = DEFAULT_DURATION_MS,
1825
- easing = HOUSE_EASE,
1826
- href,
1827
- onClick,
1828
- component,
1829
- className,
1830
- style,
1831
- "aria-label": ariaLabel
1832
- }) {
1833
- const reduce = usePrefersReducedMotion();
1834
- const label = ariaLabel ?? wordmarkText(brand.name, surface);
1835
- const [hovered, setHovered] = useState(false);
1836
- const [focused, setFocused] = useState(false);
1837
- const [introShowing, setIntroShowing] = useState(introMs > 0);
1838
- const [naturalWidth, setNaturalWidth] = useState(void 0);
1839
- const wordRef = useRef(null);
1840
- useEffect(() => {
1841
- if (introMs <= 0) return;
1842
- if (reduce) {
1843
- setIntroShowing(false);
1844
- return;
1845
- }
1846
- const t = setTimeout(() => setIntroShowing(false), introMs);
1847
- return () => clearTimeout(t);
1848
- }, [introMs, reduce]);
1849
- useLayoutEffect(() => {
1850
- const el = wordRef.current;
1851
- if (!el) return;
1852
- const measure = () => setNaturalWidth(el.scrollWidth);
1853
- measure();
1854
- const fonts = typeof document !== "undefined" && document.fonts || null;
1855
- if (fonts?.ready) fonts.ready.then(measure).catch(() => {
1856
- });
1857
- }, [brand.name, surface]);
1858
- const expanded = isExpanded({ hovered, focused, introShowing });
1859
- const ws = wordmarkStyle({ expanded, naturalWidth, gap, durationMs, easing, reduce });
1860
- const Root = component ?? "a";
1861
- const isAnchor = Root === "a";
1862
- return /* @__PURE__ */ jsxs(
1863
- Root,
1864
- {
1865
- ...isAnchor ? { href: href ?? brand.href ?? "/" } : { href: href ?? brand.href },
1866
- onClick,
1867
- "aria-label": label,
1868
- title: label,
1869
- className,
1870
- onMouseEnter: () => setHovered(true),
1871
- onMouseLeave: () => setHovered(false),
1872
- onFocus: () => setFocused(true),
1873
- onBlur: () => setFocused(false),
1874
- style: {
1875
- display: "inline-flex",
1876
- alignItems: "center",
1877
- textDecoration: "none",
1878
- color: "inherit",
1879
- cursor: "pointer",
1880
- ...style
1881
- },
1882
- children: [
1883
- /* @__PURE__ */ jsx(
1884
- "svg",
1885
- {
1886
- width: size,
1887
- height: size,
1888
- viewBox: brand.viewBox,
1889
- "aria-hidden": "true",
1890
- focusable: "false",
1891
- fill: brand.fullColor ? void 0 : "currentColor",
1892
- style: { display: "block", flexShrink: 0 },
1893
- dangerouslySetInnerHTML: { __html: brand.content }
1894
- }
1895
- ),
1896
- /* @__PURE__ */ jsx(
1897
- "span",
1898
- {
1899
- ref: wordRef,
1900
- "aria-hidden": "true",
1901
- style: {
1902
- display: "inline-block",
1903
- overflow: "hidden",
1904
- whiteSpace: "nowrap",
1905
- fontWeight: 600,
1906
- fontSize: 15,
1907
- letterSpacing: "-0.01em",
1908
- lineHeight: 1,
1909
- width: ws.width,
1910
- opacity: ws.opacity,
1911
- marginLeft: ws.marginLeft,
1912
- transition: ws.transition
1913
- },
1914
- children: label
1915
- }
1916
- )
1917
- ]
1918
- }
1919
- );
1920
- }
1921
- function FadeIn({
1922
- children,
1923
- index = 0,
1924
- step = 50,
1925
- delayMs,
1926
- style
1927
- }) {
1928
- const delay = delayMs ?? index * step;
1929
- return /* @__PURE__ */ jsx("div", { className: "hz-fade-up", style: { animationDelay: `${delay}ms`, ...style }, children });
1930
- }
1931
- function ProductIcon({
1932
- icon: Icon,
1933
- color,
1934
- size = 24
1935
- }) {
1936
- const radius = Math.round(size * 0.28);
1937
- const glyph = Math.round(size * 0.58);
1938
- const tinted = typeof color === "string" && color.trim() !== "";
1939
- if (tinted) {
1940
- return /* @__PURE__ */ jsx(
1941
- XStack,
1942
- {
1943
- width: size,
1944
- height: size,
1945
- items: "center",
1946
- justify: "center",
1947
- rounded: radius,
1948
- style: { backgroundColor: color },
1949
- children: /* @__PURE__ */ jsx(Icon, { size: glyph, color: asColor("#ffffff") })
1950
- }
1951
- );
1952
- }
1953
- return /* @__PURE__ */ jsx(XStack, { width: size, height: size, items: "center", justify: "center", rounded: radius, bg: "$color12", children: /* @__PURE__ */ jsx(Icon, { size: glyph, color: "$color1" }) });
1954
- }
1955
- var KNOWN = {
1956
- openrouter: Globe,
1957
- nvidia: Cpu
1958
- };
1959
- var isFirstParty = (provider) => {
1960
- const p = provider.trim().toLowerCase();
1961
- return p === "hanzo" || p === "zen";
1962
- };
1963
- function EnsoMark({ size, color }) {
1964
- return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 100 100", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M66.22 83.26 A37 37 0 1 1 85.57 60.20", fill: "none", stroke: color, strokeWidth: 11, strokeLinecap: "round" }) });
1965
- }
1966
- var HANZO_PATHS = [
1967
- "M22.21 67V44.6369H0V67H22.21Z",
1968
- "M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z",
1969
- "M22.21 0H0V22.3184H22.21V0Z",
1970
- "M66.7198 0H44.5098V22.3184H66.7198V0Z",
1971
- "M66.7198 67V44.6369H44.5098V67H66.7198Z"
1972
- ];
1973
- function HanzoHMark({ size, color }) {
1974
- return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 67 67", "aria-hidden": "true", children: HANZO_PATHS.map((d) => /* @__PURE__ */ jsx("path", { d, fill: color }, d)) });
1975
- }
1976
- function providerInitials(provider) {
1977
- const name = provider.trim();
1978
- if (!name) return "\u2022";
1979
- const words = name.split(/[\s/_-]+/).filter(Boolean);
1980
- if (words.length >= 2) return (words[0][0] + words[1][0]).toUpperCase();
1981
- return name.slice(0, 2).toUpperCase();
1982
- }
1983
- function ProviderLogo({ provider, size = 24 }) {
1984
- const theme = useTheme();
1985
- const radius = Math.round(size * 0.28);
1986
- const iconSize = Math.round(size * 0.56);
1987
- if (isFirstParty(provider)) {
1988
- const fg = theme.color1?.get() ?? "#000000";
1989
- const markSize = Math.round(size * 0.66);
1990
- const isZen = provider.trim().toLowerCase() === "zen";
1991
- return /* @__PURE__ */ jsx(XStack, { width: size, height: size, items: "center", justify: "center", rounded: radius, bg: "$color12", children: isZen ? /* @__PURE__ */ jsx(EnsoMark, { size: markSize, color: fg }) : /* @__PURE__ */ jsx(HanzoHMark, { size: Math.round(size * 0.56), color: fg }) });
1992
- }
1993
- const Known = KNOWN[provider.trim().toLowerCase()];
1994
- if (Known) {
1995
- return /* @__PURE__ */ jsx(
1996
- XStack,
1997
- {
1998
- width: size,
1999
- height: size,
2000
- items: "center",
2001
- justify: "center",
2002
- rounded: radius,
2003
- bg: "$color3",
2004
- borderWidth: 1,
2005
- borderColor: "$borderColor",
2006
- children: /* @__PURE__ */ jsx(Known, { size: iconSize, color: "$color11" })
2007
- }
2008
- );
2009
- }
2010
- return /* @__PURE__ */ jsx(
2011
- XStack,
2012
- {
2013
- width: size,
2014
- height: size,
2015
- items: "center",
2016
- justify: "center",
2017
- rounded: radius,
2018
- bg: "$color3",
2019
- borderWidth: 1,
2020
- borderColor: "$borderColor",
2021
- children: /* @__PURE__ */ jsx(Text, { fontSize: Math.round(size * 0.4), fontWeight: "800", color: "$color11", children: providerInitials(provider) })
2022
- }
2023
- );
2024
- }
2025
- function GenericLogo({ size = 24 }) {
2026
- return /* @__PURE__ */ jsx(XStack, { width: size, height: size, items: "center", justify: "center", rounded: Math.round(size * 0.28), bg: "$color3", borderWidth: 1, borderColor: "$borderColor", children: /* @__PURE__ */ jsx(Server, { size: Math.round(size * 0.56), color: "$color11" }) });
2027
- }
2028
- function targetIndex(from, dy, rowH, count) {
2029
- if (rowH <= 0 || count <= 0) return from;
2030
- const raw = from + Math.round(dy / rowH);
2031
- return Math.max(0, Math.min(raw, count - 1));
2032
- }
2033
- function rowShift(i, from, to, dy, rowH) {
2034
- if (i === from) return dy;
2035
- if (from < to && i > from && i <= to) return -rowH;
2036
- if (from > to && i < from && i >= to) return rowH;
2037
- return 0;
2038
- }
2039
- function Reorder({
2040
- items,
2041
- keyOf,
2042
- rowHeight = 44,
2043
- onReorder,
2044
- renderItem
2045
- }) {
2046
- const [drag, setDrag] = useState(null);
2047
- const startRef = useRef(null);
2048
- const to = drag ? targetIndex(drag.from, drag.dy, rowHeight, items.length) : -1;
2049
- const begin = useCallback(
2050
- (index) => (e) => {
2051
- const startY = e.clientY ?? e.nativeEvent?.clientY ?? 0;
2052
- startRef.current = { from: index, startY };
2053
- setDrag({ from: index, dy: 0 });
2054
- const move = (ev) => {
2055
- if (!startRef.current) return;
2056
- setDrag({ from: startRef.current.from, dy: ev.clientY - startRef.current.startY });
2057
- };
2058
- const end = () => {
2059
- const s = startRef.current;
2060
- window.removeEventListener("pointermove", move);
2061
- window.removeEventListener("pointerup", end);
2062
- window.removeEventListener("pointercancel", end);
2063
- startRef.current = null;
2064
- setDrag((d) => {
2065
- if (s && d) {
2066
- const t = targetIndex(s.from, d.dy, rowHeight, items.length);
2067
- if (t !== s.from) onReorder(s.from, t);
2068
- }
2069
- return null;
2070
- });
2071
- };
2072
- window.addEventListener("pointermove", move);
2073
- window.addEventListener("pointerup", end);
2074
- window.addEventListener("pointercancel", end);
2075
- },
2076
- [items.length, rowHeight, onReorder]
2077
- );
2078
- return /* @__PURE__ */ jsx(YStack, { children: items.map((item, i) => {
2079
- const dragging = drag?.from === i;
2080
- const shift = drag && to >= 0 ? rowShift(i, drag.from, to, drag.dy, rowHeight) : 0;
2081
- return /* @__PURE__ */ jsx(
2082
- YStack,
2083
- {
2084
- height: rowHeight,
2085
- justify: "center",
2086
- className: "hz-drag-item",
2087
- style: {
2088
- transform: `translateY(${shift}px)`,
2089
- zIndex: dragging ? 2 : 1,
2090
- ...dragging ? { transition: "none", boxShadow: "0 8px 24px rgba(0,0,0,0.28)" } : null
2091
- },
2092
- children: renderItem(item, { onPointerDown: begin(i) }, dragging)
2093
- },
2094
- keyOf(item)
2095
- );
2096
- }) });
2097
- }
2098
- function SelectMenu({
2099
- options,
2100
- value,
2101
- onChange,
2102
- allLabel = "All",
2103
- icon,
2104
- minWidth = 130
2105
- }) {
2106
- const active = value === null ? null : options.find((o) => o.key === value) ?? null;
2107
- const triggerLabel = active ? active.label : allLabel;
2108
- const items = [
2109
- { key: "__all__", label: allLabel, selected: value === null, onSelect: () => onChange(null) },
2110
- ...options.map((o) => ({ key: o.key, label: o.label, selected: value === o.key, onSelect: () => onChange(o.key) }))
2111
- ];
2112
- return /* @__PURE__ */ jsx(
2113
- DropdownMenu,
2114
- {
2115
- minWidth: Math.max(minWidth, 160),
2116
- trigger: /* @__PURE__ */ jsx(
2117
- Button,
2118
- {
2119
- size: "$2",
2120
- minW: minWidth,
2121
- justify: "space-between",
2122
- borderWidth: 1,
2123
- borderColor: "$borderColor",
2124
- bg: value !== null ? "$color5" : "transparent",
2125
- icon,
2126
- iconAfter: /* @__PURE__ */ jsx(ChevronDown, { size: 14, opacity: 0.6 }),
2127
- children: /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color12", numberOfLines: 1, flex: 1, children: triggerLabel })
2128
- }
2129
- ),
2130
- items
2131
- }
2132
- );
2133
- }
2134
- var ToastContext = createContext(null);
2135
- var ACCENT3 = {
2136
- success: "$green10",
2137
- error: "$red10",
2138
- info: "$color11"
2139
- };
2140
- var ICON = {
2141
- success: CircleCheck,
2142
- error: CircleX,
2143
- info: Info
2144
- };
2145
- function ToastCard({ t, onClose }) {
2146
- const Icon = ICON[t.kind];
2147
- const accent = ACCENT3[t.kind];
2148
- return /* @__PURE__ */ jsx(
2149
- Card,
2150
- {
2151
- width: 360,
2152
- maxWidth: "90%",
2153
- p: "$3",
2154
- gap: "$2",
2155
- bg: "$color2",
2156
- borderWidth: 1,
2157
- borderColor: "$borderColor",
2158
- borderLeftWidth: 3,
2159
- borderLeftColor: accent,
2160
- rounded: "$4",
2161
- elevation: "$2",
2162
- children: /* @__PURE__ */ jsxs(XStack, { gap: "$2.5", items: "flex-start", children: [
2163
- /* @__PURE__ */ jsx(YStack, { pt: 1, children: /* @__PURE__ */ jsx(Icon, { size: 18, color: accent }) }),
2164
- /* @__PURE__ */ jsxs(YStack, { flex: 1, gap: "$1", children: [
2165
- /* @__PURE__ */ jsx(Text, { fontSize: "$3", fontWeight: "700", color: "$color12", children: t.title }),
2166
- t.description ? /* @__PURE__ */ jsx(Text, { fontSize: "$2", color: "$color11", children: t.description }) : null
2167
- ] }),
2168
- /* @__PURE__ */ jsx(Button, { size: "$1", chromeless: true, icon: /* @__PURE__ */ jsx(X, { size: 14 }), onPress: onClose, "aria-label": "Dismiss" })
2169
- ] })
2170
- }
2171
- );
2172
- }
2173
- function ToastViewport({ toasts, dismiss }) {
2174
- const [mounted, setMounted] = useState(false);
2175
- useEffect(() => setMounted(true), []);
2176
- if (!mounted || typeof document === "undefined") return null;
2177
- return createPortal(
2178
- /* @__PURE__ */ jsx("div", { style: { position: "fixed", top: 16, right: 16, zIndex: 1e5, pointerEvents: "none" }, children: /* @__PURE__ */ jsx(YStack, { gap: "$2", items: "flex-end", children: toasts.map((t) => /* @__PURE__ */ jsx(YStack, { pointerEvents: "auto", children: /* @__PURE__ */ jsx(ToastCard, { t, onClose: () => dismiss(t.id) }) }, t.id)) }) }),
2179
- document.body
2180
- );
2181
- }
2182
- function ToastProvider({ children }) {
2183
- const track = useEmit();
2184
- const [toasts, setToasts] = useState([]);
2185
- const timers = useRef(/* @__PURE__ */ new Map());
2186
- const seq = useRef(0);
2187
- const dismiss = useCallback((id) => {
2188
- setToasts((ts) => ts.filter((t) => t.id !== id));
2189
- const timer = timers.current.get(id);
2190
- if (timer) {
2191
- clearTimeout(timer);
2192
- timers.current.delete(id);
2193
- }
2194
- }, []);
2195
- const toast = useCallback(
2196
- (input) => {
2197
- const id = ++seq.current;
2198
- const kind = input.kind ?? "info";
2199
- const durationMs = input.durationMs ?? (kind === "error" ? 6e3 : 3500);
2200
- track({ component: "Toast", action: kind === "error" ? "error" : "view", id: input.title, value: kind });
2201
- setToasts((ts) => [...ts, { id, kind, title: input.title, description: input.description, durationMs }]);
2202
- if (durationMs > 0) {
2203
- timers.current.set(
2204
- id,
2205
- setTimeout(() => dismiss(id), durationMs)
2206
- );
2207
- }
2208
- },
2209
- [dismiss, track]
2210
- );
2211
- useEffect(() => {
2212
- const map = timers.current;
2213
- return () => map.forEach((t) => clearTimeout(t));
2214
- }, []);
2215
- const api = {
2216
- toast,
2217
- success: (title, description) => toast({ title, description, kind: "success" }),
2218
- error: (title, description) => toast({ title, description, kind: "error" }),
2219
- info: (title, description) => toast({ title, description, kind: "info" }),
2220
- dismiss
2221
- };
2222
- return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: api, children: [
2223
- children,
2224
- /* @__PURE__ */ jsx(ToastViewport, { toasts, dismiss })
2225
- ] });
2226
- }
2227
- function useToast() {
2228
- const ctx = useContext(ToastContext);
2229
- if (!ctx) throw new Error("useToast must be used within <ToastProvider>");
2230
- return ctx;
2231
- }
2232
-
2233
- export { AnimatedLogo, AppHeader, BRANDS, BarChart, BarRows, BrandMark, CHART_OTHER, CHART_PALETTE, ComboBox, CommerceResource, ConfirmDelete, ContextMenu, Donut, Donut2 as DonutRing, DropdownMenu, FadeIn, FloatingMenu, GenericLogo, HANZO, HANZO_MARK_CONTENT, HanzoMark, HintButton, LUX, LegendDot, LineChart, MenuItemView, MenuLabelView, MenuPanel, MenuSeparatorView, MetricCard, Sparkline2 as MetricSparkline, MiniBars, OrgMark, OrgSwitcher, PARS, Panel, PortalTheme, ProductIcon, ProviderLogo, Reorder, SERIES, SURFACES, SearchInput, Segmented, SelectMenu, SiteFooter, SiteNav, Sparkline, ToastProvider, UtilBar, ZOO, colorForIndex, filterOptions, filterOrgs, isKnownOption, monogram, orgScope, otherSurfaces, providerInitials, renderMenuItems, resolveBrand, rowShift, targetIndex, useContainerWidth, useToast, utilColor };
2234
7
  //# sourceMappingURL=index.js.map
2235
8
  //# sourceMappingURL=index.js.map