basalt-ui 2.17.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/MIGRATING.md +44 -12
  3. package/agent/skills/basalt-design/SKILL.md +1 -1
  4. package/dist/cli/help.d.ts +1 -0
  5. package/dist/cli/help.d.ts.map +1 -1
  6. package/dist/cli/help.js +8 -2
  7. package/dist/cli/shot/capture.d.ts +12 -1
  8. package/dist/cli/shot/capture.d.ts.map +1 -1
  9. package/dist/cli/shot/capture.js +72 -10
  10. package/dist/cli/shot/index.d.ts +10 -1
  11. package/dist/cli/shot/index.d.ts.map +1 -1
  12. package/dist/cli/shot/index.js +40 -5
  13. package/dist/cli/shot/real-data.d.ts +35 -0
  14. package/dist/cli/shot/real-data.d.ts.map +1 -0
  15. package/dist/cli/shot/real-data.js +120 -0
  16. package/dist/cli/shot/serve.d.ts +2 -2
  17. package/dist/cli/shot/serve.d.ts.map +1 -1
  18. package/dist/cli/shot/serve.js +16 -2
  19. package/dist/dashboard/bar-list.d.ts +29 -0
  20. package/dist/dashboard/bar-list.d.ts.map +1 -0
  21. package/dist/dashboard/bar-list.js +52 -0
  22. package/dist/dashboard/bar-list.module.css +73 -0
  23. package/dist/dashboard/bar-list.module.css.d.ts +16 -0
  24. package/dist/dashboard/index.d.ts +2 -0
  25. package/dist/dashboard/index.d.ts.map +1 -1
  26. package/dist/dashboard/index.js +4 -0
  27. package/dist/dashboard/meter-model.d.ts +78 -0
  28. package/dist/dashboard/meter-model.d.ts.map +1 -0
  29. package/dist/dashboard/meter-model.js +91 -0
  30. package/dist/dashboard/meter-parts.d.ts +42 -0
  31. package/dist/dashboard/meter-parts.d.ts.map +1 -0
  32. package/dist/dashboard/meter-parts.js +163 -0
  33. package/dist/dashboard/meter.d.ts +112 -0
  34. package/dist/dashboard/meter.d.ts.map +1 -0
  35. package/dist/dashboard/meter.js +43 -0
  36. package/dist/dashboard/meter.module.css +150 -0
  37. package/dist/dashboard/meter.module.css.d.ts +28 -0
  38. package/dist/dashboard/scale.d.ts +9 -0
  39. package/dist/dashboard/scale.d.ts.map +1 -0
  40. package/dist/dashboard/scale.js +10 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +5 -1
  44. package/dist/tokens/derive.d.ts +11 -1
  45. package/dist/tokens/derive.d.ts.map +1 -1
  46. package/dist/tokens/derive.js +9 -24
  47. package/dist/tokens/status-text.d.ts +26 -0
  48. package/dist/tokens/status-text.d.ts.map +1 -0
  49. package/dist/tokens/status-text.js +68 -0
  50. package/llms.txt +32 -3
  51. package/package.json +1 -1
  52. package/src/cli/help.ts +22 -2
  53. package/src/cli/shot/capture.ts +98 -9
  54. package/src/cli/shot/index.ts +50 -4
  55. package/src/cli/shot/real-data.ts +165 -0
  56. package/src/cli/shot/serve.ts +28 -3
  57. package/src/dashboard/bar-list.module.css +73 -0
  58. package/src/dashboard/bar-list.module.css.d.ts +16 -0
  59. package/src/dashboard/bar-list.tsx +112 -0
  60. package/src/dashboard/index.ts +2 -0
  61. package/src/dashboard/meter-model.ts +161 -0
  62. package/src/dashboard/meter-parts.tsx +223 -0
  63. package/src/dashboard/meter.module.css +150 -0
  64. package/src/dashboard/meter.module.css.d.ts +28 -0
  65. package/src/dashboard/meter.tsx +162 -0
  66. package/src/dashboard/scale.ts +13 -0
  67. package/src/index.ts +4 -0
  68. package/src/tokens/derive.ts +19 -31
  69. package/src/tokens/status-text.ts +85 -0
@@ -0,0 +1,120 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { ShotError } from "./playwright.js";
4
+ function splitPair(flag, raw) {
5
+ const at = raw.indexOf("=");
6
+ if (at <= 0) throw new ShotError(`--${flag} expects <name>=<value>`);
7
+ return [raw.slice(0, at), raw.slice(at + 1)];
8
+ }
9
+ function resolveValue(flag, raw, src) {
10
+ const [, kind, ref = ""] = /^@(env|file):(.*)$/s.exec(raw) ?? [];
11
+ let value;
12
+ if (kind === "env") value = Object.hasOwn(src.env, ref) ? src.env[ref] : void 0;
13
+ else if (kind === "file") {
14
+ try {
15
+ value = readFileSync(resolve(src.cwd, ref), "utf8").trim();
16
+ } catch {
17
+ throw new ShotError(`--${flag}: cannot read @file:${ref}`);
18
+ }
19
+ } else throw new ShotError(`--${flag} takes @env:NAME or @file:path, never a literal`);
20
+ if (!value) throw new ShotError(`--${flag}: ${raw} is empty`);
21
+ return value;
22
+ }
23
+ const parseStorage = (list, src) => list.map((raw) => {
24
+ const [key, value] = splitPair("local-storage", raw);
25
+ return [key, resolveValue("local-storage", value, src)];
26
+ });
27
+ const NOT_FORWARDED = /* @__PURE__ */ new Set(["host", "origin", "referer", "connection", "content-length"]);
28
+ const HEADER_NAME = /^[!#$%&'*+.^_`|~\w-]+$/;
29
+ const HEADER_VALUE = /^[\t\x20-\x7e]*$/;
30
+ const parseHeaders = (list, src) => list.map((raw) => {
31
+ const [name, value] = splitPair("header", raw);
32
+ if (!HEADER_NAME.test(name) || NOT_FORWARDED.has(name.toLowerCase()))
33
+ throw new ShotError(`--header ${name}: not a header shot can send`);
34
+ const resolved = resolveValue("header", value, src);
35
+ if (!HEADER_VALUE.test(resolved))
36
+ throw new ShotError(`--header ${name}: value has characters a header cannot carry`);
37
+ return [name, resolved];
38
+ });
39
+ const LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "[::1]"]);
40
+ function parseApi(list, secrets) {
41
+ return list.map((raw) => {
42
+ const [given, target] = splitPair("api", raw);
43
+ const prefix = given.replace(/\/+$/, "");
44
+ if (!prefix.startsWith("/"))
45
+ throw new ShotError('--api prefix must start with "/" and name a path, not "/"');
46
+ let url;
47
+ try {
48
+ url = new URL(target ?? "");
49
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("protocol");
50
+ } catch {
51
+ throw new ShotError("--api <prefix>=<origin>: origin must be an http(s) URL");
52
+ }
53
+ if (secrets && url.protocol !== "https:" && !LOOPBACK.has(url.hostname))
54
+ throw new ShotError(
55
+ `--api ${prefix}: with a secret configured (--header, --local-storage) the origin must be https (loopback excepted)`
56
+ );
57
+ return { prefix, origin: url.origin };
58
+ });
59
+ }
60
+ const NOT_RETURNED = ["content-encoding", "content-length", "transfer-encoding"];
61
+ const READ_ONLY = /* @__PURE__ */ new Set(["GET", "HEAD"]);
62
+ const UNTRUSTED = (status) => status >= 500 || status >= 300 && status < 400 || status === 401 || status === 403 || status === 404;
63
+ const TIMEOUT_MS = 2e4;
64
+ function apiProxy(api, headers, opts) {
65
+ let problems = [];
66
+ const handle = async (req) => {
67
+ const url = new URL(req.url);
68
+ const route = api.find(
69
+ (r) => url.pathname === r.prefix || url.pathname.startsWith(r.prefix + "/")
70
+ );
71
+ if (!route) return null;
72
+ const depth = url.pathname.slice(route.prefix.length).split("/").filter(Boolean).length;
73
+ const label = `${req.method} ${route.prefix} +${depth}`;
74
+ if (!opts.allowWrites && !READ_ONLY.has(req.method)) {
75
+ opts.log(`[shot] api ${label} blocked: read-only run (--api-allow-writes lifts it)`);
76
+ return new Response("read-only", { status: 405 });
77
+ }
78
+ const out = new Headers();
79
+ for (const [name, value] of req.headers) if (!NOT_FORWARDED.has(name)) out.set(name, value);
80
+ const navigating = req.headers.get("sec-fetch-mode") === "navigate" || req.headers.get("sec-fetch-dest") === "document";
81
+ if (!navigating) for (const [name, value] of headers) out.set(name, value);
82
+ try {
83
+ const res = await fetch(route.origin + url.pathname + url.search, {
84
+ method: req.method,
85
+ headers: out,
86
+ redirect: "manual",
87
+ signal: AbortSignal.timeout(opts.timeoutMs ?? TIMEOUT_MS),
88
+ ...READ_ONLY.has(req.method) ? {} : { body: await req.arrayBuffer() }
89
+ });
90
+ if (!res.ok) opts.log(`[shot] api ${label} \u2192 ${res.status}`);
91
+ if (UNTRUSTED(res.status)) problems.push(`${label} ${res.status}`);
92
+ const back = new Headers(res.headers);
93
+ for (const name of NOT_RETURNED) back.delete(name);
94
+ return new Response(res.body, { status: res.status, headers: back });
95
+ } catch (error) {
96
+ const kind = error instanceof Error ? error.name : "Error";
97
+ opts.log(`[shot] api ${label} failed: ${kind}`);
98
+ problems.push(`${label} ${kind}`);
99
+ return new Response("proxy error", { status: 502 });
100
+ }
101
+ };
102
+ return {
103
+ handle,
104
+ drain: () => {
105
+ const seen = problems;
106
+ problems = [];
107
+ return seen;
108
+ }
109
+ };
110
+ }
111
+ const SEED_FLAG = "__shotSeedFailed";
112
+ const seedScript = (entries, origin) => `(()=>{if(location.origin!==${JSON.stringify(origin)}){globalThis.${SEED_FLAG}='origin';return}const f=[];for(const [k,v] of ${JSON.stringify(entries)}){try{if(localStorage.getItem(k)===null)localStorage.setItem(k,v)}catch{f.push(k)}}if(f.length)globalThis.${SEED_FLAG}=f.join(',')})()`;
113
+ export {
114
+ SEED_FLAG,
115
+ apiProxy,
116
+ parseApi,
117
+ parseHeaders,
118
+ parseStorage,
119
+ seedScript
120
+ };
@@ -1,5 +1,5 @@
1
- /** Static server for a built SPA dir: real files as-is, extensionless misses fall back to index.html. */
2
- export declare function serveDist(distDir: string): {
1
+ /** Static server for a built SPA dir: real files as-is, extensionless misses fall back to index.html; `proxy` answers first. */
2
+ export declare function serveDist(distDir: string, proxy?: (req: Request) => Promise<Response | null>): {
3
3
  origin: string;
4
4
  stop: () => void;
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/cli/shot/serve.ts"],"names":[],"mappings":"AAKA,yGAAyG;AACzG,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CA4B/E"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/cli/shot/serve.ts"],"names":[],"mappings":"AAsBA,gIAAgI;AAChI,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GACjD;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAiCtC"}
@@ -1,7 +1,17 @@
1
1
  import { existsSync, statSync } from "node:fs";
2
2
  import { join, normalize, resolve, sep } from "node:path";
3
3
  import { ShotError } from "./playwright.js";
4
- function serveDist(distDir) {
4
+ const FETCH_MODES = /* @__PURE__ */ new Set(["cors", "same-origin", "navigate"]);
5
+ function fromOwnBrowser(req, own) {
6
+ const origin = req.headers.get("origin");
7
+ const mode = req.headers.get("sec-fetch-mode");
8
+ const site = req.headers.get("sec-fetch-site");
9
+ if (req.headers.get("host") !== own) return false;
10
+ if (origin !== null) return origin === `http://${own}`;
11
+ if (site === "cross-site") return false;
12
+ return mode === null || FETCH_MODES.has(mode) || site === "same-origin";
13
+ }
14
+ function serveDist(distDir, proxy) {
5
15
  const root = resolve(distDir);
6
16
  if (!existsSync(root) || !statSync(root).isDirectory()) {
7
17
  throw new ShotError(`--dist ${distDir} is not a directory`);
@@ -17,8 +27,12 @@ function serveDist(distDir) {
17
27
  const server = Bun.serve({
18
28
  port: 0,
19
29
  hostname: "127.0.0.1",
20
- fetch(req) {
30
+ async fetch(req) {
21
31
  try {
32
+ const own = `127.0.0.1:${server.port}`;
33
+ if (proxy && !fromOwnBrowser(req, own)) return new Response("forbidden", { status: 403 });
34
+ const proxied = await proxy?.(req);
35
+ if (proxied) return proxied;
22
36
  const file = fileFor(new URL(req.url).pathname);
23
37
  return file ? new Response(Bun.file(file), { headers: { "cache-control": "no-store" } }) : new Response("not found", { status: 404 });
24
38
  } catch {
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { BasaltProps } from '../common/props.js';
3
+ type BarListItem = {
4
+ label: string;
5
+ value: number;
6
+ secondary?: ReactNode;
7
+ key?: string;
8
+ };
9
+ export type BarListProps = BasaltProps & {
10
+ /** Accessible name of the list. Required. */
11
+ label: string;
12
+ /** Rows in display order (sort them yourself; the list does not reorder). */
13
+ items: readonly BarListItem[];
14
+ /** Formats each value. Default: the number as written. */
15
+ format?: (value: number) => string;
16
+ /** Scale end shared by every bar. Default: the largest value. */
17
+ max?: number;
18
+ /** The first row's bar takes the accent. Off by default. */
19
+ accentLeader?: boolean;
20
+ /** Renders row-shaped skeletons. */
21
+ loading?: boolean;
22
+ /** Skeleton rows while loading. Default 5. */
23
+ loadingRows?: number;
24
+ /** Muted line shown when `items` is empty. */
25
+ emptyText?: string;
26
+ };
27
+ export declare function BarList({ label, items, format, max, accentLeader, loading, loadingRows, emptyText, className, style, }: BarListProps): import("react").JSX.Element;
28
+ export {};
29
+ //# sourceMappingURL=bar-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-list.d.ts","sourceRoot":"","sources":["../../src/dashboard/bar-list.tsx"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAIlD,KAAK,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAExF,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb,6EAA6E;IAC7E,KAAK,EAAE,SAAS,WAAW,EAAE,CAAA;IAC7B,0DAA0D;IAC1D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,KAAK,EACL,MAAe,EACf,GAAG,EACH,YAAoB,EACpB,OAAe,EACf,WAAe,EACf,SAAqB,EACrB,SAAS,EACT,KAAK,GACN,EAAE,YAAY,+BAkDd"}
@@ -0,0 +1,52 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Skeleton, VisuallyHidden } from "@mantine/core";
3
+ import { cx } from "../common/props.js";
4
+ import classes from "./bar-list.module.css";
5
+ import { asText, barPercent } from "./scale.js";
6
+ function BarList({
7
+ label,
8
+ items,
9
+ format = asText,
10
+ max,
11
+ accentLeader = false,
12
+ loading = false,
13
+ loadingRows = 5,
14
+ emptyText = "No data",
15
+ className,
16
+ style
17
+ }) {
18
+ if (loading) {
19
+ return /* @__PURE__ */ jsxs("div", { className: cx(classes.root, className), style, "aria-busy": "true", children: [
20
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${label}` }),
21
+ Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRow, "data-bar-skeleton": true }, i))
22
+ ] });
23
+ }
24
+ if (items.length === 0) {
25
+ return /* @__PURE__ */ jsx("output", { className: cx(classes.root, className), style, "aria-label": label, children: /* @__PURE__ */ jsx("span", { className: classes.empty, children: emptyText }) });
26
+ }
27
+ const scale = max ?? items.reduce((top, i) => Number.isFinite(i.value) ? Math.max(top, i.value) : top, 0);
28
+ return (
29
+ // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
30
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
31
+ /* @__PURE__ */ jsx("ul", { className: cx(classes.root, className), style, role: "list", "aria-label": label, children: items.map((item, i) => {
32
+ const isLeader = accentLeader && i === 0;
33
+ return /* @__PURE__ */ jsxs("li", { className: classes.row, children: [
34
+ /* @__PURE__ */ jsx(
35
+ "span",
36
+ {
37
+ className: cx(classes.bar, isLeader && classes.leader),
38
+ style: { width: `${barPercent(item.value, scale)}%` },
39
+ "data-bar-leader": isLeader ? "" : void 0,
40
+ "aria-hidden": true
41
+ }
42
+ ),
43
+ /* @__PURE__ */ jsx("span", { className: classes.label, title: item.label, children: item.label }),
44
+ /* @__PURE__ */ jsx("span", { className: classes.value, children: Number.isFinite(item.value) ? format(item.value) : "\u2014" }),
45
+ item.secondary !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.secondary, children: item.secondary })
46
+ ] }, item.key ?? `${item.label}-${i}`);
47
+ }) })
48
+ );
49
+ }
50
+ export {
51
+ BarList
52
+ };
@@ -0,0 +1,73 @@
1
+ /*
2
+ * BarList — ranked rows on one shared scale (docs/waves/design-parity/SPEC.md § 6.4). The bar sits
3
+ * BEHIND the label and value; the row never wraps: the label truncates, the value is nowrap.
4
+ */
5
+
6
+ .root {
7
+ display: flex;
8
+ flex-direction: column;
9
+ gap: var(--vx-space-stack-xs, 0.25rem);
10
+ margin: 0;
11
+ padding: 0;
12
+ list-style: none;
13
+ min-width: 0;
14
+ }
15
+
16
+ .row {
17
+ position: relative;
18
+ display: flex;
19
+ align-items: center;
20
+ gap: var(--vx-space-control-gap, 0.375rem);
21
+ min-width: 0;
22
+ min-height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
23
+ padding-inline: var(--vx-space-stack-sm);
24
+ font-size: var(--vx-text-sm);
25
+ color: var(--vx-ink);
26
+ }
27
+
28
+ .bar {
29
+ position: absolute;
30
+ inset-block: 0;
31
+ inset-inline-start: 0;
32
+ border-radius: var(--vx-radius-fine);
33
+ background: color-mix(in srgb, var(--vx-line) 30%, transparent);
34
+ }
35
+
36
+ .leader {
37
+ background: color-mix(in srgb, var(--vx-accent) 28%, transparent);
38
+ }
39
+
40
+ .label {
41
+ position: relative;
42
+ flex: 1 1 0;
43
+ min-width: 0;
44
+ overflow: hidden;
45
+ text-overflow: ellipsis;
46
+ white-space: nowrap;
47
+ }
48
+
49
+ .value {
50
+ position: relative;
51
+ flex: none;
52
+ font-family: var(--basalt-font-mono);
53
+ text-align: end;
54
+ white-space: nowrap;
55
+ }
56
+
57
+ .secondary {
58
+ position: relative;
59
+ flex: none;
60
+ font-family: var(--basalt-font-mono);
61
+ font-size: var(--vx-text-xs);
62
+ color: var(--vx-muted);
63
+ white-space: nowrap;
64
+ }
65
+
66
+ .empty {
67
+ font-size: var(--vx-text-sm);
68
+ color: var(--vx-muted);
69
+ }
70
+
71
+ .skeletonRow {
72
+ height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
73
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly root: string
7
+ readonly row: string
8
+ readonly bar: string
9
+ readonly leader: string
10
+ readonly label: string
11
+ readonly value: string
12
+ readonly secondary: string
13
+ readonly empty: string
14
+ readonly skeletonRow: string
15
+ }
16
+ export default classes
@@ -5,4 +5,6 @@ export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize } from
5
5
  export { StatGroup } from './stat-group.js';
6
6
  export { EmptyState } from './empty-state.js';
7
7
  export { SettingsSection, SettingsRow, DangerZone } from './settings-section.js';
8
+ export { Meter, type MeterProps } from './meter.js';
9
+ export { BarList, type BarListProps } from './bar-list.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA"}
@@ -5,10 +5,14 @@ import { StatCard } from "./stat-card.js";
5
5
  import { StatGroup } from "./stat-group.js";
6
6
  import { EmptyState } from "./empty-state.js";
7
7
  import { SettingsSection, SettingsRow, DangerZone } from "./settings-section.js";
8
+ import { Meter } from "./meter.js";
9
+ import { BarList } from "./bar-list.js";
8
10
  export {
11
+ BarList,
9
12
  DangerZone,
10
13
  DeltaBadge,
11
14
  EmptyState,
15
+ Meter,
12
16
  Section,
13
17
  SettingsRow,
14
18
  SettingsSection,
@@ -0,0 +1,78 @@
1
+ export type MeterSegment = {
2
+ value: number;
3
+ label: string;
4
+ color?: string;
5
+ forecast?: boolean;
6
+ };
7
+ export type MeterZone = {
8
+ from: number;
9
+ to: number;
10
+ label: string;
11
+ color?: string;
12
+ };
13
+ /** A fill on the track, as fractions (0–1) of the span. */
14
+ export type Part = {
15
+ readonly start: number;
16
+ readonly size: number;
17
+ readonly color: string | undefined;
18
+ readonly forecast: boolean;
19
+ };
20
+ type Format = (value: number) => string;
21
+ export declare const isReading: (n: number | null | undefined) => n is number;
22
+ /** The track's span. A track that ends at or before its start falls back to 1 and is `valid: false`. */
23
+ export declare function spanOf(min: number, max: number): {
24
+ span: number;
25
+ valid: boolean;
26
+ };
27
+ export declare function ariaValues(reading: number, min: number, max: number, format: Format): {
28
+ readonly role: "meter";
29
+ readonly 'aria-valuenow': number;
30
+ readonly 'aria-valuemin': number;
31
+ readonly 'aria-valuemax': number;
32
+ readonly 'aria-valuetext': string;
33
+ };
34
+ /**
35
+ * The ONE place segment amounts are sanitised: a negative or non-finite amount is 0. The painted
36
+ * track, the captions and `aria-valuenow` all derive from what this returns.
37
+ */
38
+ export declare function normalizeSegments(segments: readonly MeterSegment[]): MeterSegment[];
39
+ /** Segment amounts (already normalised) accumulate from `min`; a part never passes the track end. */
40
+ export declare function layoutSegments(segments: readonly MeterSegment[], span: number): Part[];
41
+ /** `from` is inclusive; a value on the last band's `to` belongs to that band. */
42
+ export declare function findHoldingZone(zones: readonly MeterZone[], value: number): MeterZone | undefined;
43
+ /** A zone band as left edge + width in percent, clipped to the track. */
44
+ export declare function zoneBand(zone: MeterZone, min: number, span: number): {
45
+ start: number;
46
+ width: number;
47
+ };
48
+ export type BarInput = {
49
+ reading: number;
50
+ min: number;
51
+ max: number;
52
+ format: Format;
53
+ segments?: readonly MeterSegment[] | undefined;
54
+ zones?: readonly MeterZone[] | undefined;
55
+ target?: number | undefined;
56
+ color?: string | undefined;
57
+ forecastCaption?: string | undefined;
58
+ };
59
+ export type BarModel = {
60
+ span: number;
61
+ /** Fills, or none when the track is drawn as zones. */
62
+ parts: readonly Part[];
63
+ /** Percent where the first forecast part starts; absent when the forecast opens the track. */
64
+ boundaryPct: number | undefined;
65
+ forecastText: string | null;
66
+ markerPct: number | undefined;
67
+ targetPct: number | undefined;
68
+ startText: string;
69
+ endText: string | null;
70
+ describedByText: string | null;
71
+ };
72
+ /** Segments are amounts accumulated from `min`, so the reading is `min` plus their sum. */
73
+ export declare const segmentReading: (segments: readonly MeterSegment[], min: number) => number;
74
+ export declare function modelBar(input: BarInput): BarModel;
75
+ /** The ring's one arc, as a fraction of the circumference. */
76
+ export declare const ringFraction: (reading: number, min: number, max: number) => number;
77
+ export {};
78
+ //# sourceMappingURL=meter-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter-model.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-model.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAC/F,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnF,2DAA2D;AAC3D,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAEvC,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,CAAC,IAAI,MACjB,CAAA;AAE7C,wGAAwG;AACxG,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAEjF;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;EAQnF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,YAAY,EAAE,CAEnF;AAED,qGAAqG;AACrG,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,CAUtF;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAGjG;AAED,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;EAIlE;AAKD,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;IAC9C,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAA;IACxC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IACtB,8FAA8F;IAC9F,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,CAAA;AAeD,2FAA2F;AAC3F,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,YAAY,EAAE,EAAE,KAAK,MAAM,KAAG,MAC/B,CAAA;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAuClD;AAED,8DAA8D;AAC9D,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MACvB,CAAA"}
@@ -0,0 +1,91 @@
1
+ import { clamp01, toPct } from "./scale.js";
2
+ const isReading = (n) => typeof n === "number" && Number.isFinite(n);
3
+ function spanOf(min, max) {
4
+ return max > min ? { span: max - min, valid: true } : { span: 1, valid: false };
5
+ }
6
+ function ariaValues(reading, min, max, format) {
7
+ return {
8
+ role: "meter",
9
+ "aria-valuenow": Math.min(max, Math.max(min, reading)),
10
+ "aria-valuemin": min,
11
+ "aria-valuemax": max,
12
+ "aria-valuetext": format(reading)
13
+ };
14
+ }
15
+ function normalizeSegments(segments) {
16
+ return segments.map((s) => ({ ...s, value: Number.isFinite(s.value) ? Math.max(0, s.value) : 0 }));
17
+ }
18
+ function layoutSegments(segments, span) {
19
+ let cursor = 0;
20
+ return segments.map((s) => {
21
+ const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor));
22
+ const forecast = s.forecast === true;
23
+ const part = { start: cursor, size, color: forecast ? void 0 : s.color, forecast };
24
+ cursor += size;
25
+ return part;
26
+ });
27
+ }
28
+ function findHoldingZone(zones, value) {
29
+ const end = Math.max(...zones.map((z) => z.to));
30
+ return zones.find((z) => value >= z.from && (value < z.to || value === z.to && z.to === end));
31
+ }
32
+ function zoneBand(zone, min, span) {
33
+ const lo = clamp01((zone.from - min) / span);
34
+ const hi = clamp01((zone.to - min) / span);
35
+ return { start: toPct(lo), width: toPct(hi - lo) };
36
+ }
37
+ const segmentText = (s, format) => `${s.label} ${format(s.value)}${s.forecast === true ? " (forecast)" : ""}`;
38
+ function endCaptionText(reading, target, format) {
39
+ if (target === void 0) return null;
40
+ if (reading > target) return `Target ${format(target)} \xB7 ${format(reading - target)} over`;
41
+ return `Target ${format(target)}`;
42
+ }
43
+ function fillParts(input, span, zoned) {
44
+ if (zoned) return [];
45
+ if (input.segments !== void 0) return layoutSegments(input.segments, span);
46
+ const fill = { value: input.reading - input.min, label: "" };
47
+ return layoutSegments([input.color === void 0 ? fill : { ...fill, color: input.color }], span);
48
+ }
49
+ const segmentReading = (segments, min) => segments.reduce((sum, s) => sum + s.value, min);
50
+ function modelBar(input) {
51
+ const { reading, min, max, format, segments, zones, target } = input;
52
+ const { span } = spanOf(min, max);
53
+ const zoned = zones !== void 0 && zones.length > 0;
54
+ const holding = zoned ? findHoldingZone(zones, reading) : void 0;
55
+ const parts = fillParts(input, span, zoned);
56
+ const firstForecast = parts.findIndex((p) => p.forecast);
57
+ const forecastLabels = segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? [];
58
+ const zoneText = !zoned ? [] : [
59
+ ...zones.map((z) => `${z.label} ${format(z.from)} to ${format(z.to)}`),
60
+ holding === void 0 ? `${format(reading)} is outside every zone` : `${format(reading)} is in ${holding.label}`
61
+ ];
62
+ const describedBy = [
63
+ ...segments?.map((s) => segmentText(s, format)) ?? [],
64
+ ...zoneText,
65
+ ...target === void 0 ? [] : [`Target ${format(target)}`]
66
+ ];
67
+ return {
68
+ span,
69
+ parts,
70
+ boundaryPct: firstForecast > 0 ? toPct(parts[firstForecast]?.start ?? 0) : void 0,
71
+ forecastText: forecastLabels.length === 0 ? null : input.forecastCaption ?? `Forecast: ${forecastLabels.join(", ")}`,
72
+ markerPct: zoned ? toPct((reading - min) / span) : void 0,
73
+ targetPct: target === void 0 ? void 0 : toPct((target - min) / span),
74
+ startText: holding === void 0 ? format(reading) : `${holding.label} \xB7 ${format(reading)}`,
75
+ endText: endCaptionText(reading, target, format),
76
+ describedByText: describedBy.length > 0 ? describedBy.join("; ") : null
77
+ };
78
+ }
79
+ const ringFraction = (reading, min, max) => clamp01((reading - min) / spanOf(min, max).span);
80
+ export {
81
+ ariaValues,
82
+ findHoldingZone,
83
+ isReading,
84
+ layoutSegments,
85
+ modelBar,
86
+ normalizeSegments,
87
+ ringFraction,
88
+ segmentReading,
89
+ spanOf,
90
+ zoneBand
91
+ };
@@ -0,0 +1,42 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ import type { MeterSegment, MeterZone } from './meter-model.js';
3
+ export type Shell = {
4
+ className: string | undefined;
5
+ style: CSSProperties | undefined;
6
+ };
7
+ export declare function MeterLoading({ label, ring, shell, }: {
8
+ label: string;
9
+ ring: boolean;
10
+ shell: Shell;
11
+ }): import("react").JSX.Element;
12
+ export declare function MeterEmpty(props: {
13
+ label: string;
14
+ text: string;
15
+ ring: boolean;
16
+ shell: Shell;
17
+ }): import("react").JSX.Element;
18
+ export declare function MeterRing(props: {
19
+ label: string;
20
+ reading: number;
21
+ min: number;
22
+ max: number;
23
+ color: string | undefined;
24
+ format: (value: number) => string;
25
+ shell: Shell;
26
+ }): import("react").JSX.Element;
27
+ export declare function MeterBar(props: {
28
+ label: string;
29
+ reading: number;
30
+ min: number;
31
+ max: number;
32
+ format: (value: number) => string;
33
+ color: string | undefined;
34
+ segments: readonly MeterSegment[] | undefined;
35
+ zones: readonly MeterZone[] | undefined;
36
+ target: number | undefined;
37
+ forecastCaption: string | undefined;
38
+ startCaption: ReactNode;
39
+ endCaption: ReactNode;
40
+ shell: Shell;
41
+ }): import("react").JSX.Element;
42
+ //# sourceMappingURL=meter-parts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGrD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAQ,MAAM,eAAe,CAAA;AAIlE,MAAM,MAAM,KAAK,GAAG;IAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,CAAA;AAkCvF,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,IAAI,EACJ,KAAK,GACN,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACb,+BAcA;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,+BAgB7F;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,KAAK,EAAE,KAAK,CAAA;CACb,+BAcA;AAyBD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAA;IAC7C,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAAA;IACvC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,YAAY,EAAE,SAAS,CAAA;IACvB,UAAU,EAAE,SAAS,CAAA;IACrB,KAAK,EAAE,KAAK,CAAA;CACb,+BAuDA"}