@six-vallees/ui-react 0.3.0 → 0.4.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Button,
3
3
  buttonVariants
4
- } from "../chunk-KUKSVVDZ.js";
4
+ } from "../chunk-BWYWI4BC.js";
5
5
  import "../chunk-DXRY7AS4.js";
6
6
  export {
7
7
  Button,
@@ -10,13 +10,13 @@ interface BarChartProps {
10
10
  data: BarDatum[];
11
11
  height?: number;
12
12
  showValue?: boolean;
13
- /** Colour of the promoted bar. Defaults to ink; `accent` uses the categorical blue. */
13
+ /** Colour of the promoted bar. Defaults to ink; `accent` uses the signature accent. */
14
14
  tone?: 'ink' | 'accent';
15
15
  className?: string;
16
16
  }
17
17
  /**
18
18
  * Cairn BarChart, grayscale-first: muted neutral bars, the active bar promoted to ink
19
- * (or the categorical blue via `tone="accent"`) with a value pill. Interactive: hover any
19
+ * (or the signature accent via `tone="accent"`) with a value pill. Interactive: hover any
20
20
  * bar to promote it and reveal its value. Colours resolve from `sys.chart.*` tokens (via
21
21
  * `chartToken`), so a theme swap recolours the chart for free. The chart carries a text
22
22
  * `aria-label` listing every label/value, so the data is never mouse-only (WCAG-safe).
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  BarChart
4
- } from "../chunk-PJRCDPG5.js";
5
- import "../chunk-AOULEGMT.js";
4
+ } from "../chunk-PIFHG2WO.js";
5
+ import "../chunk-TI5GM4IR.js";
6
6
  import "../chunk-DXRY7AS4.js";
7
7
  export {
8
8
  BarChart
@@ -9,7 +9,7 @@
9
9
  */
10
10
  /** Semantic chart roles → their CSS variable. The single place a chart hue is named;
11
11
  * components consume these, never the raw `--sv-sys-chart-*` var. `accent` is the one
12
- * opt-in hue (categorical blue) a fixed-shape chart may promote a value to. */
12
+ * opt-in hue (the signature accent) a fixed-shape chart may promote a value to. */
13
13
  declare const chartToken: {
14
14
  readonly ink: "var(--sv-sys-chart-ink)";
15
15
  readonly muted: "var(--sv-sys-chart-muted)";
@@ -29,7 +29,7 @@ declare const chartStroke: {
29
29
  readonly guide: 1;
30
30
  };
31
31
  /** The mono tone of a chart mark → its `sys.chart.*` colour. `ink` = the single/active series,
32
- * `muted` = a comparison/secondary series, `accent` = the one opt-in hue (categorical blue).
32
+ * `muted` = a comparison/secondary series, `accent` = the one opt-in hue (the signature accent).
33
33
  * The single definition of the `tone` option, shared by every chart in the family. */
34
34
  declare function toneFill(tone: 'ink' | 'muted' | 'accent'): string;
35
35
  /** Colour for category `i` (0-based). Wraps past the cap, pair with a label/pattern. */
@@ -40,5 +40,14 @@ declare function categoricalOn(i: number): string;
40
40
  declare function sequential(i: number, n: number): string;
41
41
  /** WCAG-AA foreground for text drawn on `sequential(i, n)`. */
42
42
  declare function sequentialOn(i: number, n: number): string;
43
+ /** True when `categorical(i)` needs a keyline. */
44
+ declare function categoricalNeedsEdge(i: number): boolean;
45
+ /** True when `sequential(i, n)` needs a keyline. */
46
+ declare function sequentialNeedsEdge(i: number, n: number): boolean;
47
+ /** True when a mono `tone` fill needs a keyline. Only `muted` (neutral.300, 1.6:1) does. */
48
+ declare function toneNeedsEdge(tone: 'ink' | 'muted' | 'accent'): boolean;
49
+ /** The keyline itself, or `undefined` when the mark carries its own contrast. Feed straight to
50
+ * a style `boxShadow`, so a component never hand-writes the inset shadow. */
51
+ declare function markEdge(needed: boolean): string | undefined;
43
52
 
44
- export { CATEGORICAL_MAX, categorical, categoricalOn, chartStroke, chartToken, sequential, sequentialOn, toneFill };
53
+ export { CATEGORICAL_MAX, categorical, categoricalNeedsEdge, categoricalOn, chartStroke, chartToken, markEdge, sequential, sequentialNeedsEdge, sequentialOn, toneFill, toneNeedsEdge };
@@ -1,21 +1,29 @@
1
1
  import {
2
2
  CATEGORICAL_MAX,
3
3
  categorical,
4
+ categoricalNeedsEdge,
4
5
  categoricalOn,
5
6
  chartStroke,
6
7
  chartToken,
8
+ markEdge,
7
9
  sequential,
10
+ sequentialNeedsEdge,
8
11
  sequentialOn,
9
- toneFill
10
- } from "../../chunk-AOULEGMT.js";
12
+ toneFill,
13
+ toneNeedsEdge
14
+ } from "../../chunk-TI5GM4IR.js";
11
15
  export {
12
16
  CATEGORICAL_MAX,
13
17
  categorical,
18
+ categoricalNeedsEdge,
14
19
  categoricalOn,
15
20
  chartStroke,
16
21
  chartToken,
22
+ markEdge,
17
23
  sequential,
24
+ sequentialNeedsEdge,
18
25
  sequentialOn,
19
- toneFill
26
+ toneFill,
27
+ toneNeedsEdge
20
28
  };
21
29
  //# sourceMappingURL=series.js.map
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  LineChart
3
- } from "../chunk-J6QWEIP3.js";
3
+ } from "../chunk-N2DFXOTF.js";
4
4
  import "../chunk-27MWE4F5.js";
5
- import "../chunk-AOULEGMT.js";
5
+ import "../chunk-TI5GM4IR.js";
6
6
  import "../chunk-DXRY7AS4.js";
7
7
  export {
8
8
  LineChart
@@ -7,7 +7,7 @@ interface RingProps {
7
7
  size?: number;
8
8
  /** Ring thickness in px. */
9
9
  thickness?: number;
10
- /** Colour of the filled arc. Defaults to ink; `accent` uses categorical blue. */
10
+ /** Colour of the filled arc. Defaults to ink; `accent` uses the signature accent. */
11
11
  tone?: 'ink' | 'accent';
12
12
  /**
13
13
  * Explicit arc colour (a token / CSS colour), overrides `tone`. Pass only colours that
@@ -16,7 +16,7 @@ interface RingProps {
16
16
  */
17
17
  color?: string;
18
18
  /**
19
- * Draw a darker keyline under the arc so a light, low-contrast colour (acid) stays
19
+ * Draw a darker keyline under the arc so a light, low-contrast colour (a pale accent step) stays
20
20
  * perceptible, the rim carries the 3:1 shape contrast the fill can't (AGENTS.md rule 9).
21
21
  * `true` uses ink; pass a colour (e.g. `sys.color.accent-edge`) for a tonal, in-family rim.
22
22
  */
@@ -31,7 +31,7 @@ interface RingProps {
31
31
  }
32
32
  /**
33
33
  * Cairn Ring, single-value radial progress. Grayscale by default (ink arc on a
34
- * neutral track); `tone="accent"` opts into the categorical blue, or pass an explicit
34
+ * neutral track); `tone="accent"` opts into the signature accent, or pass an explicit
35
35
  * `color`. The arc fills from empty on mount (rounded cap, 12 o'clock, clockwise).
36
36
  * Zero-dependency SVG. A client component (`'use client'`): the mount animation uses state;
37
37
  * pass `animate={false}` to render it statically.
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  Ring
4
- } from "../chunk-X3LG535W.js";
5
- import "../chunk-AOULEGMT.js";
4
+ } from "../chunk-65VQL6R2.js";
5
+ import "../chunk-TI5GM4IR.js";
6
6
  import "../chunk-DXRY7AS4.js";
7
7
  export {
8
8
  Ring
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SegmentedBar
3
- } from "../chunk-OY6MO6QQ.js";
4
- import "../chunk-AOULEGMT.js";
3
+ } from "../chunk-OHY4VIKZ.js";
4
+ import "../chunk-TI5GM4IR.js";
5
5
  import "../chunk-DXRY7AS4.js";
6
6
  export {
7
7
  SegmentedBar
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  chartToken,
5
5
  toneFill
6
- } from "./chunk-AOULEGMT.js";
6
+ } from "./chunk-TI5GM4IR.js";
7
7
  import {
8
8
  cn
9
9
  } from "./chunk-DXRY7AS4.js";
@@ -95,4 +95,4 @@ Ring.displayName = "Ring";
95
95
  export {
96
96
  Ring
97
97
  };
98
- //# sourceMappingURL=chunk-X3LG535W.js.map
98
+ //# sourceMappingURL=chunk-65VQL6R2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/charts/ring.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/utils';\nimport { chartToken, toneFill } from './lib/series';\n\nexport interface RingProps {\n /** Progress, 0-100. */\n value: number;\n /** Outer diameter in px. */\n size?: number;\n /** Ring thickness in px. */\n thickness?: number;\n /** Colour of the filled arc. Defaults to ink; `accent` uses the signature accent. */\n tone?: 'ink' | 'accent';\n /**\n * Explicit arc colour (a token / CSS colour), overrides `tone`. Pass only colours that\n * clear 3:1 against the surface as a thin stroke, ink, blue, or a dark graphite. Acid\n * and mid-gray are fill-only (they fail as a line); see AGENTS.md rule 9.\n */\n color?: string;\n /**\n * Draw a darker keyline under the arc so a light, low-contrast colour (a pale accent step) stays\n * perceptible, the rim carries the 3:1 shape contrast the fill can't (AGENTS.md rule 9).\n * `true` uses ink; pass a colour (e.g. `sys.color.accent-edge`) for a tonal, in-family rim.\n */\n casing?: boolean | string;\n /** Fill the arc from empty on mount. Honours `prefers-reduced-motion`. */\n animate?: boolean;\n /** Centre content, e.g. the value. Omit for a bare ring. */\n children?: React.ReactNode;\n /** Accessible label; falls back to \"<value>%\". */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * Cairn Ring, single-value radial progress. Grayscale by default (ink arc on a\n * neutral track); `tone=\"accent\"` opts into the signature accent, or pass an explicit\n * `color`. The arc fills from empty on mount (rounded cap, 12 o'clock, clockwise).\n * Zero-dependency SVG. A client component (`'use client'`): the mount animation uses state;\n * pass `animate={false}` to render it statically.\n */\nexport function Ring({\n value,\n size = 160,\n thickness = 14,\n tone = 'ink',\n color,\n casing = false,\n animate = true,\n children,\n className,\n 'aria-label': ariaLabel,\n}: RingProps) {\n const pct = Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), 100);\n const r = (size - thickness) / 2;\n const c = 2 * Math.PI * r;\n\n // Fill from empty on mount: first client paint is 0, then rAF advances to the value so the\n // CSS transition animates. Under prefers-reduced-motion we jump straight to the value with the\n // transition removed — self-contained, never relying on a global reduced-motion rule existing.\n const [progress, setProgress] = React.useState(animate ? 0 : pct);\n const [instant, setInstant] = React.useState(!animate);\n React.useEffect(() => {\n if (!animate) {\n setProgress(pct);\n return;\n }\n const reduce =\n typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n if (reduce) {\n setInstant(true);\n setProgress(pct);\n return;\n }\n setInstant(false);\n const id = requestAnimationFrame(() => setProgress(pct));\n return () => cancelAnimationFrame(id);\n }, [pct, animate]);\n\n const arc = (progress / 100) * c;\n const motion = instant ? undefined : 'transition-[stroke-dasharray] duration-[900ms] ease-out';\n const stroke = color ?? toneFill(tone);\n return (\n <div\n className={cn('relative inline-grid place-items-center', className)}\n style={{ width: size, height: size }}\n role=\"img\"\n aria-label={ariaLabel ?? `${Math.round(pct)}%`}\n >\n <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"rotate-[-90deg]\" aria-hidden=\"true\">\n <circle cx={size / 2} cy={size / 2} r={r} fill=\"none\" stroke={chartToken.track} strokeWidth={thickness} />\n {casing && (\n <circle\n cx={size / 2}\n cy={size / 2}\n r={r}\n fill=\"none\"\n stroke={typeof casing === 'string' ? casing : 'var(--sv-sys-color-on-surface)'}\n strokeWidth={thickness + 2}\n strokeLinecap=\"round\"\n strokeDasharray={`${arc} ${c - arc}`}\n className={motion}\n />\n )}\n <circle\n cx={size / 2}\n cy={size / 2}\n r={r}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={thickness}\n strokeLinecap=\"round\"\n strokeDasharray={`${arc} ${c - arc}`}\n className={motion}\n />\n </svg>\n {children != null && <div className=\"absolute inset-0 grid place-items-center\">{children}</div>}\n </div>\n );\n}\nRing.displayName = 'Ring';\n"],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AAyFjB,SACE,KADF;AAhDC,SAAS,KAAK;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAAc;AACZ,QAAM,MAAM,KAAK,IAAI,KAAK,IAAI,OAAO,SAAS,KAAK,IAAI,QAAQ,GAAG,CAAC,GAAG,GAAG;AACzE,QAAM,KAAK,OAAO,aAAa;AAC/B,QAAM,IAAI,IAAI,KAAK,KAAK;AAKxB,QAAM,CAAC,UAAU,WAAW,IAAU,eAAS,UAAU,IAAI,GA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AA;AAAA,cACC,IAAI,OAAO;AAAA,cACX,IAAI,OAAO;AAAA,cACX;AAAA,cACA,MAAK;AAAA,cACL;AAAA,cACA,aAAa;AAAA,cACb,eAAc;AAAA,cACd,iBAAiB,GAAG,GAAG,IAAI,IAAI,GAAG;AAAA,cAClC,WAAW;AAAA;AAAA,UACb;AAAA,WACF;AAAA,QACC,YAAY,QAAQ,oBAAC,SAAI,WAAU,4CAA4C,UAAS;AAAA;AAAA;AAAA,EAC3F;AAEJ;AACA,KAAK,cAAc;","names":[]}
@@ -10,14 +10,14 @@ import { jsx } from "react/jsx-runtime";
10
10
  var buttonVariants = cva(
11
11
  // A soft accent halo on hover (a fill-grade ring in `accent-halo`, box-shadow so it never shifts
12
12
  // layout and coexists with the focus-visible outline). Disabled buttons can't hover, so no halo.
13
- "inline-flex items-center justify-center gap-2 leading-none rounded-control font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow,filter] duration-150 outline-none hover:[box-shadow:0_0_0_4px_var(--sv-sys-color-accent-halo)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:pointer-events-none disabled:opacity-40",
13
+ "inline-flex items-center justify-center gap-2 leading-none rounded-control font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow] duration-150 outline-none hover:[box-shadow:0_0_0_4px_var(--sv-sys-color-accent-halo)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:pointer-events-none disabled:opacity-40",
14
14
  {
15
15
  variants: {
16
16
  variant: {
17
- primary: "bg-primary text-on-primary hover:bg-primary-hover active:brightness-90",
17
+ primary: "bg-primary text-on-primary hover:bg-primary-hover active:bg-primary-active",
18
18
  secondary: "border border-outline-strong bg-surface text-on-surface hover:bg-surface-subtle active:bg-surface-muted",
19
19
  ghost: "text-on-surface hover:bg-surface-subtle active:bg-surface-muted",
20
- danger: "bg-danger text-on-danger hover:brightness-95 active:brightness-90"
20
+ danger: "bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active"
21
21
  },
22
22
  size: {
23
23
  sm: "h-9 px-3 text-sm",
@@ -40,4 +40,4 @@ export {
40
40
  buttonVariants,
41
41
  Button
42
42
  };
43
- //# sourceMappingURL=chunk-KUKSVVDZ.js.map
43
+ //# sourceMappingURL=chunk-BWYWI4BC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/button/button.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { cn } from '@/lib/utils';\n\n/**\n * Cairn Button. Consumes the design tokens through the Tailwind bridge\n * (bg-primary, rounded-control, …), install the Cairn theme in the target project.\n */\nconst buttonVariants = cva(\n // A soft accent halo on hover (a fill-grade ring in `accent-halo`, box-shadow so it never shifts\n // layout and coexists with the focus-visible outline). Disabled buttons can't hover, so no halo.\n 'inline-flex items-center justify-center gap-2 leading-none rounded-control font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow] duration-150 outline-none hover:[box-shadow:0_0_0_4px_var(--sv-sys-color-accent-halo)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:pointer-events-none disabled:opacity-40',\n {\n variants: {\n variant: {\n primary: 'bg-primary text-on-primary hover:bg-primary-hover active:bg-primary-active',\n secondary:\n 'border border-outline-strong bg-surface text-on-surface hover:bg-surface-subtle active:bg-surface-muted',\n ghost: 'text-on-surface hover:bg-surface-subtle active:bg-surface-muted',\n danger: 'bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active',\n },\n size: {\n sm: 'h-9 px-3 text-sm',\n md: 'h-11 px-5 text-sm',\n lg: 'h-12 px-6 text-base',\n },\n },\n defaultVariants: { variant: 'primary', size: 'md' },\n }\n);\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n /** Visual style of the button. */\n variant?: 'primary' | 'secondary' | 'ghost' | 'danger';\n /** Control height and padding. */\n size?: 'sm' | 'md' | 'lg';\n /** Render as the child element (e.g. an `<a>`) instead of a `<button>`. */\n asChild?: boolean;\n}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : 'button';\n return (\n <Comp ref={ref} className={cn(buttonVariants({ variant, size }), className)} {...props} />\n );\n }\n);\nButton.displayName = 'Button';\n\nexport { buttonVariants };\n"],"mappings":";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,WAA8B;AA6CjC;AAtCN,IAAM,iBAAiB;AAAA;AAAA;AAAA,EAGrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WACE;AAAA,QACF,OAAO;AAAA,QACP,QAAQ;AAAA,MACV;AAAA,MACA,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB,EAAE,SAAS,WAAW,MAAM,KAAK;AAAA,EACpD;AACF;AAaO,IAAM,SAAe;AAAA,EAC1B,CAAC,EAAE,WAAW,SAAS,MAAM,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAChE,UAAM,OAAO,UAAU,OAAO;AAC9B,WACE,oBAAC,QAAK,KAAU,WAAW,GAAG,eAAe,EAAE,SAAS,KAAK,CAAC,GAAG,SAAS,GAAI,GAAG,OAAO;AAAA,EAE5F;AACF;AACA,OAAO,cAAc;","names":[]}
@@ -7,7 +7,7 @@ import {
7
7
  chartStroke,
8
8
  chartToken,
9
9
  toneFill
10
- } from "./chunk-AOULEGMT.js";
10
+ } from "./chunk-TI5GM4IR.js";
11
11
  import {
12
12
  cn
13
13
  } from "./chunk-DXRY7AS4.js";
@@ -88,4 +88,4 @@ LineChart.displayName = "LineChart";
88
88
  export {
89
89
  LineChart
90
90
  };
91
- //# sourceMappingURL=chunk-J6QWEIP3.js.map
91
+ //# sourceMappingURL=chunk-N2DFXOTF.js.map
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  categorical,
3
+ categoricalNeedsEdge,
3
4
  categoricalOn,
4
5
  chartToken,
6
+ markEdge,
5
7
  sequential,
6
- sequentialOn
7
- } from "./chunk-AOULEGMT.js";
8
+ sequentialNeedsEdge,
9
+ sequentialOn,
10
+ toneNeedsEdge
11
+ } from "./chunk-TI5GM4IR.js";
8
12
  import {
9
13
  cn
10
14
  } from "./chunk-DXRY7AS4.js";
@@ -27,23 +31,28 @@ function SegmentedBar({ data, height = 40, scale = "mono", showLegend = true, cl
27
31
  if (!hasActive) return "var(--sv-sys-color-on-primary)";
28
32
  return d.active ? "var(--sv-sys-color-on-primary)" : "var(--sv-sys-color-on-surface)";
29
33
  };
30
- const needsEdge = scale === "mono" && hasActive;
34
+ const edge = (d, i) => {
35
+ if (scale === "categorical") return markEdge(categoricalNeedsEdge(i));
36
+ if (scale === "sequential") return markEdge(sequentialNeedsEdge(i, data.length));
37
+ return markEdge(toneNeedsEdge(!hasActive || d.active ? "ink" : "muted"));
38
+ };
31
39
  return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
32
40
  /* @__PURE__ */ jsx(
33
41
  "div",
34
42
  {
35
- className: "flex w-full overflow-hidden rounded-control",
36
- style: {
37
- height,
38
- ...needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: "-1px" } : {}
39
- },
43
+ className: "flex w-full",
44
+ style: { height, gap: 2 },
40
45
  role: "img",
41
46
  "aria-label": data.map((d) => `${d.label} ${d.value}`).join(", "),
42
47
  children: data.map((d, i) => /* @__PURE__ */ jsx(
43
48
  "div",
44
49
  {
45
50
  className: "flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control",
46
- style: { width: `${safe(d.value) / total * 100}%`, background: fill(d, i) },
51
+ style: {
52
+ width: `${safe(d.value) / total * 100}%`,
53
+ background: fill(d, i),
54
+ boxShadow: edge(d, i)
55
+ },
47
56
  children: /* @__PURE__ */ jsx("span", { className: "truncate sv-body-xs font-medium tabular-nums", style: { color: onFill(d, i) }, children: d.value })
48
57
  },
49
58
  d.label
@@ -61,4 +70,4 @@ SegmentedBar.displayName = "SegmentedBar";
61
70
  export {
62
71
  SegmentedBar
63
72
  };
64
- //# sourceMappingURL=chunk-OY6MO6QQ.js.map
73
+ //# sourceMappingURL=chunk-OHY4VIKZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/charts/segmented-bar.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport {\n categorical, categoricalOn, categoricalNeedsEdge,\n sequential, sequentialOn, sequentialNeedsEdge,\n toneNeedsEdge, markEdge, chartToken,\n} 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 keyline only where the fill cannot carry its own 3:1 shape contrast. Dark and saturated\n // segments get none: boxing every segment turns the bar into a table (rule 9, AGENTS.md).\n const edge = (d: Segment, i: number): string | undefined => {\n if (scale === 'categorical') return markEdge(categoricalNeedsEdge(i));\n if (scale === 'sequential') return markEdge(sequentialNeedsEdge(i, data.length));\n return markEdge(toneNeedsEdge(!hasActive || d.active ? 'ink' : 'muted'));\n };\n\n return (\n <div className={cn('w-full', className)}>\n {/* A thin gap separates adjacent segments, so the keyline is not needed for that job: it\n appears only under a pale fill, which cannot carry the 3:1 shape contrast against the\n surface 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: edge(d, i),\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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AAQ,KAAK,EAAE;AAAA,QACxB,MAAK;AAAA,QACL,cAAY,KAAK,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,IAAI;AAAA,QAE7D,eAAK,IAAI,CAAC,GAAG,MACZ;AAAA,UAAC;AAAA;AAAA,YAEC,WAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO,GAAI,KAAK,EAAE,KAAK,IAAI,QAAS,GAAG;AAAA,cACvC,YAAY,KAAK,GAAG,CAAC;AAAA,cACrB,WAAW,KAAK,GAAG,CAAC;AAAA,YACtB;AAAA,YAEA,8BAAC,UAAK,WAAU,gDAA+C,OAAO,EAAE,OAAO,OAAO,GAAG,CAAC,EAAE,GAAI,YAAE,OAAM;AAAA;AAAA,UARnG,EAAE;AAAA,QAST,CACD;AAAA;AAAA,IACH;AAAA,IACC,cACC,oBAAC,QAAG,WAAU,uCACX,eAAK,IAAI,CAAC,GAAG,MACZ,qBAAC,QAAiB,WAAW,GAAG,wCAAwC,EAAE,SAAS,oBAAoB,yBAAyB,GAC9H;AAAA,0BAAC,UAAK,WAAU,kCAAiC,OAAO,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,GAAG,eAAY,QAAO;AAAA,MACtG,EAAE;AAAA,SAFI,EAAE,KAGX,CACD,GACH;AAAA,KAEJ;AAEJ;AACA,aAAa,cAAc;","names":[]}
@@ -2,8 +2,9 @@
2
2
 
3
3
  import {
4
4
  chartToken,
5
+ markEdge,
5
6
  toneFill
6
- } from "./chunk-AOULEGMT.js";
7
+ } from "./chunk-TI5GM4IR.js";
7
8
  import {
8
9
  cn
9
10
  } from "./chunk-DXRY7AS4.js";
@@ -56,9 +57,9 @@ function BarChart({ data, height = 200, showValue = true, tone = "ink", classNam
56
57
  style: {
57
58
  height: `${Math.max(2, h / max * 100)}%`,
58
59
  background: on ? activeFill : mutedFill,
59
- // The pale muted fill is < 3:1 vs the surface; a keyline carries the mark's
60
- // shape contrast (AGENTS.md rule 9). Active (ink) bars already clear 3:1.
61
- boxShadow: on ? void 0 : `inset 0 0 0 1px ${chartToken.markEdge}`
60
+ // Only the pale muted fill (< 3:1 vs the surface) takes a keyline; the active
61
+ // ink bar carries its own shape contrast and stays bare (AGENTS.md rule 9).
62
+ boxShadow: markEdge(!on)
62
63
  }
63
64
  }
64
65
  )
@@ -86,4 +87,4 @@ BarChart.displayName = "BarChart";
86
87
  export {
87
88
  BarChart
88
89
  };
89
- //# sourceMappingURL=chunk-PJRCDPG5.js.map
90
+ //# sourceMappingURL=chunk-PIFHG2WO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/charts/bar-chart.tsx"],"sourcesContent":["'use client';\nimport * as React from 'react';\nimport { cn } from '@/lib/utils';\nimport { chartToken, toneFill, markEdge } from './lib/series';\n\nexport interface BarDatum {\n label: string;\n value: number;\n /** Highlight this bar (ink) and show its value by default. */\n active?: boolean;\n}\n\nexport interface BarChartProps {\n data: BarDatum[];\n height?: number;\n showValue?: boolean;\n /** Colour of the promoted bar. Defaults to ink; `accent` uses the signature accent. */\n tone?: 'ink' | 'accent';\n className?: string;\n}\n\n/**\n * Cairn BarChart, grayscale-first: muted neutral bars, the active bar promoted to ink\n * (or the signature accent via `tone=\"accent\"`) with a value pill. Interactive: hover any\n * bar to promote it and reveal its value. Colours resolve from `sys.chart.*` tokens (via\n * `chartToken`), so a theme swap recolours the chart for free. The chart carries a text\n * `aria-label` listing every label/value, so the data is never mouse-only (WCAG-safe).\n */\nexport function BarChart({ data, height = 200, showValue = true, tone = 'ink', className }: BarChartProps) {\n const max = Math.max(...data.map((d) => (Number.isFinite(d.value) ? d.value : 0)), 1);\n const [hover, setHover] = React.useState<number | null>(null);\n\n const activeFill = toneFill(tone);\n const mutedFill = chartToken.muted;\n\n return (\n <div className={cn('w-full', className)} role=\"group\" aria-label=\"Bar chart\">\n <div className=\"flex items-end gap-2\" style={{ height }} onMouseLeave={() => setHover(null)}>\n {data.map((d, i) => {\n const on = d.active || hover === i;\n const dim = hover != null && hover !== i;\n const h = Number.isFinite(d.value) ? d.value : 0;\n return (\n // Each bar is a focusable graphical object: keyboard + screen-reader parity with hover,\n // so its value is never mouse-only (rule 9). Focus mirrors hover to reveal the pill.\n <div\n key={d.label}\n role=\"img\"\n aria-label={`${d.label}: ${d.value}`}\n tabIndex={0}\n className=\"flex h-full flex-1 flex-col items-center justify-end gap-2 rounded-control outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus\"\n onMouseEnter={() => setHover(i)}\n onFocus={() => setHover(i)}\n onBlur={() => setHover(null)}\n >\n <span\n className={cn(\n 'rounded-pill px-2 py-0.5 sv-body-xs font-medium tabular-nums transition-opacity duration-150',\n on && showValue ? 'opacity-100' : 'opacity-0'\n )}\n style={{ background: activeFill, color: 'var(--sv-sys-color-on-primary)' }}\n >\n {d.value}\n </span>\n <div\n className={cn(\n 'w-full rounded-t-control transition-[height,background-color,opacity] duration-500 ease-out',\n dim && 'opacity-60'\n )}\n style={{\n height: `${Math.max(2, (h / max) * 100)}%`,\n background: on ? activeFill : mutedFill,\n // Only the pale muted fill (< 3:1 vs the surface) takes a keyline; the active\n // ink bar carries its own shape contrast and stays bare (AGENTS.md rule 9).\n boxShadow: markEdge(!on),\n }}\n />\n </div>\n );\n })}\n </div>\n <div className=\"mt-3 flex gap-2\" aria-hidden=\"true\">\n {data.map((d, i) => (\n <span\n key={d.label}\n className={cn(\n 'flex-1 text-center sv-body-sm transition-colors',\n d.active || hover === i ? 'text-on-surface' : 'text-on-surface-variant'\n )}\n >\n {d.label}\n </span>\n ))}\n </div>\n </div>\n );\n}\nBarChart.displayName = 'BarChart';\n"],"mappings":";;;;;;;;;;AACA,YAAY,WAAW;AA4CX,SAUE,KAVF;AAjBL,SAAS,SAAS,EAAE,MAAM,SAAS,KAAK,YAAY,MAAM,OAAO,OAAO,UAAU,GAAkB;AACzG,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,MAAO,OAA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B;AAAA;AAAA,cACF;AAAA;AAAA;AAAA,UA9BK,EAAE;AAAA,QA+BT;AAAA;AAAA,IAEJ,CAAC,GACH;AAAA,IACA,oBAAC,SAAI,WAAU,mBAAkB,eAAY,QAC1C,eAAK,IAAI,CAAC,GAAG,MACZ;AAAA,MAAC;AAAA;AAAA,QAEC,WAAW;AAAA,UACT;AAAA,UACA,EAAE,UAAU,UAAU,IAAI,oBAAoB;AAAA,QAChD;AAAA,QAEC,YAAE;AAAA;AAAA,MANE,EAAE;AAAA,IAOT,CACD,GACH;AAAA,KACF;AAEJ;AACA,SAAS,cAAc;","names":[]}
@@ -24,25 +24,25 @@ var SEQUENTIAL = [
24
24
  var CATEGORICAL_MAX = CATEGORICAL.length;
25
25
  var CATEGORICAL_ON = [
26
26
  "var(--sv-sys-color-on-primary)",
27
- // white, on ink
27
+ // white, on neutral.900 (16.6:1)
28
28
  "var(--sv-sys-color-on-primary)",
29
- // white, on blue.600 (5.2:1)
29
+ // white, on main.700 (6.0:1)
30
30
  "var(--sv-sys-color-on-surface)",
31
- // ink, on acid.400 (16:1)
31
+ // ink, on neutral.400 (7.0:1)
32
32
  "var(--sv-sys-color-on-surface)"
33
- // ink, on neutral.400 (5.6:1)
33
+ // ink, on main.300 (6.9:1)
34
34
  ];
35
35
  var SEQUENTIAL_ON = [
36
36
  "var(--sv-sys-color-on-surface)",
37
- // ink, on blue.100
37
+ // ink, on main.100 (12.4:1)
38
38
  "var(--sv-sys-color-on-surface)",
39
- // ink, on blue.300
40
- "var(--sv-sys-color-on-primary)",
41
- // white, on blue.500 (4.8:1)
39
+ // ink, on main.300 (6.9:1)
40
+ "var(--sv-sys-color-on-surface)",
41
+ // ink, on main.500 (4.8:1)
42
42
  "var(--sv-sys-color-on-primary)",
43
- // white, on blue.700
43
+ // white, on main.700 (6.0:1)
44
44
  "var(--sv-sys-color-on-primary)"
45
- // white, on blue.900
45
+ // white, on main.900 (11.4:1)
46
46
  ];
47
47
  var chartStroke = { line: 2, guide: 1 };
48
48
  function toneFill(tone) {
@@ -64,6 +64,20 @@ function sequential(i, n) {
64
64
  function sequentialOn(i, n) {
65
65
  return SEQUENTIAL_ON[rampIndex(i, n)];
66
66
  }
67
+ var CATEGORICAL_PALE = [false, false, true, true];
68
+ var SEQUENTIAL_PALE = [true, true, false, false, false];
69
+ function categoricalNeedsEdge(i) {
70
+ return CATEGORICAL_PALE[wrap(i, CATEGORICAL_MAX)];
71
+ }
72
+ function sequentialNeedsEdge(i, n) {
73
+ return SEQUENTIAL_PALE[rampIndex(i, n)];
74
+ }
75
+ function toneNeedsEdge(tone) {
76
+ return tone === "muted";
77
+ }
78
+ function markEdge(needed) {
79
+ return needed ? `inset 0 0 0 1px ${chartToken.markEdge}` : void 0;
80
+ }
67
81
 
68
82
  export {
69
83
  chartToken,
@@ -73,6 +87,10 @@ export {
73
87
  categorical,
74
88
  categoricalOn,
75
89
  sequential,
76
- sequentialOn
90
+ sequentialOn,
91
+ categoricalNeedsEdge,
92
+ sequentialNeedsEdge,
93
+ toneNeedsEdge,
94
+ markEdge
77
95
  };
78
- //# sourceMappingURL=chunk-AOULEGMT.js.map
96
+ //# sourceMappingURL=chunk-TI5GM4IR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/charts/lib/series.ts"],"sourcesContent":["/**\n * Cairn data-viz colour, the single place a series gets a colour.\n *\n * Rule: grayscale first. A single series is `ink`; a comparison series is `muted`.\n * Reach for hue only when categories are genuinely unordered (`categorical`, capped\n * at 4) or encode magnitude (`sequential`, single-hue). Never hand-pick a hex, every\n * value here is a `sys.chart.*` token resolved at runtime via its CSS variable, so a\n * theme swap (light↔dark) recolours the charts for free.\n */\n\n/** Semantic chart roles → their CSS variable. The single place a chart hue is named;\n * components consume these, never the raw `--sv-sys-chart-*` var. `accent` is the one\n * opt-in hue (the signature accent) a fixed-shape chart may promote a value to. */\nexport const chartToken = {\n ink: 'var(--sv-sys-chart-ink)',\n muted: 'var(--sv-sys-chart-muted)',\n markEdge: 'var(--sv-sys-chart-mark-edge)',\n accent: 'var(--sv-sys-chart-categorical-2)',\n grid: 'var(--sv-sys-chart-grid)',\n axis: 'var(--sv-sys-chart-axis)',\n track: 'var(--sv-sys-chart-track)',\n} as const;\n\n/** The unordered-category palette. HARD CAP at 4, a 5th category needs a pattern or\n * label, never a 5th hue. Indices wrap so a longer series degrades loudly, not silently. */\nconst CATEGORICAL = [\n 'var(--sv-sys-chart-categorical-1)',\n 'var(--sv-sys-chart-categorical-2)',\n 'var(--sv-sys-chart-categorical-3)',\n 'var(--sv-sys-chart-categorical-4)',\n] as const;\n\n/** Single-hue magnitude ramp (low → high). */\nconst SEQUENTIAL = [\n 'var(--sv-sys-chart-sequential-1)',\n 'var(--sv-sys-chart-sequential-2)',\n 'var(--sv-sys-chart-sequential-3)',\n 'var(--sv-sys-chart-sequential-4)',\n 'var(--sv-sys-chart-sequential-5)',\n] as const;\n\nexport const CATEGORICAL_MAX = CATEGORICAL.length;\n\n/** Accessible foreground for text/marks laid ON each categorical fill. Every pair below\n * clears WCAG AA (≥4.5:1). The accent category is main.700, not the brand main.600: a chart\n * fill carries a small value label, and 600 only clears the 3:1 large-text bar (ink 4.35:1).\n * Index-matched to CATEGORICAL, never guess contrast at runtime. */\nconst CATEGORICAL_ON = [\n 'var(--sv-sys-color-on-primary)', // white, on neutral.900 (16.6:1)\n 'var(--sv-sys-color-on-primary)', // white, on main.700 (6.0:1)\n 'var(--sv-sys-color-on-surface)', // ink, on neutral.400 (7.0:1)\n 'var(--sv-sys-color-on-surface)', // ink, on main.300 (6.9:1)\n] as const;\n\n/** Accessible foreground per sequential step. The ramp is the accent, so it stays legible\n * under ink further up than a blue ramp would: main.100/300/500 take ink, only the darker\n * main.700/900 take white. Index-matched to SEQUENTIAL. */\nconst SEQUENTIAL_ON = [\n 'var(--sv-sys-color-on-surface)', // ink, on main.100 (12.4:1)\n 'var(--sv-sys-color-on-surface)', // ink, on main.300 (6.9:1)\n 'var(--sv-sys-color-on-surface)', // ink, on main.500 (4.8:1)\n 'var(--sv-sys-color-on-primary)', // white, on main.700 (6.0:1)\n 'var(--sv-sys-color-on-primary)', // white, on main.900 (11.4:1)\n] as const;\n\n/** Chart line-mark weights, in px. The single stroke scale for the family: every line mark\n * (sparkline, area line, trend line) uses `line`; reference/guide lines use `guide`. Radial\n * gauges (Ring) set their own arc thickness. Lives here beside `chartToken` so the whole\n * chart visual language (colour + stroke) has one home. */\nexport const chartStroke = { line: 2, guide: 1 } as const;\n\n/** The mono tone of a chart mark → its `sys.chart.*` colour. `ink` = the single/active series,\n * `muted` = a comparison/secondary series, `accent` = the one opt-in hue (the signature accent).\n * The single definition of the `tone` option, shared by every chart in the family. */\nexport function toneFill(tone: 'ink' | 'muted' | 'accent'): string {\n if (tone === 'accent') return chartToken.accent;\n if (tone === 'muted') return chartToken.muted;\n return chartToken.ink;\n}\n\nconst wrap = (i: number, n: number) => ((i % n) + n) % n;\nconst rampIndex = (i: number, n: number) =>\n n <= 1 ? SEQUENTIAL.length - 1 : Math.round(Math.min(Math.max(i / (n - 1), 0), 1) * (SEQUENTIAL.length - 1));\n\n/** Colour for category `i` (0-based). Wraps past the cap, pair with a label/pattern. */\nexport function categorical(i: number): string {\n return CATEGORICAL[wrap(i, CATEGORICAL_MAX)];\n}\n\n/** WCAG-AA foreground for text drawn on `categorical(i)`. */\nexport function categoricalOn(i: number): string {\n return CATEGORICAL_ON[wrap(i, CATEGORICAL_MAX)];\n}\n\n/** Colour for the `i`-th of `n` steps on the single-hue magnitude ramp. */\nexport function sequential(i: number, n: number): string {\n return SEQUENTIAL[rampIndex(i, n)];\n}\n\n/** WCAG-AA foreground for text drawn on `sequential(i, n)`. */\nexport function sequentialOn(i: number, n: number): string {\n return SEQUENTIAL_ON[rampIndex(i, n)];\n}\n\n/** Which fills sit under 3:1 against the surface and therefore need a `mark-edge` keyline to\n * carry their shape contrast (rule 9). Everything else already clears 3:1 on its own and takes\n * **no border at all**: a keyline on a dark or saturated fill is decoration, not accessibility,\n * and a chart where every mark is boxed reads as a table, not as data. Measured per value,\n * index-matched, never guessed at runtime.\n *\n * categorical: neutral.900 (16.6:1), main.700 (6.0:1) carry themselves; neutral.400 (2.6:1) and\n * main.300 (2.6:1) do not. sequential: main.100 (1.4:1) and main.300 (2.6:1) do not; main.500\n * (3.7:1) upward do. */\nconst CATEGORICAL_PALE = [false, false, true, true] as const;\nconst SEQUENTIAL_PALE = [true, true, false, false, false] as const;\n\n/** True when `categorical(i)` needs a keyline. */\nexport function categoricalNeedsEdge(i: number): boolean {\n return CATEGORICAL_PALE[wrap(i, CATEGORICAL_MAX)];\n}\n\n/** True when `sequential(i, n)` needs a keyline. */\nexport function sequentialNeedsEdge(i: number, n: number): boolean {\n return SEQUENTIAL_PALE[rampIndex(i, n)];\n}\n\n/** True when a mono `tone` fill needs a keyline. Only `muted` (neutral.300, 1.6:1) does. */\nexport function toneNeedsEdge(tone: 'ink' | 'muted' | 'accent'): boolean {\n return tone === 'muted';\n}\n\n/** The keyline itself, or `undefined` when the mark carries its own contrast. Feed straight to\n * a style `boxShadow`, so a component never hand-writes the inset shadow. */\nexport function markEdge(needed: boolean): string | undefined {\n return needed ? `inset 0 0 0 1px ${chartToken.markEdge}` : undefined;\n}\n"],"mappings":";AAaO,IAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAIA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,kBAAkB,YAAY;AAM3C,IAAM,iBAAiB;AAAA,EACrB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF;AAKA,IAAM,gBAAgB;AAAA,EACpB;AAAA;AAAA,EACA;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12
  buttonVariants
13
- } from "./chunk-KUKSVVDZ.js";
13
+ } from "./chunk-BWYWI4BC.js";
14
14
  import {
15
15
  Card,
16
16
  CardContent,
@@ -21,17 +21,17 @@ import {
21
21
  } from "./chunk-7GXL7U5X.js";
22
22
  import {
23
23
  BarChart
24
- } from "./chunk-PJRCDPG5.js";
24
+ } from "./chunk-PIFHG2WO.js";
25
25
  import {
26
26
  LineChart
27
- } from "./chunk-J6QWEIP3.js";
27
+ } from "./chunk-N2DFXOTF.js";
28
28
  import "./chunk-27MWE4F5.js";
29
29
  import {
30
30
  Ring
31
- } from "./chunk-X3LG535W.js";
31
+ } from "./chunk-65VQL6R2.js";
32
32
  import {
33
33
  SegmentedBar
34
- } from "./chunk-OY6MO6QQ.js";
34
+ } from "./chunk-OHY4VIKZ.js";
35
35
  import {
36
36
  CATEGORICAL_MAX,
37
37
  categorical,
@@ -41,7 +41,7 @@ import {
41
41
  sequential,
42
42
  sequentialOn,
43
43
  toneFill
44
- } from "./chunk-AOULEGMT.js";
44
+ } from "./chunk-TI5GM4IR.js";
45
45
  import {
46
46
  Stat
47
47
  } from "./chunk-XGYKA3GE.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@six-vallees/ui-react",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Cairn React components — the Six Vallées design system UI, driven by the Cairn tokens.",
6
6
  "license": "UNLICENSED",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/charts/lib/series.ts"],"sourcesContent":["/**\n * Cairn data-viz colour, the single place a series gets a colour.\n *\n * Rule: grayscale first. A single series is `ink`; a comparison series is `muted`.\n * Reach for hue only when categories are genuinely unordered (`categorical`, capped\n * at 4) or encode magnitude (`sequential`, single-hue). Never hand-pick a hex, every\n * value here is a `sys.chart.*` token resolved at runtime via its CSS variable, so a\n * theme swap (light↔dark) recolours the charts for free.\n */\n\n/** Semantic chart roles → their CSS variable. The single place a chart hue is named;\n * components consume these, never the raw `--sv-sys-chart-*` var. `accent` is the one\n * opt-in hue (categorical blue) a fixed-shape chart may promote a value to. */\nexport const chartToken = {\n ink: 'var(--sv-sys-chart-ink)',\n muted: 'var(--sv-sys-chart-muted)',\n markEdge: 'var(--sv-sys-chart-mark-edge)',\n accent: 'var(--sv-sys-chart-categorical-2)',\n grid: 'var(--sv-sys-chart-grid)',\n axis: 'var(--sv-sys-chart-axis)',\n track: 'var(--sv-sys-chart-track)',\n} as const;\n\n/** The unordered-category palette. HARD CAP at 4, a 5th category needs a pattern or\n * label, never a 5th hue. Indices wrap so a longer series degrades loudly, not silently. */\nconst CATEGORICAL = [\n 'var(--sv-sys-chart-categorical-1)',\n 'var(--sv-sys-chart-categorical-2)',\n 'var(--sv-sys-chart-categorical-3)',\n 'var(--sv-sys-chart-categorical-4)',\n] as const;\n\n/** Single-hue magnitude ramp (low → high). */\nconst SEQUENTIAL = [\n 'var(--sv-sys-chart-sequential-1)',\n 'var(--sv-sys-chart-sequential-2)',\n 'var(--sv-sys-chart-sequential-3)',\n 'var(--sv-sys-chart-sequential-4)',\n 'var(--sv-sys-chart-sequential-5)',\n] as const;\n\nexport const CATEGORICAL_MAX = CATEGORICAL.length;\n\n/** Accessible foreground for text/marks laid ON each categorical fill. Every pair below\n * clears WCAG AA (≥4.5:1): white on the dark fills (ink, blue.600), ink on the light ones\n * (acid.400, neutral.400). Index-matched to CATEGORICAL, never guess contrast at runtime. */\nconst CATEGORICAL_ON = [\n 'var(--sv-sys-color-on-primary)', // white, on ink\n 'var(--sv-sys-color-on-primary)', // white, on blue.600 (5.2:1)\n 'var(--sv-sys-color-on-surface)', // ink, on acid.400 (16:1)\n 'var(--sv-sys-color-on-surface)', // ink, on neutral.400 (5.6:1)\n] as const;\n\n/** Accessible foreground per sequential step. Light steps (blue.100/300) take ink; the\n * darker half (blue.500/700/900) takes white. Index-matched to SEQUENTIAL. */\nconst SEQUENTIAL_ON = [\n 'var(--sv-sys-color-on-surface)', // ink, on blue.100\n 'var(--sv-sys-color-on-surface)', // ink, on blue.300\n 'var(--sv-sys-color-on-primary)', // white, on blue.500 (4.8:1)\n 'var(--sv-sys-color-on-primary)', // white, on blue.700\n 'var(--sv-sys-color-on-primary)', // white, on blue.900\n] as const;\n\n/** Chart line-mark weights, in px. The single stroke scale for the family: every line mark\n * (sparkline, area line, trend line) uses `line`; reference/guide lines use `guide`. Radial\n * gauges (Ring) set their own arc thickness. Lives here beside `chartToken` so the whole\n * chart visual language (colour + stroke) has one home. */\nexport const chartStroke = { line: 2, guide: 1 } as const;\n\n/** The mono tone of a chart mark → its `sys.chart.*` colour. `ink` = the single/active series,\n * `muted` = a comparison/secondary series, `accent` = the one opt-in hue (categorical blue).\n * The single definition of the `tone` option, shared by every chart in the family. */\nexport function toneFill(tone: 'ink' | 'muted' | 'accent'): string {\n if (tone === 'accent') return chartToken.accent;\n if (tone === 'muted') return chartToken.muted;\n return chartToken.ink;\n}\n\nconst wrap = (i: number, n: number) => ((i % n) + n) % n;\nconst rampIndex = (i: number, n: number) =>\n n <= 1 ? SEQUENTIAL.length - 1 : Math.round(Math.min(Math.max(i / (n - 1), 0), 1) * (SEQUENTIAL.length - 1));\n\n/** Colour for category `i` (0-based). Wraps past the cap, pair with a label/pattern. */\nexport function categorical(i: number): string {\n return CATEGORICAL[wrap(i, CATEGORICAL_MAX)];\n}\n\n/** WCAG-AA foreground for text drawn on `categorical(i)`. */\nexport function categoricalOn(i: number): string {\n return CATEGORICAL_ON[wrap(i, CATEGORICAL_MAX)];\n}\n\n/** Colour for the `i`-th of `n` steps on the single-hue magnitude ramp. */\nexport function sequential(i: number, n: number): string {\n return SEQUENTIAL[rampIndex(i, n)];\n}\n\n/** WCAG-AA foreground for text drawn on `sequential(i, n)`. */\nexport function sequentialOn(i: number, n: number): string {\n return SEQUENTIAL_ON[rampIndex(i, n)];\n}\n"],"mappings":";AAaO,IAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAIA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,kBAAkB,YAAY;AAK3C,IAAM,iBAAiB;AAAA,EACrB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF;AAIA,IAAM,gBAAgB;AAAA,EACpB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF;AAMO,IAAM,cAAc,EAAE,MAAM,GAAG,OAAO,EAAE;AAKxC,SAAS,SAAS,MAA0C;AACjE,MAAI,SAAS,SAAU,QAAO,WAAW;AACzC,MAAI,SAAS,QAAS,QAAO,WAAW;AACxC,SAAO,WAAW;AACpB;AAEA,IAAM,OAAO,CAAC,GAAW,OAAgB,IAAI,IAAK,KAAK;AACvD,IAAM,YAAY,CAAC,GAAW,MAC5B,KAAK,IAAI,WAAW,SAAS,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,WAAW,SAAS,EAAE;AAGtG,SAAS,YAAY,GAAmB;AAC7C,SAAO,YAAY,KAAK,GAAG,eAAe,CAAC;AAC7C;AAGO,SAAS,cAAc,GAAmB;AAC/C,SAAO,eAAe,KAAK,GAAG,eAAe,CAAC;AAChD;AAGO,SAAS,WAAW,GAAW,GAAmB;AACvD,SAAO,WAAW,UAAU,GAAG,CAAC,CAAC;AACnC;AAGO,SAAS,aAAa,GAAW,GAAmB;AACzD,SAAO,cAAc,UAAU,GAAG,CAAC,CAAC;AACtC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/button/button.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { cn } from '@/lib/utils';\n\n/**\n * Cairn Button. Consumes the design tokens through the Tailwind bridge\n * (bg-primary, rounded-control, …), install the Cairn theme in the target project.\n */\nconst buttonVariants = cva(\n // A soft accent halo on hover (a fill-grade ring in `accent-halo`, box-shadow so it never shifts\n // layout and coexists with the focus-visible outline). Disabled buttons can't hover, so no halo.\n 'inline-flex items-center justify-center gap-2 leading-none rounded-control font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow,filter] duration-150 outline-none hover:[box-shadow:0_0_0_4px_var(--sv-sys-color-accent-halo)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:pointer-events-none disabled:opacity-40',\n {\n variants: {\n variant: {\n primary: 'bg-primary text-on-primary hover:bg-primary-hover active:brightness-90',\n secondary:\n 'border border-outline-strong bg-surface text-on-surface hover:bg-surface-subtle active:bg-surface-muted',\n ghost: 'text-on-surface hover:bg-surface-subtle active:bg-surface-muted',\n danger: 'bg-danger text-on-danger hover:brightness-95 active:brightness-90',\n },\n size: {\n sm: 'h-9 px-3 text-sm',\n md: 'h-11 px-5 text-sm',\n lg: 'h-12 px-6 text-base',\n },\n },\n defaultVariants: { variant: 'primary', size: 'md' },\n }\n);\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n /** Visual style of the button. */\n variant?: 'primary' | 'secondary' | 'ghost' | 'danger';\n /** Control height and padding. */\n size?: 'sm' | 'md' | 'lg';\n /** Render as the child element (e.g. an `<a>`) instead of a `<button>`. */\n asChild?: boolean;\n}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : 'button';\n return (\n <Comp ref={ref} className={cn(buttonVariants({ variant, size }), className)} {...props} />\n );\n }\n);\nButton.displayName = 'Button';\n\nexport { buttonVariants };\n"],"mappings":";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,YAAY;AACrB,SAAS,WAA8B;AA6CjC;AAtCN,IAAM,iBAAiB;AAAA;AAAA;AAAA,EAGrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WACE;AAAA,QACF,OAAO;AAAA,QACP,QAAQ;AAAA,MACV;AAAA,MACA,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB,EAAE,SAAS,WAAW,MAAM,KAAK;AAAA,EACpD;AACF;AAaO,IAAM,SAAe;AAAA,EAC1B,CAAC,EAAE,WAAW,SAAS,MAAM,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAChE,UAAM,OAAO,UAAU,OAAO;AAC9B,WACE,oBAAC,QAAK,KAAU,WAAW,GAAG,eAAe,EAAE,SAAS,KAAK,CAAC,GAAG,SAAS,GAAI,GAAG,OAAO;AAAA,EAE5F;AACF;AACA,OAAO,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,SAAS,CAAC,GAAY,MAAsB;AAChD,QAAI,UAAU,cAAe,QAAO,cAAc,CAAC;AACnD,QAAI,UAAU,aAAc,QAAO,aAAa,GAAG,KAAK,MAAM;AAE9D,QAAI,CAAC,UAAW,QAAO;AACvB,WAAO,EAAE,SAAS,mCAAmC;AAAA,EACvD;AAIA,QAAM,YAAY,UAAU,UAAU;AAEtC,SACE,qBAAC,SAAI,WAAW,GAAG,UAAU,SAAS,GACpC;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,OAAO;AAAA,UACL;AAAA,UACA,GAAI,YAAY,EAAE,SAAS,aAAa,WAAW,QAAQ,IAAI,eAAe,OAAO,IAAI,CAAC;AAAA,QAC5F;AAAA,QACA,MAAK;AAAA,QACL,cAAY,KAAK,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,IAAI;AAAA,QAE7D,eAAK,IAAI,CAAC,GAAG,MACZ;AAAA,UAAC;AAAA;AAAA,YAEC,WAAU;AAAA,YACV,OAAO,EAAE,OAAO,GAAI,KAAK,EAAE,KAAK,IAAI,QAAS,GAAG,KAAK,YAAY,KAAK,GAAG,CAAC,EAAE;AAAA,YAE5E,8BAAC,UAAK,WAAU,gDAA+C,OAAO,EAAE,OAAO,OAAO,GAAG,CAAC,EAAE,GAAI,YAAE,OAAM;AAAA;AAAA,UAJnG,EAAE;AAAA,QAKT,CACD;AAAA;AAAA,IACH;AAAA,IACC,cACC,oBAAC,QAAG,WAAU,uCACX,eAAK,IAAI,CAAC,GAAG,MACZ,qBAAC,QAAiB,WAAW,GAAG,wCAAwC,EAAE,SAAS,oBAAoB,yBAAyB,GAC9H;AAAA,0BAAC,UAAK,WAAU,kCAAiC,OAAO,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,GAAG,eAAY,QAAO;AAAA,MACtG,EAAE;AAAA,SAFI,EAAE,KAGX,CACD,GACH;AAAA,KAEJ;AAEJ;AACA,aAAa,cAAc;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/charts/bar-chart.tsx"],"sourcesContent":["'use client';\nimport * as React from 'react';\nimport { cn } from '@/lib/utils';\nimport { chartToken, toneFill } from './lib/series';\n\nexport interface BarDatum {\n label: string;\n value: number;\n /** Highlight this bar (ink) and show its value by default. */\n active?: boolean;\n}\n\nexport interface BarChartProps {\n data: BarDatum[];\n height?: number;\n showValue?: boolean;\n /** Colour of the promoted bar. Defaults to ink; `accent` uses the categorical blue. */\n tone?: 'ink' | 'accent';\n className?: string;\n}\n\n/**\n * Cairn BarChart, grayscale-first: muted neutral bars, the active bar promoted to ink\n * (or the categorical blue via `tone=\"accent\"`) with a value pill. Interactive: hover any\n * bar to promote it and reveal its value. Colours resolve from `sys.chart.*` tokens (via\n * `chartToken`), so a theme swap recolours the chart for free. The chart carries a text\n * `aria-label` listing every label/value, so the data is never mouse-only (WCAG-safe).\n */\nexport function BarChart({ data, height = 200, showValue = true, tone = 'ink', className }: BarChartProps) {\n const max = Math.max(...data.map((d) => (Number.isFinite(d.value) ? d.value : 0)), 1);\n const [hover, setHover] = React.useState<number | null>(null);\n\n const activeFill = toneFill(tone);\n const mutedFill = chartToken.muted;\n\n return (\n <div className={cn('w-full', className)} role=\"group\" aria-label=\"Bar chart\">\n <div className=\"flex items-end gap-2\" style={{ height }} onMouseLeave={() => setHover(null)}>\n {data.map((d, i) => {\n const on = d.active || hover === i;\n const dim = hover != null && hover !== i;\n const h = Number.isFinite(d.value) ? d.value : 0;\n return (\n // Each bar is a focusable graphical object: keyboard + screen-reader parity with hover,\n // so its value is never mouse-only (rule 9). Focus mirrors hover to reveal the pill.\n <div\n key={d.label}\n role=\"img\"\n aria-label={`${d.label}: ${d.value}`}\n tabIndex={0}\n className=\"flex h-full flex-1 flex-col items-center justify-end gap-2 rounded-control outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus\"\n onMouseEnter={() => setHover(i)}\n onFocus={() => setHover(i)}\n onBlur={() => setHover(null)}\n >\n <span\n className={cn(\n 'rounded-pill px-2 py-0.5 sv-body-xs font-medium tabular-nums transition-opacity duration-150',\n on && showValue ? 'opacity-100' : 'opacity-0'\n )}\n style={{ background: activeFill, color: 'var(--sv-sys-color-on-primary)' }}\n >\n {d.value}\n </span>\n <div\n className={cn(\n 'w-full rounded-t-control transition-[height,background-color,opacity] duration-500 ease-out',\n dim && 'opacity-60'\n )}\n style={{\n height: `${Math.max(2, (h / max) * 100)}%`,\n background: on ? activeFill : mutedFill,\n // The pale muted fill is < 3:1 vs the surface; a keyline carries the mark's\n // shape contrast (AGENTS.md rule 9). Active (ink) bars already clear 3:1.\n boxShadow: on ? undefined : `inset 0 0 0 1px ${chartToken.markEdge}`,\n }}\n />\n </div>\n );\n })}\n </div>\n <div className=\"mt-3 flex gap-2\" aria-hidden=\"true\">\n {data.map((d, i) => (\n <span\n key={d.label}\n className={cn(\n 'flex-1 text-center sv-body-sm transition-colors',\n d.active || hover === i ? 'text-on-surface' : 'text-on-surface-variant'\n )}\n >\n {d.label}\n </span>\n ))}\n </div>\n </div>\n );\n}\nBarChart.displayName = 'BarChart';\n"],"mappings":";;;;;;;;;AACA,YAAY,WAAW;AA4CX,SAUE,KAVF;AAjBL,SAAS,SAAS,EAAE,MAAM,SAAS,KAAK,YAAY,MAAM,OAAO,OAAO,UAAU,GAAkB;AACzG,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,MAAO,OAAO,SAAS,EAAE,KAAK,IAAI,EAAE,QAAQ,CAAE,GAAG,CAAC;AACpF,QAAM,CAAC,OAAO,QAAQ,IAAU,eAAwB,IAAI;AAE5D,QAAM,aAAa,SAAS,IAAI;AAChC,QAAM,YAAY,WAAW;AAE7B,SACE,qBAAC,SAAI,WAAW,GAAG,UAAU,SAAS,GAAG,MAAK,SAAQ,cAAW,aAC/D;AAAA,wBAAC,SAAI,WAAU,wBAAuB,OAAO,EAAE,OAAO,GAAG,cAAc,MAAM,SAAS,IAAI,GACvF,eAAK,IAAI,CAAC,GAAG,MAAM;AAClB,YAAM,KAAK,EAAE,UAAU,UAAU;AACjC,YAAM,MAAM,SAAS,QAAQ,UAAU;AACvC,YAAM,IAAI,OAAO,SAAS,EAAE,KAAK,IAAI,EAAE,QAAQ;AAC/C;AAAA;AAAA;AAAA,QAGE;AAAA,UAAC;AAAA;AAAA,YAEC,MAAK;AAAA,YACL,cAAY,GAAG,EAAE,KAAK,KAAK,EAAE,KAAK;AAAA,YAClC,UAAU;AAAA,YACV,WAAU;AAAA,YACV,cAAc,MAAM,SAAS,CAAC;AAAA,YAC9B,SAAS,MAAM,SAAS,CAAC;AAAA,YACzB,QAAQ,MAAM,SAAS,IAAI;AAAA,YAE3B;AAAA;AAAA,gBAAC;AAAA;AAAA,kBACC,WAAW;AAAA,oBACT;AAAA,oBACA,MAAM,YAAY,gBAAgB;AAAA,kBACpC;AAAA,kBACA,OAAO,EAAE,YAAY,YAAY,OAAO,iCAAiC;AAAA,kBAExE,YAAE;AAAA;AAAA,cACL;AAAA,cACA;AAAA,gBAAC;AAAA;AAAA,kBACC,WAAW;AAAA,oBACT;AAAA,oBACA,OAAO;AAAA,kBACT;AAAA,kBACA,OAAO;AAAA,oBACL,QAAQ,GAAG,KAAK,IAAI,GAAI,IAAI,MAAO,GAAG,CAAC;AAAA,oBACvC,YAAY,KAAK,aAAa;AAAA;AAAA;AAAA,oBAG9B,WAAW,KAAK,SAAY,mBAAmB,WAAW,QAAQ;AAAA,kBACpE;AAAA;AAAA,cACF;AAAA;AAAA;AAAA,UA9BK,EAAE;AAAA,QA+BT;AAAA;AAAA,IAEJ,CAAC,GACH;AAAA,IACA,oBAAC,SAAI,WAAU,mBAAkB,eAAY,QAC1C,eAAK,IAAI,CAAC,GAAG,MACZ;AAAA,MAAC;AAAA;AAAA,QAEC,WAAW;AAAA,UACT;AAAA,UACA,EAAE,UAAU,UAAU,IAAI,oBAAoB;AAAA,QAChD;AAAA,QAEC,YAAE;AAAA;AAAA,MANE,EAAE;AAAA,IAOT,CACD,GACH;AAAA,KACF;AAEJ;AACA,SAAS,cAAc;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/charts/ring.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '@/lib/utils';\nimport { chartToken, toneFill } from './lib/series';\n\nexport interface RingProps {\n /** Progress, 0-100. */\n value: number;\n /** Outer diameter in px. */\n size?: number;\n /** Ring thickness in px. */\n thickness?: number;\n /** Colour of the filled arc. Defaults to ink; `accent` uses categorical blue. */\n tone?: 'ink' | 'accent';\n /**\n * Explicit arc colour (a token / CSS colour), overrides `tone`. Pass only colours that\n * clear 3:1 against the surface as a thin stroke, ink, blue, or a dark graphite. Acid\n * and mid-gray are fill-only (they fail as a line); see AGENTS.md rule 9.\n */\n color?: string;\n /**\n * Draw a darker keyline under the arc so a light, low-contrast colour (acid) stays\n * perceptible, the rim carries the 3:1 shape contrast the fill can't (AGENTS.md rule 9).\n * `true` uses ink; pass a colour (e.g. `sys.color.accent-edge`) for a tonal, in-family rim.\n */\n casing?: boolean | string;\n /** Fill the arc from empty on mount. Honours `prefers-reduced-motion`. */\n animate?: boolean;\n /** Centre content, e.g. the value. Omit for a bare ring. */\n children?: React.ReactNode;\n /** Accessible label; falls back to \"<value>%\". */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * Cairn Ring, single-value radial progress. Grayscale by default (ink arc on a\n * neutral track); `tone=\"accent\"` opts into the categorical blue, or pass an explicit\n * `color`. The arc fills from empty on mount (rounded cap, 12 o'clock, clockwise).\n * Zero-dependency SVG. A client component (`'use client'`): the mount animation uses state;\n * pass `animate={false}` to render it statically.\n */\nexport function Ring({\n value,\n size = 160,\n thickness = 14,\n tone = 'ink',\n color,\n casing = false,\n animate = true,\n children,\n className,\n 'aria-label': ariaLabel,\n}: RingProps) {\n const pct = Math.min(Math.max(Number.isFinite(value) ? value : 0, 0), 100);\n const r = (size - thickness) / 2;\n const c = 2 * Math.PI * r;\n\n // Fill from empty on mount: first client paint is 0, then rAF advances to the value so the\n // CSS transition animates. Under prefers-reduced-motion we jump straight to the value with the\n // transition removed — self-contained, never relying on a global reduced-motion rule existing.\n const [progress, setProgress] = React.useState(animate ? 0 : pct);\n const [instant, setInstant] = React.useState(!animate);\n React.useEffect(() => {\n if (!animate) {\n setProgress(pct);\n return;\n }\n const reduce =\n typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n if (reduce) {\n setInstant(true);\n setProgress(pct);\n return;\n }\n setInstant(false);\n const id = requestAnimationFrame(() => setProgress(pct));\n return () => cancelAnimationFrame(id);\n }, [pct, animate]);\n\n const arc = (progress / 100) * c;\n const motion = instant ? undefined : 'transition-[stroke-dasharray] duration-[900ms] ease-out';\n const stroke = color ?? toneFill(tone);\n return (\n <div\n className={cn('relative inline-grid place-items-center', className)}\n style={{ width: size, height: size }}\n role=\"img\"\n aria-label={ariaLabel ?? `${Math.round(pct)}%`}\n >\n <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"rotate-[-90deg]\" aria-hidden=\"true\">\n <circle cx={size / 2} cy={size / 2} r={r} fill=\"none\" stroke={chartToken.track} strokeWidth={thickness} />\n {casing && (\n <circle\n cx={size / 2}\n cy={size / 2}\n r={r}\n fill=\"none\"\n stroke={typeof casing === 'string' ? casing : 'var(--sv-sys-color-on-surface)'}\n strokeWidth={thickness + 2}\n strokeLinecap=\"round\"\n strokeDasharray={`${arc} ${c - arc}`}\n className={motion}\n />\n )}\n <circle\n cx={size / 2}\n cy={size / 2}\n r={r}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={thickness}\n strokeLinecap=\"round\"\n strokeDasharray={`${arc} ${c - arc}`}\n className={motion}\n />\n </svg>\n {children != null && <div className=\"absolute inset-0 grid place-items-center\">{children}</div>}\n </div>\n );\n}\nRing.displayName = 'Ring';\n"],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AAyFjB,SACE,KADF;AAhDC,SAAS,KAAK;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,OAAO;AAAA,EACP;AAAA,EACA,SAAS;AAAA,EACT,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAAc;AACZ,QAAM,MAAM,KAAK,IAAI,KAAK,IAAI,OAAO,SAAS,KAAK,IAAI,QAAQ,GAAG,CAAC,GAAG,GAAG;AACzE,QAAM,KAAK,OAAO,aAAa;AAC/B,QAAM,IAAI,IAAI,KAAK,KAAK;AAKxB,QAAM,CAAC,UAAU,WAAW,IA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