@six-vallees/ui-react 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/card/card.d.ts +37 -0
- package/dist/card/card.js +18 -0
- package/dist/charts/line-chart.d.ts +38 -0
- package/dist/charts/{sparkline.js → line-chart.js} +4 -4
- package/dist/charts/segmented-bar.js +1 -1
- package/dist/charts/stat.d.ts +1 -1
- package/dist/charts/stat.js +1 -1
- package/dist/chunk-7GXL7U5X.js +67 -0
- package/dist/chunk-7GXL7U5X.js.map +1 -0
- package/dist/{chunk-OY6MO6QQ.js → chunk-AZMOEG5R.js} +8 -8
- package/dist/chunk-AZMOEG5R.js.map +1 -0
- package/dist/chunk-J6QWEIP3.js +91 -0
- package/dist/chunk-J6QWEIP3.js.map +1 -0
- package/dist/{chunk-5DZPPT7X.js → chunk-XGYKA3GE.js} +1 -1
- package/dist/chunk-XGYKA3GE.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -11
- package/package.json +1 -1
- package/dist/charts/area-chart.d.ts +0 -32
- package/dist/charts/area-chart.js +0 -10
- package/dist/charts/sparkline.d.ts +0 -30
- package/dist/chunk-5DZPPT7X.js.map +0 -1
- package/dist/chunk-64YDZRCU.js +0 -45
- package/dist/chunk-64YDZRCU.js.map +0 -1
- package/dist/chunk-L62UZTWJ.js +0 -97
- package/dist/chunk-L62UZTWJ.js.map +0 -1
- package/dist/chunk-OY6MO6QQ.js.map +0 -1
- /package/dist/{charts/area-chart.js.map → card/card.js.map} +0 -0
- /package/dist/charts/{sparkline.js.map → line-chart.js.map} +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cairn Card. A surface for grouped content, the `card`-radius container reserved
|
|
5
|
+
* for feature cards and metric tiles (AGENTS.md rule 7). Composed of parts, use as
|
|
6
|
+
* many as the content needs:
|
|
7
|
+
*
|
|
8
|
+
* <Card>
|
|
9
|
+
* <CardHeader>
|
|
10
|
+
* <CardTitle>Title</CardTitle>
|
|
11
|
+
* <CardDescription>Supporting line.</CardDescription>
|
|
12
|
+
* </CardHeader>
|
|
13
|
+
* <CardContent>…</CardContent>
|
|
14
|
+
* <CardFooter>…</CardFooter>
|
|
15
|
+
* </Card>
|
|
16
|
+
*
|
|
17
|
+
* Token-driven through the Tailwind bridge (rounded-card, border-outline, bg-surface,
|
|
18
|
+
* p-inset-*). Neutral ink throughout, hierarchy comes from the type roles and tone,
|
|
19
|
+
* never hue (rule 1). Set `asChild` to render the surface as a link or another element.
|
|
20
|
+
*/
|
|
21
|
+
interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
22
|
+
/** Render as the child element (e.g. an `<a>`) instead of a `<div>`. */
|
|
23
|
+
asChild?: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare const Card: React.ForwardRefExoticComponent<CardProps & React.RefAttributes<HTMLDivElement>>;
|
|
26
|
+
declare const CardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
27
|
+
/** The card's heading. Renders an `<h3>` by default, pass `as` to change the level. */
|
|
28
|
+
interface CardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
29
|
+
as?: 'h2' | 'h3' | 'h4';
|
|
30
|
+
}
|
|
31
|
+
declare const CardTitle: React.ForwardRefExoticComponent<CardTitleProps & React.RefAttributes<HTMLHeadingElement>>;
|
|
32
|
+
declare const CardDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
33
|
+
/** Main body. Top padding comes from the preceding `CardHeader`; add `pt-inset-lg` when used alone. */
|
|
34
|
+
declare const CardContent: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
35
|
+
declare const CardFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
36
|
+
|
|
37
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Card,
|
|
3
|
+
CardContent,
|
|
4
|
+
CardDescription,
|
|
5
|
+
CardFooter,
|
|
6
|
+
CardHeader,
|
|
7
|
+
CardTitle
|
|
8
|
+
} from "../chunk-7GXL7U5X.js";
|
|
9
|
+
import "../chunk-DXRY7AS4.js";
|
|
10
|
+
export {
|
|
11
|
+
Card,
|
|
12
|
+
CardContent,
|
|
13
|
+
CardDescription,
|
|
14
|
+
CardFooter,
|
|
15
|
+
CardHeader,
|
|
16
|
+
CardTitle
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=card.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface LineChartProps {
|
|
4
|
+
/** Values, or `{ label, value }` points. */
|
|
5
|
+
data: (number | {
|
|
6
|
+
label?: string;
|
|
7
|
+
value: number;
|
|
8
|
+
})[];
|
|
9
|
+
/** Fill the area under the line. Defaults to filled for block, unfilled for inline. */
|
|
10
|
+
area?: boolean;
|
|
11
|
+
/** Compact, fixed-width inline mode (a word-sized sparkline) vs the responsive block chart. */
|
|
12
|
+
inline?: boolean;
|
|
13
|
+
/** Inline width (px). Block mode stretches to its container. */
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
/** Block mode only: index of the point to mark with a guideline + callout dot. */
|
|
17
|
+
markerIndex?: number;
|
|
18
|
+
markerLabel?: string;
|
|
19
|
+
/** Mono tone of the line/fill: `ink` (default), `muted`, or `accent`. From `sys.chart.*`. */
|
|
20
|
+
tone?: 'ink' | 'muted' | 'accent';
|
|
21
|
+
/** Explicit colour (a token / CSS colour), overrides `tone`. */
|
|
22
|
+
color?: string;
|
|
23
|
+
/** Stroke weight in px. Defaults to the shared chart line weight. */
|
|
24
|
+
strokeWidth?: number;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Cairn LineChart, the one trend mark: a smooth line with an optional flat area fill, rendered
|
|
29
|
+
* either as a responsive block (with an optional marker) or as a compact inline sparkline
|
|
30
|
+
* (`inline`). Grayscale-first: colour comes from the chart tokens (`tone`), never `currentColor`,
|
|
31
|
+
* and line marks share `chartStroke`. Zero-dependency SVG, renders server-side (Astro-safe).
|
|
32
|
+
*/
|
|
33
|
+
declare function LineChart({ data, area, inline, width, height, markerIndex, markerLabel, tone, color, strokeWidth, className, }: LineChartProps): React.JSX.Element | null;
|
|
34
|
+
declare namespace LineChart {
|
|
35
|
+
var displayName: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { LineChart, type LineChartProps };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
LineChart
|
|
3
|
+
} from "../chunk-J6QWEIP3.js";
|
|
4
4
|
import "../chunk-27MWE4F5.js";
|
|
5
5
|
import "../chunk-AOULEGMT.js";
|
|
6
6
|
import "../chunk-DXRY7AS4.js";
|
|
7
7
|
export {
|
|
8
|
-
|
|
8
|
+
LineChart
|
|
9
9
|
};
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=line-chart.js.map
|
package/dist/charts/stat.d.ts
CHANGED
package/dist/charts/stat.js
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-DXRY7AS4.js";
|
|
4
|
+
|
|
5
|
+
// src/card/card.tsx
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var Card = React.forwardRef(
|
|
10
|
+
({ className, asChild = false, ...props }, ref) => {
|
|
11
|
+
const Comp = asChild ? Slot : "div";
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
Comp,
|
|
14
|
+
{
|
|
15
|
+
ref,
|
|
16
|
+
className: cn(
|
|
17
|
+
"rounded-card border border-outline bg-surface text-on-surface",
|
|
18
|
+
className
|
|
19
|
+
),
|
|
20
|
+
...props
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
Card.displayName = "Card";
|
|
26
|
+
var CardHeader = React.forwardRef(
|
|
27
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
28
|
+
"div",
|
|
29
|
+
{
|
|
30
|
+
ref,
|
|
31
|
+
className: cn("flex flex-col gap-gap-xs px-inset-lg pt-inset-lg pb-inset-md", className),
|
|
32
|
+
...props
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
CardHeader.displayName = "CardHeader";
|
|
37
|
+
var CardTitle = React.forwardRef(
|
|
38
|
+
({ className, as: Comp = "h3", ...props }, ref) => /* @__PURE__ */ jsx(Comp, { ref, className: cn("sv-title-md text-on-surface", className), ...props })
|
|
39
|
+
);
|
|
40
|
+
CardTitle.displayName = "CardTitle";
|
|
41
|
+
var CardDescription = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("p", { ref, className: cn("sv-body-md text-on-surface-variant", className), ...props }));
|
|
42
|
+
CardDescription.displayName = "CardDescription";
|
|
43
|
+
var CardContent = React.forwardRef(
|
|
44
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: cn("px-inset-lg pb-inset-lg", className), ...props })
|
|
45
|
+
);
|
|
46
|
+
CardContent.displayName = "CardContent";
|
|
47
|
+
var CardFooter = React.forwardRef(
|
|
48
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
49
|
+
"div",
|
|
50
|
+
{
|
|
51
|
+
ref,
|
|
52
|
+
className: cn("flex items-center gap-gap-sm px-inset-lg pb-inset-lg", className),
|
|
53
|
+
...props
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
CardFooter.displayName = "CardFooter";
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
Card,
|
|
61
|
+
CardHeader,
|
|
62
|
+
CardTitle,
|
|
63
|
+
CardDescription,
|
|
64
|
+
CardContent,
|
|
65
|
+
CardFooter
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-7GXL7U5X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/card/card.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\nimport { cn } from '@/lib/utils';\n\n/**\n * Cairn Card. A surface for grouped content, the `card`-radius container reserved\n * for feature cards and metric tiles (AGENTS.md rule 7). Composed of parts, use as\n * many as the content needs:\n *\n * <Card>\n * <CardHeader>\n * <CardTitle>Title</CardTitle>\n * <CardDescription>Supporting line.</CardDescription>\n * </CardHeader>\n * <CardContent>…</CardContent>\n * <CardFooter>…</CardFooter>\n * </Card>\n *\n * Token-driven through the Tailwind bridge (rounded-card, border-outline, bg-surface,\n * p-inset-*). Neutral ink throughout, hierarchy comes from the type roles and tone,\n * never hue (rule 1). Set `asChild` to render the surface as a link or another element.\n */\n\nexport interface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Render as the child element (e.g. an `<a>`) instead of a `<div>`. */\n asChild?: boolean;\n}\n\nexport const Card = React.forwardRef<HTMLDivElement, CardProps>(\n ({ className, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : 'div';\n return (\n <Comp\n ref={ref}\n className={cn(\n 'rounded-card border border-outline bg-surface text-on-surface',\n className\n )}\n {...props}\n />\n );\n }\n);\nCard.displayName = 'Card';\n\nexport const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn('flex flex-col gap-gap-xs px-inset-lg pt-inset-lg pb-inset-md', className)}\n {...props}\n />\n )\n);\nCardHeader.displayName = 'CardHeader';\n\n/** The card's heading. Renders an `<h3>` by default, pass `as` to change the level. */\nexport interface CardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {\n as?: 'h2' | 'h3' | 'h4';\n}\n\nexport const CardTitle = React.forwardRef<HTMLHeadingElement, CardTitleProps>(\n ({ className, as: Comp = 'h3', ...props }, ref) => (\n <Comp ref={ref} className={cn('sv-title-md text-on-surface', className)} {...props} />\n )\n);\nCardTitle.displayName = 'CardTitle';\n\nexport const CardDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => (\n <p ref={ref} className={cn('sv-body-md text-on-surface-variant', className)} {...props} />\n));\nCardDescription.displayName = 'CardDescription';\n\n/** Main body. Top padding comes from the preceding `CardHeader`; add `pt-inset-lg` when used alone. */\nexport const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn('px-inset-lg pb-inset-lg', className)} {...props} />\n )\n);\nCardContent.displayName = 'CardContent';\n\nexport const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn('flex items-center gap-gap-sm px-inset-lg pb-inset-lg', className)}\n {...props}\n />\n )\n);\nCardFooter.displayName = 'CardFooter';\n"],"mappings":";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,YAAY;AA+Bf;AAJC,IAAM,OAAa;AAAA,EACxB,CAAC,EAAE,WAAW,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AACjD,UAAM,OAAO,UAAU,OAAO;AAC9B,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA,QACF;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACF;AACA,KAAK,cAAc;AAEZ,IAAM,aAAmB;AAAA,EAC9B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QACxB;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,gEAAgE,SAAS;AAAA,MACtF,GAAG;AAAA;AAAA,EACN;AAEJ;AACA,WAAW,cAAc;AAOlB,IAAM,YAAkB;AAAA,EAC7B,CAAC,EAAE,WAAW,IAAI,OAAO,MAAM,GAAG,MAAM,GAAG,QACzC,oBAAC,QAAK,KAAU,WAAW,GAAG,+BAA+B,SAAS,GAAI,GAAG,OAAO;AAExF;AACA,UAAU,cAAc;AAEjB,IAAM,kBAAwB,iBAGnC,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAC1B,oBAAC,OAAE,KAAU,WAAW,GAAG,sCAAsC,SAAS,GAAI,GAAG,OAAO,CACzF;AACD,gBAAgB,cAAc;AAGvB,IAAM,cAAoB;AAAA,EAC/B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QACxB,oBAAC,SAAI,KAAU,WAAW,GAAG,2BAA2B,SAAS,GAAI,GAAG,OAAO;AAEnF;AACA,YAAY,cAAc;AAEnB,IAAM,aAAmB;AAAA,EAC9B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QACxB;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,wDAAwD,SAAS;AAAA,MAC9E,GAAG;AAAA;AAAA,EACN;AAEJ;AACA,WAAW,cAAc;","names":[]}
|
|
@@ -27,23 +27,23 @@ function SegmentedBar({ data, height = 40, scale = "mono", showLegend = true, cl
|
|
|
27
27
|
if (!hasActive) return "var(--sv-sys-color-on-primary)";
|
|
28
28
|
return d.active ? "var(--sv-sys-color-on-primary)" : "var(--sv-sys-color-on-surface)";
|
|
29
29
|
};
|
|
30
|
-
const needsEdge = scale === "mono" && hasActive;
|
|
31
30
|
return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
|
|
32
31
|
/* @__PURE__ */ jsx(
|
|
33
32
|
"div",
|
|
34
33
|
{
|
|
35
|
-
className: "flex w-full
|
|
36
|
-
style: {
|
|
37
|
-
height,
|
|
38
|
-
...needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: "-1px" } : {}
|
|
39
|
-
},
|
|
34
|
+
className: "flex w-full",
|
|
35
|
+
style: { height, gap: 2 },
|
|
40
36
|
role: "img",
|
|
41
37
|
"aria-label": data.map((d) => `${d.label} ${d.value}`).join(", "),
|
|
42
38
|
children: data.map((d, i) => /* @__PURE__ */ jsx(
|
|
43
39
|
"div",
|
|
44
40
|
{
|
|
45
41
|
className: "flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control",
|
|
46
|
-
style: {
|
|
42
|
+
style: {
|
|
43
|
+
width: `${safe(d.value) / total * 100}%`,
|
|
44
|
+
background: fill(d, i),
|
|
45
|
+
boxShadow: `inset 0 0 0 1px ${chartToken.markEdge}`
|
|
46
|
+
},
|
|
47
47
|
children: /* @__PURE__ */ jsx("span", { className: "truncate sv-body-xs font-medium tabular-nums", style: { color: onFill(d, i) }, children: d.value })
|
|
48
48
|
},
|
|
49
49
|
d.label
|
|
@@ -61,4 +61,4 @@ SegmentedBar.displayName = "SegmentedBar";
|
|
|
61
61
|
export {
|
|
62
62
|
SegmentedBar
|
|
63
63
|
};
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-AZMOEG5R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/segmented-bar.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { categorical, categoricalOn, sequential, sequentialOn, chartToken } from './lib/series';\n\nexport interface Segment {\n label: string;\n value: number;\n /** Pull this segment forward (ink) and others recede. */\n active?: boolean;\n}\n\nexport interface SegmentedBarProps {\n data: Segment[];\n /** Bar thickness in px. */\n height?: number;\n /**\n * How segments get colour:\n * - `mono` (default): grayscale, active segment is ink, the rest are muted tints.\n * - `categorical`: the capped unordered palette (≤4 meaningful categories).\n * - `sequential`: single-hue magnitude ramp, in data order.\n */\n scale?: 'mono' | 'categorical' | 'sequential';\n /** Show the label + value row beneath the bar. */\n showLegend?: boolean;\n className?: string;\n}\n\n/**\n * Cairn SegmentedBar, a single horizontal bar split into labelled parts (a share-of-total\n * / stacked bar). Grayscale by default; hue is opt-in via `scale`. Every segment carries a\n * text label + value, so meaning never rests on colour alone (WCAG-safe). Zero-dependency.\n */\nexport function SegmentedBar({ data, height = 40, scale = 'mono', showLegend = true, className }: SegmentedBarProps) {\n // Negative / non-finite segment values would produce invalid or overflowing widths; clamp to 0.\n const safe = (v: number) => (Number.isFinite(v) && v > 0 ? v : 0);\n const total = data.reduce((s, d) => s + safe(d.value), 0) || 1;\n const hasActive = data.some((d) => d.active);\n\n const fill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categorical(i);\n if (scale === 'sequential') return sequential(i, data.length);\n // mono: ink for the active (or all, when none is active), muted tints otherwise.\n if (!hasActive) return chartToken.ink;\n return d.active ? chartToken.ink : chartToken.muted;\n };\n\n // Accessible foreground paired to each fill, WCAG AA, never a blend mode that guesses.\n const onFill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categoricalOn(i);\n if (scale === 'sequential') return sequentialOn(i, data.length);\n // mono: white on ink fills, ink on the light muted tint.\n if (!hasActive) return 'var(--sv-sys-color-on-primary)';\n return d.active ? 'var(--sv-sys-color-on-primary)' : 'var(--sv-sys-color-on-surface)';\n };\n\n return (\n <div className={cn('w-full', className)}>\n {/* Each segment is a bounded tile: a thin gap keeps same-coloured (muted) parts distinct,\n and an inset mark-edge keyline gives every fill a crisp edge and the 3:1 shape contrast a\n pale fill can't carry on its own (AGENTS.md rule 9). */}\n <div\n className=\"flex w-full\"\n style={{ height, gap: 2 }}\n role=\"img\"\n aria-label={data.map((d) => `${d.label} ${d.value}`).join(', ')}\n >\n {data.map((d, i) => (\n <div\n key={d.label}\n className=\"flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control\"\n style={{\n width: `${(safe(d.value) / total) * 100}%`,\n background: fill(d, i),\n boxShadow: `inset 0 0 0 1px ${chartToken.markEdge}`,\n }}\n >\n <span className=\"truncate sv-body-xs font-medium tabular-nums\" style={{ color: onFill(d, i) }}>{d.value}</span>\n </div>\n ))}\n </div>\n {showLegend && (\n <ul className=\"mt-3 flex flex-wrap gap-x-4 gap-y-1\">\n {data.map((d, i) => (\n <li key={d.label} className={cn('flex items-center gap-1.5 sv-body-sm', d.active ? 'text-on-surface' : 'text-on-surface-variant')}>\n <span className=\"size-2 shrink-0 rounded-swatch\" style={{ background: fill(d, i) }} aria-hidden=\"true\" />\n {d.label}\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n}\nSegmentedBar.displayName = 'SegmentedBar';\n"],"mappings":";;;;;;;;;;;;AA2EY,cAOA,YAPA;AA5CL,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,QAAQ,QAAQ,aAAa,MAAM,UAAU,GAAsB;AAEnH,QAAM,OAAO,CAAC,MAAe,OAAO,SAAS,CAAC,KAAK,IAAI,IAAI,IAAI;AAC/D,QAAM,QAAQ,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,KAAK,GAAG,CAAC,KAAK;AAC7D,QAAM,YAAY,KAAK,KAAK,CAAC,MAAM,EAAE,MAAM;AAE3C,QAAM,OAAO,CAAC,GAAY,MAAsB;AAC9C,QAAI,UAAU,cAAe,QAAO,YAAY,CAAC;AACjD,QAAI,UAAU,aAAc,QAAO,WAAW,GAAG,KAAK,MAAM;AAE5D,QAAI,CAAC,UAAW,QAAO,WAAW;AAClC,WAAO,EAAE,SAAS,WAAW,MAAM,WAAW;AAAA,EAChD;AAGA,QAAM,SAAS,CAAC,GAAY,MAAsB;AAChD,QAAI,UAAU,cAAe,QAAO,cAAc,CAAC;AACnD,QAAI,UAAU,aAAc,QAAO,aAAa,GAAG,KAAK,MAAM;A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
8
|
+
chartToken,
|
|
9
|
+
toneFill
|
|
10
|
+
} from "./chunk-AOULEGMT.js";
|
|
11
|
+
import {
|
|
12
|
+
cn
|
|
13
|
+
} from "./chunk-DXRY7AS4.js";
|
|
14
|
+
|
|
15
|
+
// src/charts/line-chart.tsx
|
|
16
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var W = 1e3;
|
|
18
|
+
var TOP = 26;
|
|
19
|
+
var BOTTOM = 8;
|
|
20
|
+
function LineChart({
|
|
21
|
+
data,
|
|
22
|
+
area,
|
|
23
|
+
inline = false,
|
|
24
|
+
width = 120,
|
|
25
|
+
height,
|
|
26
|
+
markerIndex,
|
|
27
|
+
markerLabel,
|
|
28
|
+
tone = "ink",
|
|
29
|
+
color,
|
|
30
|
+
strokeWidth = chartStroke.line,
|
|
31
|
+
className
|
|
32
|
+
}) {
|
|
33
|
+
const values = finite(data.map((d) => typeof d === "number" ? d : d.value));
|
|
34
|
+
if (values.length < 2) return null;
|
|
35
|
+
const stroke = color ?? toneFill(tone);
|
|
36
|
+
const filled = area ?? !inline;
|
|
37
|
+
const { min, max, range } = extent(values);
|
|
38
|
+
if (inline) {
|
|
39
|
+
const h = height ?? 34;
|
|
40
|
+
const pad = strokeWidth;
|
|
41
|
+
const step = width / (values.length - 1);
|
|
42
|
+
const pts2 = values.map((v, i) => [i * step, pad + (1 - (v - min) / range) * (h - pad * 2)]);
|
|
43
|
+
const line2 = smooth(pts2);
|
|
44
|
+
const areaPath2 = `${line2} L ${width},${h} L 0,${h} Z`;
|
|
45
|
+
return /* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${width} ${h}`, width, height: h, fill: "none", className: cn("overflow-visible", className), "aria-hidden": "true", children: [
|
|
46
|
+
filled && /* @__PURE__ */ jsx("path", { d: areaPath2, fill: stroke, opacity: "0.12" }),
|
|
47
|
+
/* @__PURE__ */ jsx("path", { d: line2, stroke, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
const H = height ?? 240;
|
|
51
|
+
const stepX = W / (values.length - 1);
|
|
52
|
+
const y = (v) => TOP + (1 - (v - min) / range) * (H - TOP - BOTTOM);
|
|
53
|
+
const pts = values.map((v, i) => [i * stepX, y(v)]);
|
|
54
|
+
const line = smooth(pts);
|
|
55
|
+
const areaPath = `${line} L ${W},${H} L 0,${H} Z`;
|
|
56
|
+
const labelled = data.filter((d) => typeof d !== "number" && d.label);
|
|
57
|
+
const ariaLabel = labelled.length ? data.map((d, i) => typeof d === "number" ? `${values[i]}` : `${d.label} ${d.value}`).join(", ") : `Trend across ${values.length} points, from ${min} to ${max}`;
|
|
58
|
+
const marked = markerIndex != null && markerIndex >= 0 && markerIndex < values.length;
|
|
59
|
+
const markLeft = marked ? markerIndex / (values.length - 1) * 100 : 0;
|
|
60
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), style: { height: H }, role: "img", "aria-label": ariaLabel, children: [
|
|
61
|
+
/* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${W} ${H}`, width: "100%", height: H, preserveAspectRatio: "none", fill: "none", "aria-hidden": "true", children: [
|
|
62
|
+
filled && /* @__PURE__ */ jsx("path", { d: areaPath, fill: stroke, fillOpacity: 0.1 }),
|
|
63
|
+
/* @__PURE__ */ jsx("path", { d: line, stroke, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke" }),
|
|
64
|
+
marked && /* @__PURE__ */ jsx("line", { x1: markerIndex * stepX, y1: TOP, x2: markerIndex * stepX, y2: H, stroke: chartToken.axis, strokeWidth: chartStroke.guide, vectorEffect: "non-scaling-stroke" })
|
|
65
|
+
] }),
|
|
66
|
+
marked && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
"span",
|
|
69
|
+
{
|
|
70
|
+
className: "pointer-events-none absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 bg-surface",
|
|
71
|
+
style: { left: `${markLeft}%`, top: y(values[markerIndex]), borderColor: stroke },
|
|
72
|
+
"aria-hidden": "true"
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
markerLabel && /* @__PURE__ */ jsx(
|
|
76
|
+
"span",
|
|
77
|
+
{
|
|
78
|
+
className: "pointer-events-none absolute top-0 -translate-x-1/2 whitespace-nowrap sv-body-sm font-medium text-on-surface",
|
|
79
|
+
style: { left: `${markLeft}%` },
|
|
80
|
+
children: markerLabel
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
] })
|
|
84
|
+
] });
|
|
85
|
+
}
|
|
86
|
+
LineChart.displayName = "LineChart";
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
LineChart
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=chunk-J6QWEIP3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/line-chart.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { smooth, finite, extent } from './lib/path';\nimport { toneFill, chartToken, chartStroke } from './lib/series';\n\nexport interface LineChartProps {\n /** Values, or `{ label, value }` points. */\n data: (number | { label?: string; value: number })[];\n /** Fill the area under the line. Defaults to filled for block, unfilled for inline. */\n area?: boolean;\n /** Compact, fixed-width inline mode (a word-sized sparkline) vs the responsive block chart. */\n inline?: boolean;\n /** Inline width (px). Block mode stretches to its container. */\n width?: number;\n height?: number;\n /** Block mode only: index of the point to mark with a guideline + callout dot. */\n markerIndex?: number;\n markerLabel?: string;\n /** Mono tone of the line/fill: `ink` (default), `muted`, or `accent`. From `sys.chart.*`. */\n tone?: 'ink' | 'muted' | 'accent';\n /** Explicit colour (a token / CSS colour), overrides `tone`. */\n color?: string;\n /** Stroke weight in px. Defaults to the shared chart line weight. */\n strokeWidth?: number;\n className?: string;\n}\n\n/** Block-mode internal coordinate width; the SVG stretches to the container. */\nconst W = 1000;\n/** Top room (px) reserved for the marker callout so it never clips. */\nconst TOP = 26;\nconst BOTTOM = 8;\n\n/**\n * Cairn LineChart, the one trend mark: a smooth line with an optional flat area fill, rendered\n * either as a responsive block (with an optional marker) or as a compact inline sparkline\n * (`inline`). Grayscale-first: colour comes from the chart tokens (`tone`), never `currentColor`,\n * and line marks share `chartStroke`. Zero-dependency SVG, renders server-side (Astro-safe).\n */\nexport function LineChart({\n data,\n area,\n inline = false,\n width = 120,\n height,\n markerIndex,\n markerLabel,\n tone = 'ink',\n color,\n strokeWidth = chartStroke.line,\n className,\n}: LineChartProps) {\n const values = finite(data.map((d) => (typeof d === 'number' ? d : d.value)));\n if (values.length < 2) return null;\n const stroke = color ?? toneFill(tone);\n const filled = area ?? !inline;\n const { min, max, range } = extent(values);\n\n // Inline: fixed word-sized sparkline, no marker.\n if (inline) {\n const h = height ?? 34;\n const pad = strokeWidth;\n const step = width / (values.length - 1);\n const pts = values.map((v, i) => [i * step, pad + (1 - (v - min) / range) * (h - pad * 2)] as const);\n const line = smooth(pts);\n const areaPath = `${line} L ${width},${h} L 0,${h} Z`;\n return (\n <svg viewBox={`0 0 ${width} ${h}`} width={width} height={h} fill=\"none\" className={cn('overflow-visible', className)} aria-hidden=\"true\">\n {filled && <path d={areaPath} fill={stroke} opacity=\"0.12\" />}\n <path d={line} stroke={stroke} strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n );\n }\n\n // Block: responsive, non-scaling stroke, optional marker with HTML overlays.\n const H = height ?? 240;\n const stepX = W / (values.length - 1);\n const y = (v: number) => TOP + (1 - (v - min) / range) * (H - TOP - BOTTOM);\n const pts = values.map((v, i) => [i * stepX, y(v)] as const);\n const line = smooth(pts);\n const areaPath = `${line} L ${W},${H} L 0,${H} Z`;\n\n const labelled = data.filter((d) => typeof d !== 'number' && d.label);\n const ariaLabel = labelled.length\n ? data.map((d, i) => (typeof d === 'number' ? `${values[i]}` : `${d.label} ${d.value}`)).join(', ')\n : `Trend across ${values.length} points, from ${min} to ${max}`;\n\n const marked = markerIndex != null && markerIndex >= 0 && markerIndex < values.length;\n const markLeft = marked ? (markerIndex! / (values.length - 1)) * 100 : 0;\n\n return (\n <div className={cn('relative w-full', className)} style={{ height: H }} role=\"img\" aria-label={ariaLabel}>\n <svg viewBox={`0 0 ${W} ${H}`} width=\"100%\" height={H} preserveAspectRatio=\"none\" fill=\"none\" aria-hidden=\"true\">\n {filled && <path d={areaPath} fill={stroke} fillOpacity={0.1} />}\n <path d={line} stroke={stroke} strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\" vectorEffect=\"non-scaling-stroke\" />\n {marked && (\n <line x1={markerIndex! * stepX} y1={TOP} x2={markerIndex! * stepX} y2={H} stroke={chartToken.axis} strokeWidth={chartStroke.guide} vectorEffect=\"non-scaling-stroke\" />\n )}\n </svg>\n {marked && (\n <>\n <span\n className=\"pointer-events-none absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 bg-surface\"\n style={{ left: `${markLeft}%`, top: y(values[markerIndex!]), borderColor: stroke }}\n aria-hidden=\"true\"\n />\n {markerLabel && (\n <span\n className=\"pointer-events-none absolute top-0 -translate-x-1/2 whitespace-nowrap sv-body-sm font-medium text-on-surface\"\n style={{ left: `${markLeft}%` }}\n >\n {markerLabel}\n </span>\n )}\n </>\n )}\n </div>\n );\n}\nLineChart.displayName = 'LineChart';\n"],"mappings":";;;;;;;;;;;;;;;AAkEM,SAiCE,UAhCW,KADb;AAvCN,IAAM,IAAI;AAEV,IAAM,MAAM;AACZ,IAAM,SAAS;AAQR,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,cAAc,YAAY;AAAA,EAC1B;AACF,GAAmB;AACjB,QAAM,SAAS,OAAO,KAAK,IAAI,CAAC,MAAO,OAAO,MAAM,WAAW,IAAI,EAAE,K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aPath"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/stat.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '@/lib/utils';\n\nexport interface StatProps {\n /** The metric, pre-formatted (e.g. \"3,484\" or \"118 lbs\"). */\n value: string;\n label?: string;\n /** Change indicator. `tone` colours it (success / error / neutral). */\n delta?: { value: string; tone?: 'success' | 'error' | 'neutral' };\n /** Trailing visual, e.g. a `<LineChart inline />`. */\n children?: React.ReactNode;\n className?: string;\n}\n\n/** Cairn Stat, a metric with an optional coloured delta and a trailing sparkline. */\nexport function Stat({ value, label, delta, children, className }: StatProps) {\n const tone = delta?.tone ?? 'neutral';\n // Message-as-meaning lives in a status container with its paired on-* text (AGENTS.md\n // rule 4), never as bare coloured text — so the delta is a small container pill.\n const toneCls =\n tone === 'success'\n ? 'bg-success-container text-on-success-container'\n : tone === 'error'\n ? 'bg-error-container text-on-error-container'\n : 'bg-surface-muted text-on-surface-variant';\n // A directional glyph so the up/down meaning never rests on hue alone (rule 4).\n const arrow = tone === 'success' ? '↑' : tone === 'error' ? '↓' : null;\n return (\n <div className={cn('rounded-card border border-outline p-5', className)}>\n {label && <p className=\"sv-body-sm text-on-surface-variant\">{label}</p>}\n <div className=\"mt-2 flex items-end justify-between gap-4\">\n <div>\n <div className=\"sv-metric tabular-nums text-on-surface\">{value}</div>\n {delta && (\n <div className=\"mt-2\">\n <span className={cn('inline-flex items-center gap-1 rounded-pill px-2 py-0.5 sv-body-sm font-medium', toneCls)}>\n {arrow && <span aria-hidden=\"true\">{arrow}</span>}\n {delta.value}\n </span>\n </div>\n )}\n </div>\n {children && <div className=\"shrink-0 text-on-surface-variant\">{children}</div>}\n </div>\n </div>\n );\n}\nStat.displayName = 'Stat';\n"],"mappings":";;;;;AA6BgB,cAMF,YANE;AAdT,SAAS,KAAK,EAAE,OAAO,OAAO,OAAO,UAAU,UAAU,GAAc;AAC5E,QAAM,OAAO,OAAO,QAAQ;AAG5B,QAAM,UACJ,SAAS,YACL,mDACA,SAAS,UACP,+CACA;AAER,QAAM,QAAQ,SAAS,YAAY,WAAM,SAAS,UAAU,WAAM;AAClE,SACE,qBAAC,SAAI,WAAW,GAAG,0CAA0C,SAAS,GACnE;AAAA,aAAS,oBAAC,OAAE,WAAU,sCAAsC,iBAAM;AAAA,IACnE,qBAAC,SAAI,WAAU,6CACb;AAAA,2BAAC,SACC;AAAA,4BAAC,SAAI,WAAU,0CAA0C,iBAAM;AAAA,QAC9D,SACC,oBAAC,SAAI,WAAU,QACb,+BAAC,UAAK,WAAW,GAAG,kFAAkF,OAAO,GAC1G;AAAA,mBAAS,oBAAC,UAAK,eAAY,QAAQ,iBAAM;AAAA,UACzC,MAAM;AAAA,WACT,GACF;AAAA,SAEJ;AAAA,MACC,YAAY,oBAAC,SAAI,WAAU,oCAAoC,UAAS;AAAA,OAC3E;AAAA,KACF;AAEJ;AACA,KAAK,cAAc;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Button, ButtonProps, buttonVariants } from './button/button.js';
|
|
2
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardProps, CardTitle, CardTitleProps } from './card/card.js';
|
|
2
3
|
export { Icon, IconProps } from './icon/icon.js';
|
|
3
4
|
export { Logo, LogoProps } from './logo/logo.js';
|
|
4
5
|
export { LogoMark, LogoMarkProps } from './logo/logo-mark.js';
|
|
5
|
-
export {
|
|
6
|
-
export { AreaChart, AreaChartProps } from './charts/area-chart.js';
|
|
6
|
+
export { LineChart, LineChartProps } from './charts/line-chart.js';
|
|
7
7
|
export { BarChart, BarChartProps, BarDatum } from './charts/bar-chart.js';
|
|
8
8
|
export { Stat, StatProps } from './charts/stat.js';
|
|
9
9
|
export { Ring, RingProps } from './charts/ring.js';
|
package/dist/index.js
CHANGED
|
@@ -11,22 +11,19 @@ import {
|
|
|
11
11
|
Button,
|
|
12
12
|
buttonVariants
|
|
13
13
|
} from "./chunk-KUKSVVDZ.js";
|
|
14
|
-
import {
|
|
15
|
-
AreaChart
|
|
16
|
-
} from "./chunk-L62UZTWJ.js";
|
|
17
14
|
import {
|
|
18
15
|
BarChart
|
|
19
16
|
} from "./chunk-PJRCDPG5.js";
|
|
17
|
+
import {
|
|
18
|
+
LineChart
|
|
19
|
+
} from "./chunk-J6QWEIP3.js";
|
|
20
|
+
import "./chunk-27MWE4F5.js";
|
|
20
21
|
import {
|
|
21
22
|
Ring
|
|
22
23
|
} from "./chunk-X3LG535W.js";
|
|
23
24
|
import {
|
|
24
25
|
SegmentedBar
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import {
|
|
27
|
-
Sparkline
|
|
28
|
-
} from "./chunk-64YDZRCU.js";
|
|
29
|
-
import "./chunk-27MWE4F5.js";
|
|
26
|
+
} from "./chunk-AZMOEG5R.js";
|
|
30
27
|
import {
|
|
31
28
|
CATEGORICAL_MAX,
|
|
32
29
|
categorical,
|
|
@@ -39,19 +36,32 @@ import {
|
|
|
39
36
|
} from "./chunk-AOULEGMT.js";
|
|
40
37
|
import {
|
|
41
38
|
Stat
|
|
42
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-XGYKA3GE.js";
|
|
40
|
+
import {
|
|
41
|
+
Card,
|
|
42
|
+
CardContent,
|
|
43
|
+
CardDescription,
|
|
44
|
+
CardFooter,
|
|
45
|
+
CardHeader,
|
|
46
|
+
CardTitle
|
|
47
|
+
} from "./chunk-7GXL7U5X.js";
|
|
43
48
|
import "./chunk-DXRY7AS4.js";
|
|
44
49
|
export {
|
|
45
|
-
AreaChart,
|
|
46
50
|
BarChart,
|
|
47
51
|
Button,
|
|
48
52
|
CATEGORICAL_MAX,
|
|
53
|
+
Card,
|
|
54
|
+
CardContent,
|
|
55
|
+
CardDescription,
|
|
56
|
+
CardFooter,
|
|
57
|
+
CardHeader,
|
|
58
|
+
CardTitle,
|
|
49
59
|
Icon,
|
|
60
|
+
LineChart,
|
|
50
61
|
Logo,
|
|
51
62
|
LogoMark,
|
|
52
63
|
Ring,
|
|
53
64
|
SegmentedBar,
|
|
54
|
-
Sparkline,
|
|
55
65
|
Stat,
|
|
56
66
|
buttonVariants,
|
|
57
67
|
categorical,
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
interface AreaChartProps {
|
|
4
|
-
/** Values, or `{ label, value }` points. */
|
|
5
|
-
data: (number | {
|
|
6
|
-
label?: string;
|
|
7
|
-
value: number;
|
|
8
|
-
})[];
|
|
9
|
-
height?: number;
|
|
10
|
-
/** Index of the point to mark with a guideline + callout. */
|
|
11
|
-
markerIndex?: number;
|
|
12
|
-
markerLabel?: string;
|
|
13
|
-
/** Mono tone of the line/fill: `ink` (default), `muted`, or `accent`. From `sys.chart.*`. */
|
|
14
|
-
tone?: 'ink' | 'muted' | 'accent';
|
|
15
|
-
/** Explicit colour (a token / CSS colour), overrides `tone`. */
|
|
16
|
-
color?: string;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Cairn AreaChart, a smooth line with a flat fill. Grayscale-first: colour comes from the
|
|
21
|
-
* chart tokens (`tone`), never ambient `currentColor`, so the family reads as one system.
|
|
22
|
-
* Zero-dependency SVG: renders server-side (Astro-safe), no client JS. The horizontal
|
|
23
|
-
* axis stretches to the container (non-scaling strokes keep the line crisp); the marker
|
|
24
|
-
* dot + callout are HTML overlays so they never distort. An interactive tier (hover
|
|
25
|
-
* tooltips) belongs to the visx layer, this is the static SSR tier.
|
|
26
|
-
*/
|
|
27
|
-
declare function AreaChart({ data, height, markerIndex, markerLabel, tone, color, className }: AreaChartProps): React.JSX.Element | null;
|
|
28
|
-
declare namespace AreaChart {
|
|
29
|
-
var displayName: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { AreaChart, type AreaChartProps };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
interface SparklineProps {
|
|
4
|
-
/** The series of values. */
|
|
5
|
-
data: number[];
|
|
6
|
-
width?: number;
|
|
7
|
-
height?: number;
|
|
8
|
-
/** `line` or filled `area`. */
|
|
9
|
-
type?: 'line' | 'area';
|
|
10
|
-
/**
|
|
11
|
-
* Mono tone of the mark: `ink` (single series, default), `muted` (secondary/trailing, e.g.
|
|
12
|
-
* inside a Stat), or `accent` (the one opt-in hue). Resolves from `sys.chart.*`.
|
|
13
|
-
*/
|
|
14
|
-
tone?: 'ink' | 'muted' | 'accent';
|
|
15
|
-
/** Explicit colour (a token / CSS colour), overrides `tone`. */
|
|
16
|
-
color?: string;
|
|
17
|
-
/** Stroke weight in px. Defaults to the shared chart line weight. */
|
|
18
|
-
strokeWidth?: number;
|
|
19
|
-
className?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Cairn Sparkline, a compact, axis-less trend line. Grayscale-first: colour comes from the
|
|
23
|
-
* chart tokens (`tone`), never ambient `currentColor`, so it reads the same in any context.
|
|
24
|
-
*/
|
|
25
|
-
declare function Sparkline({ data, width, height, type, tone, color, strokeWidth, className, }: SparklineProps): React.JSX.Element | null;
|
|
26
|
-
declare namespace Sparkline {
|
|
27
|
-
var displayName: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { Sparkline, type SparklineProps };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/stat.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '@/lib/utils';\n\nexport interface StatProps {\n /** The metric, pre-formatted (e.g. \"3,484\" or \"118 lbs\"). */\n value: string;\n label?: string;\n /** Change indicator. `tone` colours it (success / error / neutral). */\n delta?: { value: string; tone?: 'success' | 'error' | 'neutral' };\n /** Trailing visual, e.g. a `<Sparkline />`. */\n children?: React.ReactNode;\n className?: string;\n}\n\n/** Cairn Stat, a metric with an optional coloured delta and a trailing sparkline. */\nexport function Stat({ value, label, delta, children, className }: StatProps) {\n const tone = delta?.tone ?? 'neutral';\n // Message-as-meaning lives in a status container with its paired on-* text (AGENTS.md\n // rule 4), never as bare coloured text — so the delta is a small container pill.\n const toneCls =\n tone === 'success'\n ? 'bg-success-container text-on-success-container'\n : tone === 'error'\n ? 'bg-error-container text-on-error-container'\n : 'bg-surface-muted text-on-surface-variant';\n // A directional glyph so the up/down meaning never rests on hue alone (rule 4).\n const arrow = tone === 'success' ? '↑' : tone === 'error' ? '↓' : null;\n return (\n <div className={cn('rounded-card border border-outline p-5', className)}>\n {label && <p className=\"sv-body-sm text-on-surface-variant\">{label}</p>}\n <div className=\"mt-2 flex items-end justify-between gap-4\">\n <div>\n <div className=\"sv-metric tabular-nums text-on-surface\">{value}</div>\n {delta && (\n <div className=\"mt-2\">\n <span className={cn('inline-flex items-center gap-1 rounded-pill px-2 py-0.5 sv-body-sm font-medium', toneCls)}>\n {arrow && <span aria-hidden=\"true\">{arrow}</span>}\n {delta.value}\n </span>\n </div>\n )}\n </div>\n {children && <div className=\"shrink-0 text-on-surface-variant\">{children}</div>}\n </div>\n </div>\n );\n}\nStat.displayName = 'Stat';\n"],"mappings":";;;;;AA6BgB,cAMF,YANE;AAdT,SAAS,KAAK,EAAE,OAAO,OAAO,OAAO,UAAU,UAAU,GAAc;AAC5E,QAAM,OAAO,OAAO,QAAQ;AAG5B,QAAM,UACJ,SAAS,YACL,mDACA,SAAS,UACP,+CACA;AAER,QAAM,QAAQ,SAAS,YAAY,WAAM,SAAS,UAAU,WAAM;AAClE,SACE,qBAAC,SAAI,WAAW,GAAG,0CAA0C,SAAS,GACnE;AAAA,aAAS,oBAAC,OAAE,WAAU,sCAAsC,iBAAM;AAAA,IACnE,qBAAC,SAAI,WAAU,6CACb;AAAA,2BAAC,SACC;AAAA,4BAAC,SAAI,WAAU,0CAA0C,iBAAM;AAAA,QAC9D,SACC,oBAAC,SAAI,WAAU,QACb,+BAAC,UAAK,WAAW,GAAG,kFAAkF,OAAO,GAC1G;AAAA,mBAAS,oBAAC,UAAK,eAAY,QAAQ,iBAAM;AAAA,UACzC,MAAM;AAAA,WACT,GACF;AAAA,SAEJ;AAAA,MACC,YAAY,oBAAC,SAAI,WAAU,oCAAoC,UAAS;AAAA,OAC3E;AAAA,KACF;AAEJ;AACA,KAAK,cAAc;","names":[]}
|
package/dist/chunk-64YDZRCU.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extent,
|
|
3
|
-
finite,
|
|
4
|
-
smooth
|
|
5
|
-
} from "./chunk-27MWE4F5.js";
|
|
6
|
-
import {
|
|
7
|
-
chartStroke,
|
|
8
|
-
toneFill
|
|
9
|
-
} from "./chunk-AOULEGMT.js";
|
|
10
|
-
import {
|
|
11
|
-
cn
|
|
12
|
-
} from "./chunk-DXRY7AS4.js";
|
|
13
|
-
|
|
14
|
-
// src/charts/sparkline.tsx
|
|
15
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
-
function Sparkline({
|
|
17
|
-
data,
|
|
18
|
-
width = 120,
|
|
19
|
-
height = 34,
|
|
20
|
-
type = "line",
|
|
21
|
-
tone = "ink",
|
|
22
|
-
color,
|
|
23
|
-
strokeWidth = chartStroke.line,
|
|
24
|
-
className
|
|
25
|
-
}) {
|
|
26
|
-
if (data.length < 2) return null;
|
|
27
|
-
const values = finite(data);
|
|
28
|
-
const { min, range } = extent(values);
|
|
29
|
-
const step = width / (values.length - 1);
|
|
30
|
-
const pad = strokeWidth;
|
|
31
|
-
const pts = values.map((v, i) => [i * step, pad + (1 - (v - min) / range) * (height - pad * 2)]);
|
|
32
|
-
const line = smooth(pts);
|
|
33
|
-
const area = `${line} L ${width},${height} L 0,${height} Z`;
|
|
34
|
-
const stroke = color ?? toneFill(tone);
|
|
35
|
-
return /* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${width} ${height}`, width, height, fill: "none", className: cn("overflow-visible", className), "aria-hidden": "true", children: [
|
|
36
|
-
type === "area" && /* @__PURE__ */ jsx("path", { d: area, fill: stroke, opacity: "0.12" }),
|
|
37
|
-
/* @__PURE__ */ jsx("path", { d: line, stroke, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
38
|
-
] });
|
|
39
|
-
}
|
|
40
|
-
Sparkline.displayName = "Sparkline";
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
Sparkline
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=chunk-64YDZRCU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/sparkline.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { smooth, finite, extent } from './lib/path';\nimport { toneFill, chartStroke } from './lib/series';\n\nexport interface SparklineProps {\n /** The series of values. */\n data: number[];\n width?: number;\n height?: number;\n /** `line` or filled `area`. */\n type?: 'line' | 'area';\n /**\n * Mono tone of the mark: `ink` (single series, default), `muted` (secondary/trailing, e.g.\n * inside a Stat), or `accent` (the one opt-in hue). Resolves from `sys.chart.*`.\n */\n tone?: 'ink' | 'muted' | 'accent';\n /** Explicit colour (a token / CSS colour), overrides `tone`. */\n color?: string;\n /** Stroke weight in px. Defaults to the shared chart line weight. */\n strokeWidth?: number;\n className?: string;\n}\n\n/**\n * Cairn Sparkline, a compact, axis-less trend line. Grayscale-first: colour comes from the\n * chart tokens (`tone`), never ambient `currentColor`, so it reads the same in any context.\n */\nexport function Sparkline({\n data,\n width = 120,\n height = 34,\n type = 'line',\n tone = 'ink',\n color,\n strokeWidth = chartStroke.line,\n className,\n}: SparklineProps) {\n if (data.length < 2) return null;\n const values = finite(data);\n const { min, range } = extent(values);\n const step = width / (values.length - 1);\n const pad = strokeWidth;\n const pts = values.map((v, i) => [i * step, pad + (1 - (v - min) / range) * (height - pad * 2)] as const);\n const line = smooth(pts);\n const area = `${line} L ${width},${height} L 0,${height} Z`;\n const stroke = color ?? toneFill(tone);\n return (\n <svg viewBox={`0 0 ${width} ${height}`} width={width} height={height} fill=\"none\" className={cn('overflow-visible', className)} aria-hidden=\"true\">\n {type === 'area' && <path d={area} fill={stroke} opacity=\"0.12\" />}\n <path d={line} stroke={stroke} strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n );\n}\nSparkline.displayName = 'Sparkline';\n"],"mappings":";;;;;;;;;;;;;;AA+CI,SACsB,KADtB;AApBG,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP;AAAA,EACA,cAAc,YAAY;AAAA,EAC1B;AACF,GAAmB;AACjB,MAAI,KAAK,SAAS,EAAG,QAAO;AAC5B,QAAM,SAAS,OAAO,IAAI;AAC1B,QAAM,EAAE,KAAK,MAAM,IAAI,OAAO,MAAM;AACpC,QAAM,OAAO,SAAS,OAAO,SAAS;AACtC,QAAM,MAAM;AACZ,QAAM,MAAM,OAAO,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,MAAM,OAAO,KAAK,IAAI,OAAO,UAAU,SAAS,MAAM,EAAE,CAAU;AACxG,QAAM,OAAO,OAAO,GAAG;AACvB,QAAM,OAAO,GAAG,IAAI,MAAM,KAAK,IAAI,MAAM,QAAQ,MAAM;AACvD,QAAM,SAAS,SAAS,SAAS,IAAI;AACrC,SACE,qBAAC,SAAI,SAAS,OAAO,KAAK,IAAI,MAAM,IAAI,OAAc,QAAgB,MAAK,QAAO,WAAW,GAAG,oBAAoB,SAAS,GAAG,eAAY,QACzI;AAAA,aAAS,UAAU,oBAAC,UAAK,GAAG,MAAM,MAAM,QAAQ,SAAQ,QAAO;AAAA,IAChE,oBAAC,UAAK,GAAG,MAAM,QAAgB,aAA0B,eAAc,SAAQ,gBAAe,SAAQ;AAAA,KACxG;AAEJ;AACA,UAAU,cAAc;","names":[]}
|
package/dist/chunk-L62UZTWJ.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extent,
|
|
3
|
-
finite,
|
|
4
|
-
smooth
|
|
5
|
-
} from "./chunk-27MWE4F5.js";
|
|
6
|
-
import {
|
|
7
|
-
chartStroke,
|
|
8
|
-
chartToken,
|
|
9
|
-
toneFill
|
|
10
|
-
} from "./chunk-AOULEGMT.js";
|
|
11
|
-
import {
|
|
12
|
-
cn
|
|
13
|
-
} from "./chunk-DXRY7AS4.js";
|
|
14
|
-
|
|
15
|
-
// src/charts/area-chart.tsx
|
|
16
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
-
var W = 1e3;
|
|
18
|
-
var TOP = 26;
|
|
19
|
-
var BOTTOM = 8;
|
|
20
|
-
function AreaChart({ data, height = 240, markerIndex, markerLabel, tone = "ink", color, className }) {
|
|
21
|
-
const values = finite(data.map((d) => typeof d === "number" ? d : d.value));
|
|
22
|
-
if (values.length < 2) return null;
|
|
23
|
-
const stroke = color ?? toneFill(tone);
|
|
24
|
-
const { min, max, range } = extent(values);
|
|
25
|
-
const stepX = W / (values.length - 1);
|
|
26
|
-
const labelled = data.filter((d) => typeof d !== "number" && d.label);
|
|
27
|
-
const ariaLabel = labelled.length ? data.map((d, i) => typeof d === "number" ? `${values[i]}` : `${d.label} ${d.value}`).join(", ") : `Trend across ${values.length} points, from ${min} to ${max}`;
|
|
28
|
-
const y = (v) => TOP + (1 - (v - min) / range) * (height - TOP - BOTTOM);
|
|
29
|
-
const pts = values.map((v, i) => [i * stepX, y(v)]);
|
|
30
|
-
const line = smooth(pts);
|
|
31
|
-
const area = `${line} L ${W},${height} L 0,${height} Z`;
|
|
32
|
-
const marked = markerIndex != null && markerIndex >= 0 && markerIndex < values.length;
|
|
33
|
-
const markLeft = marked ? markerIndex / (values.length - 1) * 100 : 0;
|
|
34
|
-
return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), style: { height }, role: "img", "aria-label": ariaLabel, children: [
|
|
35
|
-
/* @__PURE__ */ jsxs(
|
|
36
|
-
"svg",
|
|
37
|
-
{
|
|
38
|
-
viewBox: `0 0 ${W} ${height}`,
|
|
39
|
-
width: "100%",
|
|
40
|
-
height,
|
|
41
|
-
preserveAspectRatio: "none",
|
|
42
|
-
fill: "none",
|
|
43
|
-
"aria-hidden": "true",
|
|
44
|
-
children: [
|
|
45
|
-
/* @__PURE__ */ jsx("path", { d: area, fill: stroke, fillOpacity: 0.1 }),
|
|
46
|
-
/* @__PURE__ */ jsx(
|
|
47
|
-
"path",
|
|
48
|
-
{
|
|
49
|
-
d: line,
|
|
50
|
-
stroke,
|
|
51
|
-
strokeWidth: chartStroke.line,
|
|
52
|
-
strokeLinecap: "round",
|
|
53
|
-
strokeLinejoin: "round",
|
|
54
|
-
vectorEffect: "non-scaling-stroke"
|
|
55
|
-
}
|
|
56
|
-
),
|
|
57
|
-
marked && /* @__PURE__ */ jsx(
|
|
58
|
-
"line",
|
|
59
|
-
{
|
|
60
|
-
x1: markerIndex * stepX,
|
|
61
|
-
y1: TOP,
|
|
62
|
-
x2: markerIndex * stepX,
|
|
63
|
-
y2: height,
|
|
64
|
-
stroke: chartToken.axis,
|
|
65
|
-
strokeWidth: chartStroke.guide,
|
|
66
|
-
vectorEffect: "non-scaling-stroke"
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
),
|
|
72
|
-
marked && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
73
|
-
/* @__PURE__ */ jsx(
|
|
74
|
-
"span",
|
|
75
|
-
{
|
|
76
|
-
className: "pointer-events-none absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 bg-surface",
|
|
77
|
-
style: { left: `${markLeft}%`, top: y(values[markerIndex]), borderColor: stroke },
|
|
78
|
-
"aria-hidden": "true"
|
|
79
|
-
}
|
|
80
|
-
),
|
|
81
|
-
markerLabel && /* @__PURE__ */ jsx(
|
|
82
|
-
"span",
|
|
83
|
-
{
|
|
84
|
-
className: "pointer-events-none absolute top-0 -translate-x-1/2 whitespace-nowrap sv-body-sm font-medium text-on-surface",
|
|
85
|
-
style: { left: `${markLeft}%` },
|
|
86
|
-
children: markerLabel
|
|
87
|
-
}
|
|
88
|
-
)
|
|
89
|
-
] })
|
|
90
|
-
] });
|
|
91
|
-
}
|
|
92
|
-
AreaChart.displayName = "AreaChart";
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
AreaChart
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=chunk-L62UZTWJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/area-chart.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { smooth, finite, extent } from './lib/path';\nimport { toneFill, chartToken, chartStroke } from './lib/series';\n\nexport interface AreaChartProps {\n /** Values, or `{ label, value }` points. */\n data: (number | { label?: string; value: number })[];\n height?: number;\n /** Index of the point to mark with a guideline + callout. */\n markerIndex?: number;\n markerLabel?: string;\n /** Mono tone of the line/fill: `ink` (default), `muted`, or `accent`. From `sys.chart.*`. */\n tone?: 'ink' | 'muted' | 'accent';\n /** Explicit colour (a token / CSS colour), overrides `tone`. */\n color?: string;\n className?: string;\n}\n\n/** Internal coordinate width; the SVG stretches to the container (see preserveAspectRatio). */\nconst W = 1000;\n/** Top room (px) reserved for the marker callout so it never clips. */\nconst TOP = 26;\nconst BOTTOM = 8;\n\n/**\n * Cairn AreaChart, a smooth line with a flat fill. Grayscale-first: colour comes from the\n * chart tokens (`tone`), never ambient `currentColor`, so the family reads as one system.\n * Zero-dependency SVG: renders server-side (Astro-safe), no client JS. The horizontal\n * axis stretches to the container (non-scaling strokes keep the line crisp); the marker\n * dot + callout are HTML overlays so they never distort. An interactive tier (hover\n * tooltips) belongs to the visx layer, this is the static SSR tier.\n */\nexport function AreaChart({ data, height = 240, markerIndex, markerLabel, tone = 'ink', color, className }: AreaChartProps) {\n const values = finite(data.map((d) => (typeof d === 'number' ? d : d.value)));\n if (values.length < 2) return null;\n const stroke = color ?? toneFill(tone);\n\n const { min, max, range } = extent(values);\n const stepX = W / (values.length - 1);\n\n // Expose the series to assistive tech: labelled points when given, else a plain range summary.\n const labelled = data.filter((d) => typeof d !== 'number' && d.label);\n const ariaLabel = labelled.length\n ? (data.map((d, i) => (typeof d === 'number' ? `${values[i]}` : `${d.label} ${d.value}`)).join(', '))\n : `Trend across ${values.length} points, from ${min} to ${max}`;\n const y = (v: number) => TOP + (1 - (v - min) / range) * (height - TOP - BOTTOM);\n\n const pts = values.map((v, i) => [i * stepX, y(v)] as const);\n const line = smooth(pts);\n const area = `${line} L ${W},${height} L 0,${height} Z`;\n\n const marked = markerIndex != null && markerIndex >= 0 && markerIndex < values.length;\n const markLeft = marked ? (markerIndex! / (values.length - 1)) * 100 : 0;\n\n return (\n <div className={cn('relative w-full', className)} style={{ height }} role=\"img\" aria-label={ariaLabel}>\n <svg\n viewBox={`0 0 ${W} ${height}`}\n width=\"100%\"\n height={height}\n preserveAspectRatio=\"none\"\n fill=\"none\"\n aria-hidden=\"true\"\n >\n <path d={area} fill={stroke} fillOpacity={0.1} />\n <path\n d={line}\n stroke={stroke}\n strokeWidth={chartStroke.line}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n vectorEffect=\"non-scaling-stroke\"\n />\n {marked && (\n <line\n x1={markerIndex! * stepX}\n y1={TOP}\n x2={markerIndex! * stepX}\n y2={height}\n stroke={chartToken.axis}\n strokeWidth={chartStroke.guide}\n vectorEffect=\"non-scaling-stroke\"\n />\n )}\n </svg>\n\n {marked && (\n <>\n {/* HTML overlays: undistorted regardless of the horizontal stretch. */}\n <span\n className=\"pointer-events-none absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 bg-surface\"\n style={{ left: `${markLeft}%`, top: y(values[markerIndex!]), borderColor: stroke }}\n aria-hidden=\"true\"\n />\n {markerLabel && (\n <span\n className=\"pointer-events-none absolute top-0 -translate-x-1/2 whitespace-nowrap sv-body-sm font-medium text-on-surface\"\n style={{ left: `${markLeft}%` }}\n >\n {markerLabel}\n </span>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,OAAO,EAAE,OAAO,GAAG,MAAK,OAAM,cAAY,WAC1F;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,OAAO,CAAC,IAAI,MAAM;AAAA,QAC3B,OAAM;AAAA,QACN;AAAA,QACA,qBAAoB;AAAA,QACpB,MAAK;AAAA,QACL,eAAY;AAAA,QAEZ;AAAA,8BAAC,UAAK,GAAG,MAAM,MAAM,QAAQ,aAAa,KAAK;AAAA,UAC/C;AAAA,YAAC;AAAA;AAAA,cACC,GAAG;AAAA,cACH;AAAA,cACA,aAAa,YAAY;AAAA,cACzB,eAAc;AAAA,cACd,gBAAe;AAAA,cACf,cAAa;AAAA;AAAA,UACf;AAAA,UACC,UACC;AAAA,YAAC;AAAA;AAAA,cACC,IAAI,cAAe;AAAA,cACnB,IAAI;AAAA,cACJ,IAAI,cAAe;AAAA,cACnB,IAAI;AAAA,cACJ,QAAQ,WAAW;AAAA,cACnB,aAAa,YAAY;AAAA,cACzB,cAAa;AAAA;AAAA,UACf;AAAA;AAAA;AAAA,IAEJ;AAAA,IAEC,UACC,iCAEE;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,EAAE,MAAM,GAAG,QAAQ,KAAK,KAAK,EAAE,OAAO,WAAY,CAAC,GAAG,aAAa,OAAO;AAAA,UACjF,eAAY;AAAA;AAAA,MACd;AAAA,MACC,eACC;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,EAAE,MAAM,GAAG,QAAQ,IAAI;AAAA,UAE7B;AAAA;AAAA,MACH;AAAA,OAEJ;AAAA,KAEJ;AAEJ;AACA,UAAU,cAAc;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/segmented-bar.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { categorical, categoricalOn, sequential, sequentialOn, chartToken } from './lib/series';\n\nexport interface Segment {\n label: string;\n value: number;\n /** Pull this segment forward (ink) and others recede. */\n active?: boolean;\n}\n\nexport interface SegmentedBarProps {\n data: Segment[];\n /** Bar thickness in px. */\n height?: number;\n /**\n * How segments get colour:\n * - `mono` (default): grayscale, active segment is ink, the rest are muted tints.\n * - `categorical`: the capped unordered palette (≤4 meaningful categories).\n * - `sequential`: single-hue magnitude ramp, in data order.\n */\n scale?: 'mono' | 'categorical' | 'sequential';\n /** Show the label + value row beneath the bar. */\n showLegend?: boolean;\n className?: string;\n}\n\n/**\n * Cairn SegmentedBar, a single horizontal bar split into labelled parts (a share-of-total\n * / stacked bar). Grayscale by default; hue is opt-in via `scale`. Every segment carries a\n * text label + value, so meaning never rests on colour alone (WCAG-safe). Zero-dependency.\n */\nexport function SegmentedBar({ data, height = 40, scale = 'mono', showLegend = true, className }: SegmentedBarProps) {\n // Negative / non-finite segment values would produce invalid or overflowing widths; clamp to 0.\n const safe = (v: number) => (Number.isFinite(v) && v > 0 ? v : 0);\n const total = data.reduce((s, d) => s + safe(d.value), 0) || 1;\n const hasActive = data.some((d) => d.active);\n\n const fill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categorical(i);\n if (scale === 'sequential') return sequential(i, data.length);\n // mono: ink for the active (or all, when none is active), muted tints otherwise.\n if (!hasActive) return chartToken.ink;\n return d.active ? chartToken.ink : chartToken.muted;\n };\n\n // Accessible foreground paired to each fill, WCAG AA, never a blend mode that guesses.\n const onFill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categoricalOn(i);\n if (scale === 'sequential') return sequentialOn(i, data.length);\n // mono: white on ink fills, ink on the light muted tint.\n if (!hasActive) return 'var(--sv-sys-color-on-primary)';\n return d.active ? 'var(--sv-sys-color-on-primary)' : 'var(--sv-sys-color-on-surface)';\n };\n\n // A pale muted segment is < 3:1 vs the surface; a keyline round the bar carries its shape\n // contrast (AGENTS.md rule 9). Only needed in mono when some segment recedes to the muted tint.\n const needsEdge = scale === 'mono' && hasActive;\n\n return (\n <div className={cn('w-full', className)}>\n <div\n className=\"flex w-full overflow-hidden rounded-control\"\n style={{\n height,\n ...(needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: '-1px' } : {}),\n }}\n role=\"img\"\n aria-label={data.map((d) => `${d.label} ${d.value}`).join(', ')}\n >\n {data.map((d, i) => (\n <div\n key={d.label}\n className=\"flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control\"\n style={{ width: `${(safe(d.value) / total) * 100}%`, background: fill(d, i) }}\n >\n <span className=\"truncate sv-body-xs font-medium tabular-nums\" style={{ color: onFill(d, i) }}>{d.value}</span>\n </div>\n ))}\n </div>\n {showLegend && (\n <ul className=\"mt-3 flex flex-wrap gap-x-4 gap-y-1\">\n {data.map((d, i) => (\n <li key={d.label} className={cn('flex items-center gap-1.5 sv-body-sm', d.active ? 'text-on-surface' : 'text-on-surface-variant')}>\n <span className=\"size-2 shrink-0 rounded-swatch\" style={{ background: fill(d, i) }} aria-hidden=\"true\" />\n {d.label}\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n}\nSegmentedBar.displayName = 'SegmentedBar';\n"],"mappings":";;;;;;;;;;;;AA2EY,cAOA,YAPA;AA5CL,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,QAAQ,QAAQ,aAAa,MAAM,UAAU,GAAsB;AAEnH,QAAM,OAAO,CAAC,MAAe,OAAO,SAAS,CAAC,KAAK,IAAI,IAAI,IAAI;AAC/D,QAAM,QAAQ,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,KAAK,GAAG,CAAC,KAAK;AAC7D,QAAM,YAAY,KAAK,KAAK,CAAC,MAAM,EAAE,MAAM;AAE3C,QAAM,OAAO,CAAC,GAAY,MAAsB;AAC9C,QAAI,UAAU,cAAe,QAAO,YAAY,CAAC;AACjD,QAAI,UAAU,aAAc,QAAO,WAAW,GAAG,KAAK,MAAM;AAE5D,QAAI,CAAC,UAAW,QAAO,WAAW;AAClC,WAAO,EAAE,SAAS,WAAW,MAAM,WAAW;AAAA,EAChD;AAGA,QAAM,SA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