@luxfi/ui 7.4.0 → 7.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/avatar.cjs +7 -6
  2. package/dist/avatar.js +7 -5
  3. package/dist/badge.cjs +33 -35
  4. package/dist/badge.js +33 -35
  5. package/dist/bank.d.cts +3 -3
  6. package/dist/bank.d.ts +3 -3
  7. package/dist/checkbox.cjs +4 -4
  8. package/dist/checkbox.d.cts +3 -2
  9. package/dist/checkbox.d.ts +3 -2
  10. package/dist/checkbox.js +5 -4
  11. package/dist/chrome.cjs +960 -0
  12. package/dist/chrome.d.cts +93 -0
  13. package/dist/chrome.d.ts +93 -0
  14. package/dist/chrome.js +931 -0
  15. package/dist/drawer.cjs +86 -20
  16. package/dist/drawer.js +85 -19
  17. package/dist/expiration-selector.cjs +3 -2
  18. package/dist/expiration-selector.js +3 -2
  19. package/dist/greeks-display.cjs +6 -6
  20. package/dist/greeks-display.js +6 -6
  21. package/dist/gui.cjs +13 -0
  22. package/dist/gui.d.cts +2 -0
  23. package/dist/gui.d.ts +2 -0
  24. package/dist/gui.js +2 -0
  25. package/dist/heading.cjs +4 -2
  26. package/dist/heading.js +4 -2
  27. package/dist/iam.cjs +216 -0
  28. package/dist/iam.d.cts +65 -0
  29. package/dist/iam.d.ts +65 -0
  30. package/dist/iam.js +211 -0
  31. package/dist/icons.cjs +13 -0
  32. package/dist/icons.d.cts +1 -0
  33. package/dist/icons.d.ts +1 -0
  34. package/dist/icons.js +2 -0
  35. package/dist/identity.cjs +430 -0
  36. package/dist/identity.d.cts +64 -0
  37. package/dist/identity.d.ts +64 -0
  38. package/dist/identity.js +408 -0
  39. package/dist/index.cjs +1610 -836
  40. package/dist/index.d.cts +7 -3
  41. package/dist/index.d.ts +7 -3
  42. package/dist/index.js +1587 -831
  43. package/dist/input.cjs +3 -1
  44. package/dist/input.d.cts +3 -5
  45. package/dist/input.d.ts +3 -5
  46. package/dist/input.js +3 -1
  47. package/dist/lux.config.cjs +23 -2
  48. package/dist/lux.config.d.cts +28 -10
  49. package/dist/lux.config.d.ts +28 -10
  50. package/dist/lux.config.js +23 -2
  51. package/dist/menu.cjs +4 -4
  52. package/dist/menu.js +4 -4
  53. package/dist/next.cjs +132 -0
  54. package/dist/next.d.cts +32 -0
  55. package/dist/next.d.ts +32 -0
  56. package/dist/next.js +129 -0
  57. package/dist/option-chain.cjs +1 -1
  58. package/dist/option-chain.js +1 -1
  59. package/dist/option-position.cjs +2 -1
  60. package/dist/option-position.js +2 -1
  61. package/dist/pnl-diagram.cjs +8 -6
  62. package/dist/pnl-diagram.js +8 -6
  63. package/dist/progress.cjs +7 -6
  64. package/dist/progress.js +7 -5
  65. package/dist/provider.cjs +146 -4
  66. package/dist/provider.d.cts +15 -3
  67. package/dist/provider.d.ts +15 -3
  68. package/dist/provider.js +146 -5
  69. package/dist/radio.cjs +9 -7
  70. package/dist/radio.js +10 -7
  71. package/dist/separator.cjs +3 -1
  72. package/dist/separator.js +3 -1
  73. package/dist/slider.cjs +28 -16
  74. package/dist/slider.js +28 -15
  75. package/dist/strategy-builder.cjs +2 -1
  76. package/dist/strategy-builder.js +2 -1
  77. package/dist/switch.cjs +11 -12
  78. package/dist/switch.js +12 -12
  79. package/dist/tag.cjs +34 -36
  80. package/dist/tag.js +33 -35
  81. package/dist/textarea.cjs +3 -1
  82. package/dist/textarea.js +3 -1
  83. package/dist/tooltip.cjs +28 -30
  84. package/dist/tooltip.js +27 -29
  85. package/dist/use-narrow.cjs +46 -0
  86. package/dist/use-narrow.d.cts +12 -0
  87. package/dist/use-narrow.d.ts +12 -0
  88. package/dist/use-narrow.js +20 -0
  89. package/dist/vite.cjs +109 -0
  90. package/dist/vite.d.cts +29 -0
  91. package/dist/vite.d.ts +29 -0
  92. package/dist/vite.js +107 -0
  93. package/dist/white-label.cjs +142 -0
  94. package/dist/white-label.d.cts +59 -0
  95. package/dist/white-label.d.ts +59 -0
  96. package/dist/white-label.js +134 -0
  97. package/package.json +85 -19
  98. package/src/avatar.tsx +22 -16
  99. package/src/checkbox.tsx +15 -10
  100. package/src/chrome.tsx +459 -0
  101. package/src/drawer.tsx +83 -10
  102. package/src/engine.ts +130 -0
  103. package/src/expiration-selector.tsx +3 -2
  104. package/src/greeks-display.tsx +9 -6
  105. package/src/gui.ts +17 -0
  106. package/src/heading.tsx +12 -8
  107. package/src/iam.ts +170 -0
  108. package/src/icons.ts +18 -0
  109. package/src/identity.tsx +318 -0
  110. package/src/index.ts +44 -1
  111. package/src/input.tsx +13 -9
  112. package/src/lux.config.ts +16 -15
  113. package/src/menu.tsx +4 -4
  114. package/src/next.ts +89 -0
  115. package/src/option-chain.tsx +1 -1
  116. package/src/option-position.tsx +2 -1
  117. package/src/pnl-diagram.tsx +11 -6
  118. package/src/progress.tsx +15 -8
  119. package/src/provider.tsx +48 -7
  120. package/src/radio.tsx +15 -11
  121. package/src/separator.tsx +8 -3
  122. package/src/slider.tsx +35 -19
  123. package/src/strategy-builder.tsx +3 -2
  124. package/src/switch.tsx +17 -16
  125. package/src/textarea.tsx +8 -4
  126. package/src/tooltip.tsx +15 -24
  127. package/src/use-narrow.ts +40 -0
  128. package/src/vite.ts +80 -0
  129. package/src/white-label.ts +254 -0
  130. package/tokens.css +613 -319
  131. package/src/tokens.css +0 -438
@@ -0,0 +1,408 @@
1
+ "use client";
2
+ import * as React2 from 'react';
3
+ import React2__default from 'react';
4
+ import '@hanzo/gui';
5
+ import { QueryClient } from '@tanstack/react-query';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ // src/white-label.ts
9
+ var LUX_BRAND = {
10
+ lux: "#7000FF",
11
+ zoo: "#6C5EFB",
12
+ hanzo: "#EA580C",
13
+ pars: "#1C3879"};
14
+ var PARS_GOLD = "#C8A45C";
15
+ var ORGS = {
16
+ lux: {
17
+ org: "lux",
18
+ name: "Lux",
19
+ domain: "lux.network",
20
+ iamDomain: "lux.id",
21
+ accent: LUX_BRAND.lux,
22
+ accentForeground: "#FFFFFF"
23
+ },
24
+ zoo: {
25
+ org: "zoo",
26
+ name: "Zoo",
27
+ domain: "zoo.ngo",
28
+ // Zoo's issuer is `zoolabs.id` — the one row where it is not `<org>.id`,
29
+ // and the one every hand-rolled branding map gets wrong. `id.zoo.network`
30
+ // ANSWERS, which is why it keeps being copied around, but it is an alias:
31
+ // its own discovery document advertises
32
+ // issuer https://zoolabs.id
33
+ // authorization_endpoint https://zoolabs.id/v1/iam/oauth/authorize
34
+ // jwks_uri https://zoolabs.id/v1/iam/.well-known/jwks
35
+ // so a client configured on the alias validates `iss` against a string the
36
+ // IdP never emits and rejects every token it is given — the exact shape of
37
+ // the lux.id outage. `zoo.id` is not an IdP at all (no discovery document).
38
+ iamDomain: "zoolabs.id",
39
+ accent: LUX_BRAND.zoo,
40
+ accentForeground: "#FFFFFF"
41
+ },
42
+ bootnode: {
43
+ org: "bootnode",
44
+ name: "Bootnode",
45
+ domain: "bootno.de",
46
+ iamDomain: "id.bootno.de",
47
+ accent: LUX_BRAND.lux,
48
+ accentForeground: "#FFFFFF"
49
+ },
50
+ hanzo: {
51
+ org: "hanzo",
52
+ name: "Hanzo",
53
+ domain: "hanzo.ai",
54
+ iamDomain: "hanzo.id",
55
+ accent: LUX_BRAND.hanzo,
56
+ accentForeground: "#FFFFFF"
57
+ },
58
+ pars: {
59
+ org: "pars",
60
+ name: "Pars",
61
+ domain: "pars.id",
62
+ iamDomain: "pars.id",
63
+ accent: LUX_BRAND.pars,
64
+ accentForeground: PARS_GOLD
65
+ }
66
+ };
67
+ var DOMAIN_ORG = [
68
+ ["lux.network", "lux"],
69
+ ["lux.cloud", "lux"],
70
+ ["lux.id", "lux"],
71
+ ["lux.finance", "lux"],
72
+ ["lux.market", "lux"],
73
+ ["lux.exchange", "lux"],
74
+ ["zoo.ngo", "zoo"],
75
+ ["zoo.network", "zoo"],
76
+ ["zoo.cloud", "zoo"],
77
+ ["zoolabs.id", "zoo"],
78
+ ["hanzo.ai", "hanzo"],
79
+ ["hanzo.cloud", "hanzo"],
80
+ ["hanzo.id", "hanzo"],
81
+ ["pars.id", "pars", "app"],
82
+ ["pars.network", "pars", "app"],
83
+ ["parsdao.org", "pars", "app"],
84
+ ["bootno.de", "bootnode", "platform"]
85
+ ];
86
+ var DEFAULT_ORG = "lux";
87
+ function normalizeHost(host) {
88
+ const noPort = host.trim().toLowerCase().split(":")[0] ?? "";
89
+ return noPort.replace(/\.$/, "");
90
+ }
91
+ function isUnder(host, domain) {
92
+ return host === domain || host.endsWith(`.${domain}`);
93
+ }
94
+ function matchDomain(host) {
95
+ let best;
96
+ for (const entry of DOMAIN_ORG) {
97
+ if (isUnder(host, entry[0]) && (!best || entry[0].length > best[0].length)) {
98
+ best = entry;
99
+ }
100
+ }
101
+ return best;
102
+ }
103
+ function appSlug(host, domain, pinned) {
104
+ if (pinned) return pinned;
105
+ const sub = host === domain ? "" : host.slice(0, -(domain.length + 1));
106
+ const leftmost = sub.split(".")[0] ?? "";
107
+ if (leftmost && leftmost !== "www") return leftmost;
108
+ const label = domain.split(".")[0] ?? "";
109
+ const tld = domain.split(".").slice(1).join(".");
110
+ return tld.split(".")[0] || label;
111
+ }
112
+ function isLocal(host) {
113
+ return host === "localhost" || host.endsWith(".localhost") || host === "127.0.0.1" || host === "0.0.0.0" || host === "[::1]" || host.endsWith(".local");
114
+ }
115
+ function resolveWhiteLabel(host) {
116
+ const h = normalizeHost(host ?? "");
117
+ const match = h ? matchDomain(h) : void 0;
118
+ const org = match ? match[1] : DEFAULT_ORG;
119
+ const identity = ORGS[org];
120
+ const app = match ? appSlug(h, match[0], match[2]) : h && isLocal(h) ? "local" : "app";
121
+ return {
122
+ ...identity,
123
+ host: h,
124
+ app,
125
+ theme: `dark_${org}`,
126
+ issuer: `https://${identity.iamDomain}`,
127
+ clientId: `${org}-${app}`
128
+ };
129
+ }
130
+
131
+ // src/iam.ts
132
+ var IamError = class extends Error {
133
+ constructor(message, status, unauthenticated) {
134
+ super(message);
135
+ this.name = "IamError";
136
+ this.status = status;
137
+ this.unauthenticated = unauthenticated;
138
+ }
139
+ };
140
+ var SIGNED_OUT = /please sign in|authentication required|unauthorized/i;
141
+ function isSignedOut(status, msg) {
142
+ return status === 401 || status === 403 || SIGNED_OUT.test(msg);
143
+ }
144
+ function iamBase(host) {
145
+ const wl = typeof host === "object" && host !== null ? host : resolveWhiteLabel(host);
146
+ return `${wl.issuer}/v1/iam`;
147
+ }
148
+ async function read(call, verb, params) {
149
+ const url = new URL(`${call.base}/${verb}`);
150
+ for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
151
+ let res;
152
+ try {
153
+ res = await fetch(url.toString(), {
154
+ method: "GET",
155
+ // The bearer is the whole credential. IAM does not allow credentialed
156
+ // CORS, so sending cookies would only get the response blocked.
157
+ headers: call.token ? { Authorization: `Bearer ${call.token}` } : {},
158
+ signal: call.signal
159
+ });
160
+ } catch (e) {
161
+ throw new IamError(e instanceof Error ? e.message : "IAM unreachable", 0, false);
162
+ }
163
+ const body = await res.json().catch(() => ({}));
164
+ const msg = typeof body.msg === "string" ? body.msg : "";
165
+ if (!res.ok || body.status === "error") {
166
+ throw new IamError(msg || `IAM ${verb} failed (${res.status})`, res.status, isSignedOut(res.status, msg));
167
+ }
168
+ return body.data;
169
+ }
170
+ var IAM_PAGE_SIZE = 20;
171
+ var iam = {
172
+ /** The signed-in principal, or null when there is no session. */
173
+ async account(call) {
174
+ try {
175
+ const data = await read(call, "get-account", {});
176
+ return data && data.name ? data : null;
177
+ } catch (e) {
178
+ if (e instanceof IamError && e.unauthenticated) return null;
179
+ throw e;
180
+ }
181
+ },
182
+ /**
183
+ * One page of the orgs the principal can see. IAM scopes the read to the
184
+ * caller's authority, so a normal member gets their own org and a super
185
+ * admin gets the tenant list — the page never has to decide.
186
+ */
187
+ async organizations(call, page = 0, query = "", pageSize = IAM_PAGE_SIZE) {
188
+ const params = {
189
+ owner: "admin",
190
+ // IAM orgs live under the reserved `admin` owner
191
+ p: page + 1,
192
+ // the backend page is 1-based
193
+ pageSize,
194
+ sortField: "name",
195
+ sortOrder: "ascending"
196
+ };
197
+ const q = query.trim();
198
+ if (q) {
199
+ params.field = "name";
200
+ params.value = q;
201
+ }
202
+ return await read(call, "get-organizations", params) ?? [];
203
+ },
204
+ /** One organization by name. */
205
+ async organization(call, name) {
206
+ return await read(call, "get-organization", { id: `admin/${name}` }) ?? null;
207
+ },
208
+ /** Members of an organization. */
209
+ async users(call, org) {
210
+ return await read(call, "get-users", { owner: org }) ?? [];
211
+ },
212
+ /** The organization's projects — IAM keys this read by `organization`. */
213
+ async projects(call, org) {
214
+ return await read(call, "get-organization-projects", { organization: org }) ?? [];
215
+ }
216
+ };
217
+ new QueryClient({
218
+ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: 1, staleTime: 3e4 } }
219
+ });
220
+ var WhiteLabelContext = React2__default.createContext(resolveWhiteLabel(""));
221
+ var useWhiteLabel = () => React2__default.useContext(WhiteLabelContext);
222
+ var IAM_TOKEN_KEY = "hanzo_iam_access_token";
223
+ function storedToken() {
224
+ if (typeof window === "undefined") return null;
225
+ for (const store of [window.sessionStorage, window.localStorage]) {
226
+ try {
227
+ const t = store.getItem(IAM_TOKEN_KEY);
228
+ if (t) return t;
229
+ } catch {
230
+ }
231
+ }
232
+ return null;
233
+ }
234
+ function clearStoredTokens() {
235
+ if (typeof window === "undefined") return;
236
+ for (const store of [window.sessionStorage, window.localStorage]) {
237
+ try {
238
+ for (const k of ["access_token", "refresh_token", "id_token", "expires_at"]) {
239
+ store.removeItem(`hanzo_iam_${k}`);
240
+ }
241
+ } catch {
242
+ }
243
+ }
244
+ }
245
+ var defaultAuth = {};
246
+ var scopeKey = (host, kind) => `lux-ui:${kind}:${host}`;
247
+ function readScope(host, kind) {
248
+ if (typeof window === "undefined") return null;
249
+ try {
250
+ return window.localStorage.getItem(scopeKey(host, kind));
251
+ } catch {
252
+ return null;
253
+ }
254
+ }
255
+ function writeScope(host, kind, value) {
256
+ if (typeof window === "undefined") return;
257
+ try {
258
+ window.localStorage.setItem(scopeKey(host, kind), value);
259
+ } catch {
260
+ }
261
+ }
262
+ var IdentityContext = React2.createContext(null);
263
+ var IdentityProvider = ({
264
+ children,
265
+ auth = defaultAuth,
266
+ loginPath = "/login"
267
+ }) => {
268
+ const whiteLabel = useWhiteLabel();
269
+ const base = React2.useMemo(() => iamBase(whiteLabel), [whiteLabel]);
270
+ const [status, setStatus] = React2.useState("loading");
271
+ const [account, setAccount] = React2.useState(null);
272
+ const [orgs, setOrgs] = React2.useState([]);
273
+ const [projects, setProjects] = React2.useState([]);
274
+ const [error, setError] = React2.useState(null);
275
+ const [orgName, setOrgName] = React2.useState(null);
276
+ const [projectName, setProjectName] = React2.useState(null);
277
+ const [epoch, setEpoch] = React2.useState(0);
278
+ React2.useEffect(() => {
279
+ const ac = new AbortController();
280
+ let live = true;
281
+ void (async () => {
282
+ const token = await (auth.token ?? storedToken)();
283
+ if (!live) return;
284
+ if (!token) {
285
+ setStatus("anonymous");
286
+ setAccount(null);
287
+ setOrgs([]);
288
+ return;
289
+ }
290
+ const call = { base, token, signal: ac.signal };
291
+ try {
292
+ const me = await iam.account(call);
293
+ if (!live) return;
294
+ if (!me) {
295
+ setStatus("anonymous");
296
+ setAccount(null);
297
+ setOrgs([]);
298
+ return;
299
+ }
300
+ setAccount(me);
301
+ const rows = await iam.organizations(call).catch((e) => {
302
+ if (e instanceof IamError && !e.unauthenticated) return [{ owner: "admin", name: me.owner }];
303
+ throw e;
304
+ });
305
+ if (!live) return;
306
+ setOrgs(rows);
307
+ setStatus("ready");
308
+ setError(null);
309
+ } catch (e) {
310
+ if (!live || ac.signal.aborted) return;
311
+ if (e instanceof IamError && e.unauthenticated) {
312
+ setStatus("anonymous");
313
+ setAccount(null);
314
+ setOrgs([]);
315
+ return;
316
+ }
317
+ setStatus("error");
318
+ setError(e instanceof Error ? e.message : "Could not reach IAM.");
319
+ }
320
+ })();
321
+ return () => {
322
+ live = false;
323
+ ac.abort();
324
+ };
325
+ }, [base, auth, epoch]);
326
+ const org = React2.useMemo(() => {
327
+ if (orgs.length === 0) return null;
328
+ const saved = orgName ?? readScope(whiteLabel.host, "org");
329
+ return orgs.find((o) => o.name === saved) ?? orgs.find((o) => o.name === account?.owner) ?? orgs[0];
330
+ }, [orgs, orgName, account, whiteLabel.host]);
331
+ React2.useEffect(() => {
332
+ if (!org) {
333
+ setProjects([]);
334
+ return;
335
+ }
336
+ const ac = new AbortController();
337
+ let live = true;
338
+ void (async () => {
339
+ const token = await (auth.token ?? storedToken)();
340
+ if (!live || !token) return;
341
+ const rows = await iam.projects({ base, token, signal: ac.signal }, org.name).catch(() => []);
342
+ if (live) setProjects(rows);
343
+ })();
344
+ return () => {
345
+ live = false;
346
+ ac.abort();
347
+ };
348
+ }, [base, auth, org, epoch]);
349
+ const project = React2.useMemo(() => {
350
+ if (projects.length === 0) return null;
351
+ const saved = projectName ?? readScope(whiteLabel.host, "project");
352
+ return projects.find((p) => p.name === saved) ?? projects.find((p) => p.isDefault) ?? projects[0];
353
+ }, [projects, projectName, whiteLabel.host]);
354
+ const value = React2.useMemo(() => ({
355
+ status,
356
+ account,
357
+ orgs,
358
+ org,
359
+ projects,
360
+ project,
361
+ error,
362
+ whiteLabel,
363
+ setOrg: (name) => {
364
+ writeScope(whiteLabel.host, "org", name);
365
+ setOrgName(name);
366
+ setProjectName(null);
367
+ },
368
+ setProject: (name) => {
369
+ writeScope(whiteLabel.host, "project", name);
370
+ setProjectName(name);
371
+ },
372
+ signIn: () => {
373
+ if (auth.signIn) return auth.signIn();
374
+ if (typeof window !== "undefined") window.location.assign(loginPath);
375
+ },
376
+ signOut: () => {
377
+ if (auth.signOut) return auth.signOut();
378
+ clearStoredTokens();
379
+ if (typeof window !== "undefined") window.location.assign(loginPath);
380
+ },
381
+ reload: () => setEpoch((n) => n + 1)
382
+ }), [status, account, orgs, org, projects, project, error, whiteLabel, auth, loginPath]);
383
+ return /* @__PURE__ */ jsx(IdentityContext.Provider, { value, children });
384
+ };
385
+ function useIdentity() {
386
+ const ctx = React2.useContext(IdentityContext);
387
+ const whiteLabel = useWhiteLabel();
388
+ const fallback = React2.useMemo(() => ({
389
+ status: "anonymous",
390
+ account: null,
391
+ orgs: [],
392
+ org: null,
393
+ projects: [],
394
+ project: null,
395
+ error: null,
396
+ whiteLabel,
397
+ setOrg: () => void 0,
398
+ setProject: () => void 0,
399
+ signIn: () => {
400
+ if (typeof window !== "undefined") window.location.assign("/login");
401
+ },
402
+ signOut: () => void 0,
403
+ reload: () => void 0
404
+ }), [whiteLabel]);
405
+ return ctx ?? fallback;
406
+ }
407
+
408
+ export { IdentityProvider, useIdentity };