strata-react 2.1.22 → 2.2.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.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystem
11
11
  import * as React from "react";
12
12
  import { useRef, useState } from "react";
13
13
  import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading, Input as Input$1, Keyboard, Link, ListBox, ListBoxItem, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, RouterProvider, Row, SearchField, Select, SelectValue, Separator, Slider as Slider$1, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Tree as Tree$1, TreeItem, TreeItemContent, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
14
- import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Brush, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUp, CircleAlert, CircleCheck, CircleDashed, Clock as Clock$1, CloudOff, Columns2, Ellipsis, Eraser, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, Hand, Highlighter, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, MousePointer2, Paintbrush, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, PenLine, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
14
+ import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Brush, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUp, CircleAlert, CircleCheck, CircleDashed, Clock as Clock$1, CloudOff, Columns2, Ellipsis, Eraser, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, Hand, Highlighter, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, MousePointer2, Paintbrush, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, PenLine, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
15
15
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
16
  import { Link as Link$1, NavLink, useHref, useNavigate, useSearchParams } from "react-router";
17
17
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
@@ -26133,8 +26133,8 @@ function TurnArrow({ facing, turn, label, className }) {
26133
26133
  }
26134
26134
 
26135
26135
  // src/components/partial-date-field.tsx
26136
- const PARTIAL_DATE_RE = /^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/;
26137
- /** Parse and validate a partial ISO date (`YYYY`, `YYYY-MM`, or `YYYY-MM-DD`), checking calendar month and day limits. */
26136
+ const PARTIAL_DATE_RE = /^(\d{4})(?:([-/.])(\d{2})(?:\2(\d{2}))?|(\d{2})(\d{2})?)?$/;
26137
+ /** Parse and validate a partial ISO date (`YYYY`, `YYYY-MM`, `YYYY-MM-DD`, or compact `YYYYMM`/`YYYYMMDD`), checking calendar month and day limits and returning canonical hyphenated ISO format. */
26138
26138
  function parsePartialDate(raw, circa = false) {
26139
26139
  const trimmed = raw.trim();
26140
26140
  if (!trimmed) return {
@@ -26144,36 +26144,42 @@ function parsePartialDate(raw, circa = false) {
26144
26144
  const m = PARTIAL_DATE_RE.exec(trimmed);
26145
26145
  if (!m) return {
26146
26146
  ok: false,
26147
- error: "Use YYYY, YYYY-MM or YYYY-MM-DD (for example 1985 or 1985-06-15)."
26147
+ error: "Use YYYY, YYYY-MM, YYYY-MM-DD or YYYYMMDD (for example 1985 or 1985-06-15)."
26148
26148
  };
26149
- const year = Number(m[1]);
26149
+ const yearStr = m[1];
26150
+ const monthStr = m[3] ?? m[5];
26151
+ const dayStr = m[4] ?? m[6];
26152
+ const year = Number(yearStr);
26150
26153
  if (year < 1 || year > 9999) return {
26151
26154
  ok: false,
26152
26155
  error: "Enter a four-digit year between 0001 and 9999."
26153
26156
  };
26157
+ let canonical = yearStr;
26154
26158
  let inferred = "year";
26155
- if (m[2] !== void 0) {
26156
- const month = Number(m[2]);
26159
+ if (monthStr !== void 0) {
26160
+ const month = Number(monthStr);
26157
26161
  if (month < 1 || month > 12) return {
26158
26162
  ok: false,
26159
26163
  error: "Month must be between 01 and 12."
26160
26164
  };
26165
+ canonical = `${yearStr}-${monthStr}`;
26161
26166
  inferred = "month";
26162
- if (m[3] !== void 0) {
26163
- const day = Number(m[3]);
26167
+ if (dayStr !== void 0) {
26168
+ const day = Number(dayStr);
26164
26169
  const check = /* @__PURE__ */ new Date(0);
26165
26170
  check.setUTCFullYear(year, month - 1, day);
26166
26171
  if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day) return {
26167
26172
  ok: false,
26168
- error: `${trimmed} is not a valid calendar date.`
26173
+ error: `${canonical}-${dayStr} is not a valid calendar date.`
26169
26174
  };
26175
+ canonical = `${canonical}-${dayStr}`;
26170
26176
  inferred = "day";
26171
26177
  }
26172
26178
  }
26173
26179
  return {
26174
26180
  ok: true,
26175
26181
  value: {
26176
- date: trimmed,
26182
+ date: canonical,
26177
26183
  precision: circa ? "circa" : inferred
26178
26184
  }
26179
26185
  };
@@ -26188,7 +26194,16 @@ function PartialDateField({ value, onChange, placeholder = "YYYY, YYYY-MM or YYY
26188
26194
  const { report } = useFieldControl();
26189
26195
  const [draft, setDraft] = React.useState(value?.date ?? "");
26190
26196
  const [circa, setCirca] = React.useState(value?.precision === "circa");
26197
+ const lastCommitted = React.useRef({
26198
+ date: value?.date,
26199
+ precision: value?.precision
26200
+ });
26191
26201
  React.useEffect(() => {
26202
+ if (value?.date === lastCommitted.current.date && value?.precision === lastCommitted.current.precision) return;
26203
+ lastCommitted.current = {
26204
+ date: value?.date,
26205
+ precision: value?.precision
26206
+ };
26192
26207
  setDraft(value?.date ?? "");
26193
26208
  setCirca(value?.precision === "circa");
26194
26209
  report(void 0);
@@ -26197,10 +26212,15 @@ function PartialDateField({ value, onChange, placeholder = "YYYY, YYYY-MM or YYY
26197
26212
  value?.precision,
26198
26213
  report
26199
26214
  ]);
26200
- const commit = (nextDraft, nextCirca, showError) => {
26215
+ const commit = (nextDraft, nextCirca, showError, normalizeDraft = false) => {
26201
26216
  const parsed = parsePartialDate(nextDraft, allowCirca && nextCirca);
26202
26217
  if (parsed.ok) {
26203
26218
  report(void 0);
26219
+ lastCommitted.current = {
26220
+ date: parsed.value?.date,
26221
+ precision: parsed.value?.precision
26222
+ };
26223
+ if (normalizeDraft) setDraft(parsed.value?.date ?? "");
26204
26224
  onChange(parsed.value);
26205
26225
  } else if (showError) report(parsed.error);
26206
26226
  };
@@ -26216,7 +26236,7 @@ function PartialDateField({ value, onChange, placeholder = "YYYY, YYYY-MM or YYY
26216
26236
  setDraft(next);
26217
26237
  commit(next, circa, false);
26218
26238
  },
26219
- onBlur: () => commit(draft, circa, true)
26239
+ onBlur: () => commit(draft, circa, true, true)
26220
26240
  }), allowCirca && /* @__PURE__ */ jsx(Checkbox, {
26221
26241
  label: circaLabel,
26222
26242
  checked: circa,
@@ -26229,5 +26249,1690 @@ function PartialDateField({ value, onChange, placeholder = "YYYY, YYYY-MM or YYY
26229
26249
  });
26230
26250
  }
26231
26251
 
26232
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BRUSHES, Balance, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, CLOCK_FACE_STYLES, CLOCK_STYLES, COINS, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, Clock, ClockFace, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Concealed, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DIGITAL_CLOCK_STYLES, DataTable, DataView$1 as DataView, Density, Dialog, DigitalClock, Disclosure, Done, DragSource, DrawingLayer, DrawingToolbar, EditListPlayer, EmptyState, EventLog, FACINGS, FIT, FRACTION_OUTLINES, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FillLevel, FilmStrip, FolderPicker, FractionShape, FullscreenFrame, Glimpse, HttpError, INK_COLOURS, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, JsonView, KeysLegend, LEVEL_FLOOR_DB, LengthBar, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, Money, NBSP, NOTES, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PartialDateField, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RangeSlider, RateChoice, ReadAlong, RegionEditor, RichText, RowAction, SOLID_SHAPES, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SayPicture, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SetClock, ShortcutEditor, SideNav, Skeleton, Slider, Solid, SortableList, SpanActions, SpanStrip, SpeakerTimeline, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, TurnArrow, UNCLEAR, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, applyOp, assignTurns, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, clockParts, clockWords, cn, coinOutline, colorSchemeScript, commandShortcut, continues, copyTurns, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, currentOf, curvePoints, dayPart, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, digitalTime, diskThresholds, drawRect, drawingToSvg, ease, editTimeOf, editTimes, emptyDrawing, encodeWav, errorPayload, explainMicrophoneError, feedbackMarker, fetchJson, fieldErrorsOf, fillWords, filterMarkup, findPage, fitPoints, fitRect, followAim, format, formatChord, formatPartialDate, fractionParts, fractionWords, frameAt, freshId, gainToVolume, geo, gridPoints, gutterOf, hitsStroke, hourAt, inkMatch, inputLevelThresholds, invertOp, isDigitalStyle, isDoubtful, isRefusal, isReservedChord, isSpeaking, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, jsonBranchPaths, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, mediaStatRows, mergeWithNext, minutesAt, moneyWords, moveGutter, moveMinuteHand, movePoints, moveRect, newStrokeId, newVoiceName, nextBreak, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parsePartialDate, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, pointsBox, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, removeTurns, renameVoice, replay, resample, resamplePeaks, rescaleDrawing, resizeRect, rgbaToBlob, rmsDb, romanHour, safeHref, sayPosition, serialiseSort, setEdge, settleCut, simplifyPoints, skipAction, smoothPath, snapToGrid, solidWords, sortRows, speak, speechLevel, splitRect, splitTurn, staleOf, stepId, stepMinuteHand, stepOnGrid, stopSpeaking, strokeAt, strokeBox, strokeShape, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnWords, turned, turnedSize, turnsAt, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useCountdown, useDifference, useDrawing, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useInkMatch, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMediaStats, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useReadAloud, useRebindableShortcuts, useRecorder, useReserve, useRevealed, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeaking, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, voicesOf, widthsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
26252
+ // src/lib/eval-charts.ts
26253
+ /**
26254
+ * Compute clean 1-2-5 axis bounds and tick positions covering `[rawMin, rawMax]`.
26255
+ * Never crops a value: the returned `[min, max]` always contains `[rawMin, rawMax]`.
26256
+ */
26257
+ function niceScale(rawMin, rawMax, targetTicks = 5) {
26258
+ if (!Number.isFinite(rawMin) || !Number.isFinite(rawMax)) return {
26259
+ min: 0,
26260
+ max: 1,
26261
+ ticks: [
26262
+ 0,
26263
+ .5,
26264
+ 1
26265
+ ],
26266
+ step: .5
26267
+ };
26268
+ let lo = Math.min(rawMin, rawMax);
26269
+ let hi = Math.max(rawMin, rawMax);
26270
+ if (lo === hi) {
26271
+ const pad = lo === 0 ? 1 : Math.abs(lo) * .2;
26272
+ lo -= pad;
26273
+ hi += pad;
26274
+ }
26275
+ const roughStep = (hi - lo) / Math.max(2, targetTicks - 1);
26276
+ const mag = 10 ** Math.floor(Math.log10(roughStep));
26277
+ const norm = roughStep / mag;
26278
+ const step = (norm <= 1.5 ? 1 : norm <= 3 ? 2 : norm <= 7 ? 5 : 10) * mag;
26279
+ const min = Math.floor(lo / step) * step;
26280
+ const max = Math.ceil(hi / step) * step;
26281
+ const ticks = [];
26282
+ const count = Math.round((max - min) / step);
26283
+ for (let i = 0; i <= count; i++) {
26284
+ const val = Number((min + i * step).toPrecision(12));
26285
+ ticks.push(Object.is(val, -0) ? 0 : val);
26286
+ }
26287
+ return {
26288
+ min: ticks[0] ?? min,
26289
+ max: ticks[ticks.length - 1] ?? max,
26290
+ ticks,
26291
+ step
26292
+ };
26293
+ }
26294
+ /**
26295
+ * Return the non-dominated (Pareto optimal) point IDs and the frontier points ordered along `x`.
26296
+ * A point A dominates B when A is at least as good on both axes and strictly better on at least one.
26297
+ */
26298
+ function paretoFrontier(points, xDirection, yDirection) {
26299
+ const valid = points.filter((p) => Number.isFinite(p.x) && Number.isFinite(p.y));
26300
+ const betterOrEqualX = (a, b) => xDirection === "higher" ? a >= b : a <= b;
26301
+ const strictlyBetterX = (a, b) => xDirection === "higher" ? a > b : a < b;
26302
+ const betterOrEqualY = (a, b) => yDirection === "higher" ? a >= b : a <= b;
26303
+ const strictlyBetterY = (a, b) => yDirection === "higher" ? a > b : a < b;
26304
+ const ordered = [...valid.filter((candidate) => {
26305
+ return !valid.some((other) => other !== candidate && betterOrEqualX(other.x, candidate.x) && betterOrEqualY(other.y, candidate.y) && (strictlyBetterX(other.x, candidate.x) || strictlyBetterY(other.y, candidate.y)));
26306
+ })].sort((a, b) => a.x === b.x ? a.y - b.y : a.x - b.x);
26307
+ return {
26308
+ ids: new Set(ordered.map((p) => p.id)),
26309
+ ordered
26310
+ };
26311
+ }
26312
+ function linearQuantile(sorted, q) {
26313
+ if (sorted.length === 0) return NaN;
26314
+ if (sorted.length === 1) return sorted[0];
26315
+ const pos = (sorted.length - 1) * q;
26316
+ const lo = Math.floor(pos);
26317
+ const hi = Math.ceil(pos);
26318
+ const frac = pos - lo;
26319
+ return sorted[lo] + (sorted[hi] - sorted[lo]) * frac;
26320
+ }
26321
+ /** Compute five-number summary + mean for finite numeric observations. */
26322
+ function summarizeDistribution(values) {
26323
+ const finite = values.filter(Number.isFinite).sort((a, b) => a - b);
26324
+ if (finite.length === 0) return null;
26325
+ let sum = 0;
26326
+ for (const v of finite) sum += v;
26327
+ return {
26328
+ n: finite.length,
26329
+ min: finite[0],
26330
+ p25: linearQuantile(finite, .25),
26331
+ median: linearQuantile(finite, .5),
26332
+ p75: linearQuantile(finite, .75),
26333
+ max: finite[finite.length - 1],
26334
+ mean: sum / finite.length
26335
+ };
26336
+ }
26337
+ /** Empirical cumulative distribution function points `(x, proportion in [0, 1])`. */
26338
+ function ecdfPoints(values) {
26339
+ const finite = values.filter(Number.isFinite).sort((a, b) => a - b);
26340
+ const n = finite.length;
26341
+ if (n === 0) return [];
26342
+ const out = [];
26343
+ for (let i = 0; i < n; i++) {
26344
+ const x = finite[i];
26345
+ if (i < n - 1 && finite[i + 1] === x) continue;
26346
+ out.push({
26347
+ x,
26348
+ y: (i + 1) / n
26349
+ });
26350
+ }
26351
+ return out;
26352
+ }
26353
+ /** Deterministic jitter in `[-1, 1]` from a string/number key so visual snapshots never drift. */
26354
+ function deterministicJitter(key) {
26355
+ const s = String(key);
26356
+ let h = 2166136261;
26357
+ for (let i = 0; i < s.length; i++) {
26358
+ h ^= s.charCodeAt(i);
26359
+ h = Math.imul(h, 16777619);
26360
+ }
26361
+ return (h >>> 0) / 4294967295 * 2 - 1;
26362
+ }
26363
+ /** Categorical chart colours from the Strata token contract (`--chart-1`…`--chart-5`). */
26364
+ const CHART_COLOURS = [
26365
+ "var(--chart-1)",
26366
+ "var(--chart-2)",
26367
+ "var(--chart-3)",
26368
+ "var(--chart-4)",
26369
+ "var(--chart-5)"
26370
+ ];
26371
+ function chartColour(index) {
26372
+ return CHART_COLOURS[(index % CHART_COLOURS.length + CHART_COLOURS.length) % CHART_COLOURS.length];
26373
+ }
26374
+ /** Measure an element's pixel width with ResizeObserver, falling back cleanly in jsdom/SSR. */
26375
+ function useContainerWidth(ref, fallback = 560) {
26376
+ const [width, setWidth] = React.useState(fallback);
26377
+ React.useLayoutEffect(() => {
26378
+ const el = ref.current;
26379
+ if (!el) return;
26380
+ const measure = () => {
26381
+ const w = el.getBoundingClientRect().width;
26382
+ if (w > 0) setWidth(Math.round(w));
26383
+ };
26384
+ measure();
26385
+ if (typeof ResizeObserver === "undefined") return;
26386
+ const ro = new ResizeObserver(measure);
26387
+ ro.observe(el);
26388
+ return () => ro.disconnect();
26389
+ }, [ref]);
26390
+ return width;
26391
+ }
26392
+
26393
+ // src/components/forest-plot.tsx
26394
+ const PLOT_PAD_X = 14;
26395
+ const ROW_H$1 = 44;
26396
+ const AXIS_H = 28;
26397
+ const VERDICT_COLOUR = {
26398
+ neutral: "var(--muted-foreground)",
26399
+ info: "var(--info)",
26400
+ success: "var(--success)",
26401
+ warning: "var(--warning)",
26402
+ danger: "var(--danger)"
26403
+ };
26404
+ /** Horizontal forest plot of paired effect estimates with confidence intervals, minimum-effect band, guardrails and verdicts. */
26405
+ function ForestPlot({ label, rows, formatValue, reference = 0, referenceLabel = "No change", minEffect, minEffectLabel, worseLabel = "Worse", betterLabel = "Better", note, selectedId, onSelect, className }) {
26406
+ const plotRef = React.useRef(null);
26407
+ const plotWidth = useContainerWidth(plotRef, 360);
26408
+ const scale = React.useMemo(() => {
26409
+ const vals = [reference];
26410
+ if (minEffect !== void 0 && Number.isFinite(minEffect)) vals.push(minEffect);
26411
+ for (const r of rows) {
26412
+ if (r.estimate !== null && Number.isFinite(r.estimate)) vals.push(r.estimate);
26413
+ if (r.low !== void 0 && r.low !== null && Number.isFinite(r.low)) vals.push(r.low);
26414
+ if (r.high !== void 0 && r.high !== null && Number.isFinite(r.high)) vals.push(r.high);
26415
+ }
26416
+ const rawMin = Math.min(...vals);
26417
+ const rawMax = Math.max(...vals);
26418
+ return niceScale(rawMin, rawMax, 5);
26419
+ }, [
26420
+ rows,
26421
+ reference,
26422
+ minEffect
26423
+ ]);
26424
+ const innerW = Math.max(120, plotWidth - 28);
26425
+ const span = scale.max - scale.min || 1;
26426
+ const xOf = (v) => PLOT_PAD_X + (v - scale.min) / span * innerW;
26427
+ const refX = xOf(reference);
26428
+ const minEffX = minEffect !== void 0 && Number.isFinite(minEffect) ? xOf(minEffect) : null;
26429
+ const hasGuards = rows.some((r) => r.guards && r.guards.length > 0);
26430
+ const hasVerdicts = rows.some((r) => r.verdict);
26431
+ const labelTicks = React.useMemo(() => {
26432
+ const maxLabels = Math.max(2, Math.floor(innerW / 68));
26433
+ if (scale.ticks.length <= maxLabels) return scale.ticks;
26434
+ const stride = Math.ceil(scale.ticks.length / maxLabels);
26435
+ const picked = scale.ticks.filter((_, idx) => idx % stride === 0);
26436
+ const last = scale.ticks[scale.ticks.length - 1];
26437
+ if (last !== void 0 && picked[picked.length - 1] !== last && innerW - (xOf(picked[picked.length - 1]) - PLOT_PAD_X) > 48) picked.push(last);
26438
+ return picked;
26439
+ }, [scale.ticks, innerW]);
26440
+ const gridCols = `minmax(145px, 1.2fr) minmax(220px, 2fr) minmax(150px, auto) 44px${hasGuards ? " minmax(100px, auto)" : ""}${hasVerdicts ? " 90px" : ""}`;
26441
+ return /* @__PURE__ */ jsxs("figure", {
26442
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
26443
+ children: [
26444
+ /* @__PURE__ */ jsxs("figcaption", {
26445
+ className: "flex flex-wrap items-baseline justify-between gap-2 border-b border-border px-4 py-2.5",
26446
+ children: [/* @__PURE__ */ jsx("span", {
26447
+ className: "type-label text-foreground",
26448
+ children: label
26449
+ }), note && /* @__PURE__ */ jsx("span", {
26450
+ className: "type-caption text-muted-foreground",
26451
+ children: note
26452
+ })]
26453
+ }),
26454
+ /* @__PURE__ */ jsx("div", {
26455
+ className: "overflow-x-auto",
26456
+ children: /* @__PURE__ */ jsxs("div", {
26457
+ className: "min-w-[640px]",
26458
+ children: [
26459
+ /* @__PURE__ */ jsxs("div", {
26460
+ className: "grid items-end gap-3 border-b border-border bg-surface-sunken px-4 py-1.5 type-caption text-muted-foreground",
26461
+ style: { gridTemplateColumns: gridCols },
26462
+ children: [
26463
+ /* @__PURE__ */ jsx("div", { children: "Candidate" }),
26464
+ /* @__PURE__ */ jsxs("div", {
26465
+ ref: plotRef,
26466
+ className: "flex items-center justify-between gap-2 px-1",
26467
+ children: [
26468
+ /* @__PURE__ */ jsxs("span", {
26469
+ className: "inline-flex items-center gap-1",
26470
+ children: [/* @__PURE__ */ jsx(ArrowLeft, {
26471
+ "aria-hidden": true,
26472
+ className: "size-3"
26473
+ }), worseLabel]
26474
+ }),
26475
+ /* @__PURE__ */ jsx("span", {
26476
+ className: "text-foreground/70",
26477
+ children: referenceLabel
26478
+ }),
26479
+ /* @__PURE__ */ jsxs("span", {
26480
+ className: "inline-flex items-center gap-1",
26481
+ children: [betterLabel, /* @__PURE__ */ jsx(ArrowRight, {
26482
+ "aria-hidden": true,
26483
+ className: "size-3"
26484
+ })]
26485
+ })
26486
+ ]
26487
+ }),
26488
+ /* @__PURE__ */ jsx("div", {
26489
+ className: "text-right",
26490
+ children: "Effect (CI)"
26491
+ }),
26492
+ /* @__PURE__ */ jsx("div", {
26493
+ className: "text-right",
26494
+ children: "N"
26495
+ }),
26496
+ hasGuards && /* @__PURE__ */ jsx("div", { children: "Guards" }),
26497
+ hasVerdicts && /* @__PURE__ */ jsx("div", {
26498
+ className: "text-right",
26499
+ children: "Verdict"
26500
+ })
26501
+ ]
26502
+ }),
26503
+ /* @__PURE__ */ jsx("div", {
26504
+ role: "list",
26505
+ "aria-label": label,
26506
+ className: "divide-y divide-border",
26507
+ children: rows.map((row) => {
26508
+ const isSelected = selectedId === row.id;
26509
+ const interactive = Boolean(onSelect);
26510
+ const pointColour = row.baseline ? "var(--muted-foreground)" : row.verdict ? VERDICT_COLOUR[row.verdict.tone] : "var(--primary)";
26511
+ const hasInterval = row.low !== void 0 && row.low !== null && row.high !== void 0 && row.high !== null && Number.isFinite(row.low) && Number.isFinite(row.high);
26512
+ const hasEstimate = row.estimate !== null && Number.isFinite(row.estimate);
26513
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
26514
+ /* @__PURE__ */ jsxs("div", {
26515
+ className: "min-w-0",
26516
+ children: [/* @__PURE__ */ jsx("div", {
26517
+ className: cn("truncate type-label", row.baseline ? "text-muted-foreground" : "text-foreground"),
26518
+ children: row.label
26519
+ }), row.subtitle && /* @__PURE__ */ jsx("div", {
26520
+ className: "truncate type-caption text-muted-foreground",
26521
+ children: row.subtitle
26522
+ })]
26523
+ }),
26524
+ /* @__PURE__ */ jsx("div", {
26525
+ className: "h-[44px] w-full",
26526
+ children: /* @__PURE__ */ jsxs("svg", {
26527
+ width: plotWidth,
26528
+ height: ROW_H$1,
26529
+ className: "block h-full w-full overflow-visible",
26530
+ "aria-hidden": "true",
26531
+ children: [
26532
+ scale.ticks.map((t) => {
26533
+ const tx = xOf(t);
26534
+ return /* @__PURE__ */ jsx("line", {
26535
+ x1: tx,
26536
+ x2: tx,
26537
+ y1: 0,
26538
+ y2: ROW_H$1,
26539
+ stroke: "var(--border)",
26540
+ strokeOpacity: t === reference ? 0 : .55,
26541
+ strokeWidth: 1
26542
+ }, t);
26543
+ }),
26544
+ minEffX !== null && /* @__PURE__ */ jsx("rect", {
26545
+ x: Math.min(refX, minEffX),
26546
+ y: 0,
26547
+ width: Math.max(1, Math.abs(minEffX - refX)),
26548
+ height: ROW_H$1,
26549
+ fill: "var(--primary)",
26550
+ fillOpacity: .09
26551
+ }),
26552
+ /* @__PURE__ */ jsx("line", {
26553
+ x1: refX,
26554
+ x2: refX,
26555
+ y1: 0,
26556
+ y2: ROW_H$1,
26557
+ stroke: "var(--muted-foreground)",
26558
+ strokeDasharray: "3 3",
26559
+ strokeWidth: 1.25
26560
+ }),
26561
+ minEffX !== null && /* @__PURE__ */ jsx("line", {
26562
+ x1: minEffX,
26563
+ x2: minEffX,
26564
+ y1: 0,
26565
+ y2: ROW_H$1,
26566
+ stroke: "var(--primary)",
26567
+ strokeOpacity: .55,
26568
+ strokeDasharray: "2 2",
26569
+ strokeWidth: 1
26570
+ }),
26571
+ hasInterval && /* @__PURE__ */ jsxs(Fragment, { children: [
26572
+ /* @__PURE__ */ jsx("line", {
26573
+ x1: xOf(row.low),
26574
+ x2: xOf(row.high),
26575
+ y1: ROW_H$1 / 2,
26576
+ y2: ROW_H$1 / 2,
26577
+ stroke: pointColour,
26578
+ strokeWidth: 2,
26579
+ strokeLinecap: "round"
26580
+ }),
26581
+ /* @__PURE__ */ jsx("line", {
26582
+ x1: xOf(row.low),
26583
+ x2: xOf(row.low),
26584
+ y1: ROW_H$1 / 2 - 4,
26585
+ y2: 26,
26586
+ stroke: pointColour,
26587
+ strokeWidth: 1.5
26588
+ }),
26589
+ /* @__PURE__ */ jsx("line", {
26590
+ x1: xOf(row.high),
26591
+ x2: xOf(row.high),
26592
+ y1: ROW_H$1 / 2 - 4,
26593
+ y2: 26,
26594
+ stroke: pointColour,
26595
+ strokeWidth: 1.5
26596
+ })
26597
+ ] }),
26598
+ hasEstimate && (row.baseline ? /* @__PURE__ */ jsx("polygon", {
26599
+ points: `${xOf(row.estimate)},${ROW_H$1 / 2 - 5} ${xOf(row.estimate) + 5},${ROW_H$1 / 2} ${xOf(row.estimate)},27 ${xOf(row.estimate) - 5},${ROW_H$1 / 2}`,
26600
+ fill: "var(--card)",
26601
+ stroke: pointColour,
26602
+ strokeWidth: 2
26603
+ }) : /* @__PURE__ */ jsx("circle", {
26604
+ cx: xOf(row.estimate),
26605
+ cy: ROW_H$1 / 2,
26606
+ r: isSelected ? 5.5 : 4.5,
26607
+ fill: pointColour,
26608
+ stroke: "var(--card)",
26609
+ strokeWidth: 1.5
26610
+ }))
26611
+ ]
26612
+ })
26613
+ }),
26614
+ /* @__PURE__ */ jsx("div", {
26615
+ className: "whitespace-nowrap text-right font-mono type-caption tabular-nums",
26616
+ children: hasEstimate ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
26617
+ className: "font-medium text-foreground",
26618
+ children: formatValue(row.estimate)
26619
+ }), hasInterval && /* @__PURE__ */ jsxs("div", {
26620
+ className: "text-muted-foreground",
26621
+ children: [
26622
+ "[",
26623
+ formatValue(row.low),
26624
+ ", ",
26625
+ formatValue(row.high),
26626
+ "]"
26627
+ ]
26628
+ })] }) : /* @__PURE__ */ jsx("span", {
26629
+ className: "text-muted-foreground",
26630
+ children: "—"
26631
+ })
26632
+ }),
26633
+ /* @__PURE__ */ jsx("div", {
26634
+ className: "text-right font-mono type-caption tabular-nums text-muted-foreground",
26635
+ children: row.n
26636
+ }),
26637
+ hasGuards && /* @__PURE__ */ jsx("div", {
26638
+ className: "flex flex-wrap gap-1",
26639
+ children: row.guards?.map((g) => /* @__PURE__ */ jsxs("span", {
26640
+ className: cn("inline-flex items-center gap-0.5 rounded-control px-1.5 py-0.5 type-caption", g.passed === true && "bg-success-subtle text-success", g.passed === false && "bg-danger-subtle text-danger", g.passed === null && "bg-muted text-muted-foreground"),
26641
+ children: [
26642
+ g.passed === true && /* @__PURE__ */ jsx(Check, {
26643
+ "aria-hidden": true,
26644
+ className: "size-3"
26645
+ }),
26646
+ g.passed === false && /* @__PURE__ */ jsx(X, {
26647
+ "aria-hidden": true,
26648
+ className: "size-3"
26649
+ }),
26650
+ /* @__PURE__ */ jsx("span", { children: g.label })
26651
+ ]
26652
+ }, g.label))
26653
+ }),
26654
+ hasVerdicts && /* @__PURE__ */ jsx("div", {
26655
+ className: "flex justify-end",
26656
+ children: row.verdict ? /* @__PURE__ */ jsx(Status, {
26657
+ tone: row.verdict.tone,
26658
+ children: row.verdict.label
26659
+ }) : null
26660
+ })
26661
+ ] });
26662
+ if (interactive) return /* @__PURE__ */ jsx("div", {
26663
+ role: "listitem",
26664
+ children: /* @__PURE__ */ jsx("button", {
26665
+ type: "button",
26666
+ onClick: () => onSelect?.(row),
26667
+ "aria-pressed": isSelected,
26668
+ style: { gridTemplateColumns: gridCols },
26669
+ className: cn("grid w-full items-center gap-3 px-4 py-1 text-left transition-state focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring", isSelected ? "bg-accent" : "hover:bg-muted/60"),
26670
+ children: content
26671
+ })
26672
+ }, row.id);
26673
+ return /* @__PURE__ */ jsx("div", {
26674
+ role: "listitem",
26675
+ style: { gridTemplateColumns: gridCols },
26676
+ className: cn("grid items-center gap-3 px-4 py-1", isSelected && "bg-accent"),
26677
+ children: content
26678
+ }, row.id);
26679
+ })
26680
+ }),
26681
+ /* @__PURE__ */ jsxs("div", {
26682
+ className: "grid items-center gap-3 border-t border-border bg-surface-sunken px-4 py-1",
26683
+ style: { gridTemplateColumns: gridCols },
26684
+ children: [
26685
+ /* @__PURE__ */ jsx("div", {
26686
+ className: "type-caption text-muted-foreground",
26687
+ children: minEffectLabel && /* @__PURE__ */ jsxs("span", {
26688
+ className: "inline-flex items-center gap-1.5",
26689
+ children: [/* @__PURE__ */ jsx("span", {
26690
+ "aria-hidden": true,
26691
+ className: "inline-block size-2.5 shrink-0 rounded-control border border-primary/50 bg-primary/15"
26692
+ }), minEffectLabel]
26693
+ })
26694
+ }),
26695
+ /* @__PURE__ */ jsx("svg", {
26696
+ width: plotWidth,
26697
+ height: AXIS_H,
26698
+ className: "block w-full overflow-visible",
26699
+ "aria-hidden": "true",
26700
+ children: labelTicks.map((t) => {
26701
+ const tx = xOf(t);
26702
+ return /* @__PURE__ */ jsxs("g", {
26703
+ transform: `translate(${tx}, 0)`,
26704
+ children: [/* @__PURE__ */ jsx("line", {
26705
+ y1: 0,
26706
+ y2: 5,
26707
+ stroke: "var(--border)",
26708
+ strokeWidth: 1
26709
+ }), /* @__PURE__ */ jsx("text", {
26710
+ y: 18,
26711
+ textAnchor: "middle",
26712
+ fill: "var(--muted-foreground)",
26713
+ fontSize: 11,
26714
+ fontFamily: "var(--font-mono)",
26715
+ children: formatValue(t)
26716
+ })]
26717
+ }, t);
26718
+ })
26719
+ }),
26720
+ /* @__PURE__ */ jsx("div", {}),
26721
+ /* @__PURE__ */ jsx("div", {}),
26722
+ hasGuards && /* @__PURE__ */ jsx("div", {}),
26723
+ hasVerdicts && /* @__PURE__ */ jsx("div", {})
26724
+ ]
26725
+ })
26726
+ ]
26727
+ })
26728
+ }),
26729
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsxs("table", { children: [
26730
+ /* @__PURE__ */ jsx("caption", { children: label }),
26731
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
26732
+ /* @__PURE__ */ jsx("th", { children: "Candidate" }),
26733
+ /* @__PURE__ */ jsx("th", { children: "Effect" }),
26734
+ /* @__PURE__ */ jsx("th", { children: "Interval" }),
26735
+ /* @__PURE__ */ jsx("th", { children: "N" }),
26736
+ /* @__PURE__ */ jsx("th", { children: "Verdict" })
26737
+ ] }) }),
26738
+ /* @__PURE__ */ jsx("tbody", { children: rows.map((r) => /* @__PURE__ */ jsxs("tr", { children: [
26739
+ /* @__PURE__ */ jsx("td", { children: r.label }),
26740
+ /* @__PURE__ */ jsx("td", { children: r.estimate !== null ? formatValue(r.estimate) : "Not evaluated" }),
26741
+ /* @__PURE__ */ jsx("td", { children: r.low !== void 0 && r.low !== null && r.high !== void 0 && r.high !== null ? `${formatValue(r.low)} to ${formatValue(r.high)}` : "None" }),
26742
+ /* @__PURE__ */ jsx("td", { children: r.n }),
26743
+ /* @__PURE__ */ jsx("td", { children: r.verdict?.label ?? "" })
26744
+ ] }, r.id)) })
26745
+ ] }) })
26746
+ ]
26747
+ });
26748
+ }
26749
+
26750
+ // src/components/scatter-frontier.tsx
26751
+ const PAD = {
26752
+ top: 22,
26753
+ right: 24,
26754
+ bottom: 44,
26755
+ left: 64
26756
+ };
26757
+ const SHAPES = [
26758
+ "circle",
26759
+ "square",
26760
+ "diamond",
26761
+ "triangle"
26762
+ ];
26763
+ function renderShape(shape, cx, cy, r, fill, stroke, strokeWidth) {
26764
+ switch (shape) {
26765
+ case "square": return /* @__PURE__ */ jsx("rect", {
26766
+ x: cx - r,
26767
+ y: cy - r,
26768
+ width: r * 2,
26769
+ height: r * 2,
26770
+ rx: 1.5,
26771
+ fill,
26772
+ stroke,
26773
+ strokeWidth
26774
+ });
26775
+ case "diamond": return /* @__PURE__ */ jsx("polygon", {
26776
+ points: `${cx},${cy - r * 1.25} ${cx + r * 1.25},${cy} ${cx},${cy + r * 1.25} ${cx - r * 1.25},${cy}`,
26777
+ fill,
26778
+ stroke,
26779
+ strokeWidth
26780
+ });
26781
+ case "triangle": return /* @__PURE__ */ jsx("polygon", {
26782
+ points: `${cx},${cy - r * 1.25} ${cx + r * 1.2},${cy + r} ${cx - r * 1.2},${cy + r}`,
26783
+ fill,
26784
+ stroke,
26785
+ strokeWidth
26786
+ });
26787
+ default: return /* @__PURE__ */ jsx("circle", {
26788
+ cx,
26789
+ cy,
26790
+ r,
26791
+ fill,
26792
+ stroke,
26793
+ strokeWidth
26794
+ });
26795
+ }
26796
+ }
26797
+ /** Interactive 2D scatter plot with automatic Pareto frontier, switchable axes, category shapes and detail readout. */
26798
+ function ScatterFrontier({ label, points, xAxis, yAxis, showFrontier = true, showIntervals = false, height = 300, caveat, selectedId: controlledSelectedId, onSelect, className }) {
26799
+ const xAxes = Array.isArray(xAxis) ? xAxis : [xAxis];
26800
+ const yAxes = Array.isArray(yAxis) ? yAxis : [yAxis];
26801
+ const [xAxisId, setXAxisId] = React.useState(xAxes[0].id);
26802
+ const [yAxisId, setYAxisId] = React.useState(yAxes[0].id);
26803
+ const [internalSelected, setInternalSelected] = React.useState(null);
26804
+ const [hoveredId, setHoveredId] = React.useState(null);
26805
+ const activeX = xAxes.find((a) => a.id === xAxisId) ?? xAxes[0];
26806
+ const activeY = yAxes.find((a) => a.id === yAxisId) ?? yAxes[0];
26807
+ const selectedId = controlledSelectedId !== void 0 ? controlledSelectedId : internalSelected;
26808
+ const containerRef = React.useRef(null);
26809
+ const width = useContainerWidth(containerRef, 560);
26810
+ const resolved = React.useMemo(() => {
26811
+ return points.map((p) => {
26812
+ const xv = p.values ? p.values[activeX.id] : p.x;
26813
+ const yv = p.values ? p.values[activeY.id] : p.y;
26814
+ if (typeof xv !== "number" || !Number.isFinite(xv) || typeof yv !== "number" || !Number.isFinite(yv)) return null;
26815
+ return {
26816
+ point: p,
26817
+ id: p.id,
26818
+ x: xv,
26819
+ y: yv
26820
+ };
26821
+ }).filter((item) => item !== null);
26822
+ }, [
26823
+ points,
26824
+ activeX.id,
26825
+ activeY.id
26826
+ ]);
26827
+ const groups = React.useMemo(() => {
26828
+ const seen = [];
26829
+ for (const r of resolved) {
26830
+ const g = r.point.group;
26831
+ if (g && !seen.includes(g)) seen.push(g);
26832
+ }
26833
+ return seen;
26834
+ }, [resolved]);
26835
+ const frontier = React.useMemo(() => paretoFrontier(resolved, activeX.direction, activeY.direction), [
26836
+ resolved,
26837
+ activeX.direction,
26838
+ activeY.direction
26839
+ ]);
26840
+ const xScale = React.useMemo(() => {
26841
+ const vals = [];
26842
+ for (const r of resolved) {
26843
+ vals.push(r.x);
26844
+ if (r.point.xLow !== void 0 && Number.isFinite(r.point.xLow)) vals.push(r.point.xLow);
26845
+ if (r.point.xHigh !== void 0 && Number.isFinite(r.point.xHigh)) vals.push(r.point.xHigh);
26846
+ }
26847
+ return vals.length ? niceScale(Math.min(...vals), Math.max(...vals), 5) : niceScale(0, 1, 5);
26848
+ }, [resolved]);
26849
+ const yScale = React.useMemo(() => {
26850
+ const vals = [];
26851
+ for (const r of resolved) {
26852
+ vals.push(r.y);
26853
+ if (r.point.yLow !== void 0 && Number.isFinite(r.point.yLow)) vals.push(r.point.yLow);
26854
+ if (r.point.yHigh !== void 0 && Number.isFinite(r.point.yHigh)) vals.push(r.point.yHigh);
26855
+ }
26856
+ return vals.length ? niceScale(Math.min(...vals), Math.max(...vals), 5) : niceScale(0, 1, 5);
26857
+ }, [resolved]);
26858
+ const innerW = Math.max(160, width - PAD.left - PAD.right);
26859
+ const innerH = Math.max(120, height - PAD.top - PAD.bottom);
26860
+ const xSpan = xScale.max - xScale.min || 1;
26861
+ const ySpan = yScale.max - yScale.min || 1;
26862
+ const px = (v) => PAD.left + (v - xScale.min) / xSpan * innerW;
26863
+ const py = (v) => PAD.top + (1 - (v - yScale.min) / ySpan) * innerH;
26864
+ const activeDetailId = selectedId ?? hoveredId;
26865
+ const activeDetail = resolved.find((r) => r.id === activeDetailId) ?? null;
26866
+ const handleSelect = (p) => {
26867
+ const next = selectedId === p.id ? null : p;
26868
+ if (controlledSelectedId === void 0) setInternalSelected(next?.id ?? null);
26869
+ onSelect?.(next);
26870
+ };
26871
+ const betterCornerX = activeX.direction === "higher" ? PAD.left + innerW - 6 : PAD.left + 6;
26872
+ const betterCornerY = activeY.direction === "higher" ? PAD.top + 12 : PAD.top + innerH - 8;
26873
+ const betterAnchor = activeX.direction === "higher" ? "end" : "start";
26874
+ const frontierPath = showFrontier && frontier.ordered.length > 1 ? frontier.ordered.map((p, i) => `${i === 0 ? "M" : "L"}${px(p.x).toFixed(1)},${py(p.y).toFixed(1)}`).join(" ") : null;
26875
+ return /* @__PURE__ */ jsxs("figure", {
26876
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
26877
+ children: [
26878
+ /* @__PURE__ */ jsxs("figcaption", {
26879
+ className: "flex flex-wrap items-center justify-between gap-3 border-b border-border px-4 py-2.5",
26880
+ children: [/* @__PURE__ */ jsx("span", {
26881
+ className: "type-label text-foreground",
26882
+ children: label
26883
+ }), (xAxes.length > 1 || yAxes.length > 1) && /* @__PURE__ */ jsxs("div", {
26884
+ className: "flex flex-wrap items-center gap-2",
26885
+ children: [yAxes.length > 1 && /* @__PURE__ */ jsxs("label", {
26886
+ className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground",
26887
+ children: [/* @__PURE__ */ jsx("span", { children: "Y:" }), /* @__PURE__ */ jsx("select", {
26888
+ "aria-label": "Y axis metric",
26889
+ value: activeY.id,
26890
+ onChange: (e) => setYAxisId(e.target.value),
26891
+ className: "rounded-control border border-border bg-background px-2 py-0.5 type-caption text-foreground focus-visible:outline-2 focus-visible:outline-ring",
26892
+ children: yAxes.map((a) => /* @__PURE__ */ jsx("option", {
26893
+ value: a.id,
26894
+ children: a.label
26895
+ }, a.id))
26896
+ })]
26897
+ }), xAxes.length > 1 && /* @__PURE__ */ jsxs("label", {
26898
+ className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground",
26899
+ children: [/* @__PURE__ */ jsx("span", { children: "X:" }), /* @__PURE__ */ jsx("select", {
26900
+ "aria-label": "X axis metric",
26901
+ value: activeX.id,
26902
+ onChange: (e) => setXAxisId(e.target.value),
26903
+ className: "rounded-control border border-border bg-background px-2 py-0.5 type-caption text-foreground focus-visible:outline-2 focus-visible:outline-ring",
26904
+ children: xAxes.map((a) => /* @__PURE__ */ jsx("option", {
26905
+ value: a.id,
26906
+ children: a.label
26907
+ }, a.id))
26908
+ })]
26909
+ })]
26910
+ })]
26911
+ }),
26912
+ (groups.length > 0 || showFrontier) && /* @__PURE__ */ jsxs("div", {
26913
+ className: "flex flex-wrap items-center gap-x-4 gap-y-1 border-b border-border bg-surface-sunken px-4 py-1.5 type-caption text-muted-foreground",
26914
+ children: [groups.map((g, idx) => /* @__PURE__ */ jsxs("span", {
26915
+ className: "inline-flex items-center gap-1.5",
26916
+ children: [/* @__PURE__ */ jsx("svg", {
26917
+ width: 12,
26918
+ height: 12,
26919
+ "aria-hidden": "true",
26920
+ children: renderShape(SHAPES[idx % SHAPES.length], 6, 6, 4, chartColour(idx), "var(--card)", 1)
26921
+ }), /* @__PURE__ */ jsx("span", { children: g })]
26922
+ }, g)), showFrontier && /* @__PURE__ */ jsxs("span", {
26923
+ className: "inline-flex items-center gap-1.5",
26924
+ children: [/* @__PURE__ */ jsx("svg", {
26925
+ width: 18,
26926
+ height: 10,
26927
+ "aria-hidden": "true",
26928
+ children: /* @__PURE__ */ jsx("line", {
26929
+ x1: 0,
26930
+ x2: 18,
26931
+ y1: 5,
26932
+ y2: 5,
26933
+ stroke: "var(--primary)",
26934
+ strokeWidth: 1.75,
26935
+ strokeDasharray: "4 3"
26936
+ })
26937
+ }), /* @__PURE__ */ jsx("span", { children: "Pareto frontier" })]
26938
+ })]
26939
+ }),
26940
+ /* @__PURE__ */ jsx("div", {
26941
+ ref: containerRef,
26942
+ className: "px-2 pt-2",
26943
+ children: /* @__PURE__ */ jsxs("svg", {
26944
+ width,
26945
+ height,
26946
+ className: "block w-full select-none overflow-visible",
26947
+ role: "img",
26948
+ "aria-label": label,
26949
+ children: [
26950
+ yScale.ticks.map((t) => {
26951
+ const y = py(t);
26952
+ return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
26953
+ x1: PAD.left,
26954
+ x2: PAD.left + innerW,
26955
+ y1: y,
26956
+ y2: y,
26957
+ stroke: "var(--border)",
26958
+ strokeOpacity: .6
26959
+ }), /* @__PURE__ */ jsx("text", {
26960
+ x: PAD.left - 8,
26961
+ y: y + 3.5,
26962
+ textAnchor: "end",
26963
+ fill: "var(--muted-foreground)",
26964
+ fontSize: 11,
26965
+ fontFamily: "var(--font-mono)",
26966
+ children: activeY.format(t)
26967
+ })] }, `y-${t}`);
26968
+ }),
26969
+ xScale.ticks.map((t) => {
26970
+ const x = px(t);
26971
+ return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
26972
+ x1: x,
26973
+ x2: x,
26974
+ y1: PAD.top,
26975
+ y2: PAD.top + innerH,
26976
+ stroke: "var(--border)",
26977
+ strokeOpacity: .45
26978
+ }), /* @__PURE__ */ jsx("text", {
26979
+ x,
26980
+ y: PAD.top + innerH + 16,
26981
+ textAnchor: "middle",
26982
+ fill: "var(--muted-foreground)",
26983
+ fontSize: 11,
26984
+ fontFamily: "var(--font-mono)",
26985
+ children: activeX.format(t)
26986
+ })] }, `x-${t}`);
26987
+ }),
26988
+ /* @__PURE__ */ jsxs("text", {
26989
+ x: PAD.left + innerW / 2,
26990
+ y: height - 6,
26991
+ textAnchor: "middle",
26992
+ fill: "var(--muted-foreground)",
26993
+ fontSize: 12,
26994
+ children: [
26995
+ activeX.label,
26996
+ " ",
26997
+ activeX.direction === "higher" ? "(higher is better)" : "(lower is better)"
26998
+ ]
26999
+ }),
27000
+ /* @__PURE__ */ jsxs("text", {
27001
+ x: 14,
27002
+ y: PAD.top + innerH / 2,
27003
+ textAnchor: "middle",
27004
+ fill: "var(--muted-foreground)",
27005
+ fontSize: 12,
27006
+ transform: `rotate(-90, 14, ${PAD.top + innerH / 2})`,
27007
+ children: [
27008
+ activeY.label,
27009
+ " ",
27010
+ activeY.direction === "higher" ? "(higher is better)" : "(lower is better)"
27011
+ ]
27012
+ }),
27013
+ /* @__PURE__ */ jsx("text", {
27014
+ x: betterCornerX,
27015
+ y: betterCornerY,
27016
+ textAnchor: betterAnchor,
27017
+ fill: "var(--primary)",
27018
+ fillOpacity: .8,
27019
+ fontSize: 11,
27020
+ fontWeight: 500,
27021
+ children: "Better corner"
27022
+ }),
27023
+ frontierPath && /* @__PURE__ */ jsx("path", {
27024
+ d: frontierPath,
27025
+ fill: "none",
27026
+ stroke: "var(--primary)",
27027
+ strokeWidth: 1.75,
27028
+ strokeDasharray: "5 4",
27029
+ strokeOpacity: .8
27030
+ }),
27031
+ resolved.map(({ point, id, x, y }) => {
27032
+ const cx = px(x);
27033
+ const cy = py(y);
27034
+ const isFrontier = frontier.ids.has(id);
27035
+ const isSelected = selectedId === id;
27036
+ const isHovered = hoveredId === id;
27037
+ const groupIdx = point.group ? groups.indexOf(point.group) : 0;
27038
+ const shape = SHAPES[Math.max(0, groupIdx) % SHAPES.length];
27039
+ const colour = point.group ? chartColour(Math.max(0, groupIdx)) : isFrontier ? "var(--primary)" : "var(--muted-foreground)";
27040
+ const showCrosshair = showIntervals || isSelected || isHovered;
27041
+ const labelRight = cx < PAD.left + innerW * .72;
27042
+ return /* @__PURE__ */ jsxs("g", {
27043
+ role: "button",
27044
+ tabIndex: 0,
27045
+ "aria-label": `${point.label}: ${activeX.label} ${activeX.format(x)}, ${activeY.label} ${activeY.format(y)}${isFrontier ? ", on Pareto frontier" : ""}`,
27046
+ "aria-pressed": isSelected,
27047
+ onClick: () => handleSelect(point),
27048
+ onMouseEnter: () => setHoveredId(id),
27049
+ onMouseLeave: () => setHoveredId((prev) => prev === id ? null : prev),
27050
+ onKeyDown: (e) => {
27051
+ if (e.key === "Enter" || e.key === " ") {
27052
+ e.preventDefault();
27053
+ handleSelect(point);
27054
+ }
27055
+ },
27056
+ className: "cursor-pointer outline-none focus-visible:opacity-100",
27057
+ children: [
27058
+ showCrosshair && point.xLow !== void 0 && point.xHigh !== void 0 && /* @__PURE__ */ jsx("line", {
27059
+ x1: px(point.xLow),
27060
+ x2: px(point.xHigh),
27061
+ y1: cy,
27062
+ y2: cy,
27063
+ stroke: colour,
27064
+ strokeWidth: 1.5,
27065
+ strokeOpacity: .7
27066
+ }),
27067
+ showCrosshair && point.yLow !== void 0 && point.yHigh !== void 0 && /* @__PURE__ */ jsx("line", {
27068
+ x1: cx,
27069
+ x2: cx,
27070
+ y1: py(point.yLow),
27071
+ y2: py(point.yHigh),
27072
+ stroke: colour,
27073
+ strokeWidth: 1.5,
27074
+ strokeOpacity: .7
27075
+ }),
27076
+ (isSelected || isHovered) && /* @__PURE__ */ jsx("circle", {
27077
+ cx,
27078
+ cy,
27079
+ r: 10,
27080
+ fill: colour,
27081
+ fillOpacity: .16,
27082
+ stroke: colour,
27083
+ strokeWidth: 1.5
27084
+ }),
27085
+ renderShape(shape, cx, cy, isSelected ? 6 : isFrontier ? 5.5 : 4.5, isFrontier || isSelected ? colour : "var(--card)", isFrontier || isSelected ? "var(--card)" : colour, isFrontier || isSelected ? 1.5 : 2),
27086
+ (isFrontier || isSelected || isHovered) && /* @__PURE__ */ jsx("text", {
27087
+ x: labelRight ? cx + 9 : cx - 9,
27088
+ y: cy + 3.5,
27089
+ textAnchor: labelRight ? "start" : "end",
27090
+ fill: "var(--foreground)",
27091
+ fontSize: 11,
27092
+ fontWeight: isSelected ? 600 : 500,
27093
+ children: point.label
27094
+ })
27095
+ ]
27096
+ }, id);
27097
+ })
27098
+ ]
27099
+ })
27100
+ }),
27101
+ /* @__PURE__ */ jsx("div", {
27102
+ className: "flex flex-wrap items-center justify-between gap-2 border-t border-border bg-surface-sunken px-4 py-2 type-caption",
27103
+ children: activeDetail ? /* @__PURE__ */ jsxs(Fragment, { children: [
27104
+ /* @__PURE__ */ jsxs("div", {
27105
+ className: "flex flex-wrap items-center gap-2",
27106
+ children: [
27107
+ /* @__PURE__ */ jsx("span", {
27108
+ className: "font-medium text-foreground",
27109
+ children: activeDetail.point.label
27110
+ }),
27111
+ activeDetail.point.group && /* @__PURE__ */ jsxs("span", {
27112
+ className: "text-muted-foreground",
27113
+ children: [
27114
+ "(",
27115
+ activeDetail.point.group,
27116
+ ")"
27117
+ ]
27118
+ }),
27119
+ frontier.ids.has(activeDetail.id) && /* @__PURE__ */ jsx(Status, {
27120
+ tone: "info",
27121
+ children: "Frontier"
27122
+ }),
27123
+ activeDetail.point.status && /* @__PURE__ */ jsx(Status, {
27124
+ tone: activeDetail.point.status.tone,
27125
+ children: activeDetail.point.status.label
27126
+ })
27127
+ ]
27128
+ }),
27129
+ /* @__PURE__ */ jsxs("div", {
27130
+ className: "flex flex-wrap items-center gap-3 font-mono tabular-nums text-foreground",
27131
+ children: [
27132
+ /* @__PURE__ */ jsxs("span", { children: [
27133
+ activeX.label,
27134
+ ": ",
27135
+ /* @__PURE__ */ jsx("strong", { children: activeX.format(activeDetail.x) })
27136
+ ] }),
27137
+ /* @__PURE__ */ jsxs("span", { children: [
27138
+ activeY.label,
27139
+ ": ",
27140
+ /* @__PURE__ */ jsx("strong", { children: activeY.format(activeDetail.y) })
27141
+ ] }),
27142
+ activeDetail.point.n !== void 0 && /* @__PURE__ */ jsxs("span", {
27143
+ className: "text-muted-foreground",
27144
+ children: ["N=", activeDetail.point.n]
27145
+ })
27146
+ ]
27147
+ }),
27148
+ activeDetail.point.note && /* @__PURE__ */ jsx("div", {
27149
+ className: "w-full text-muted-foreground",
27150
+ children: activeDetail.point.note
27151
+ })
27152
+ ] }) : /* @__PURE__ */ jsx("span", {
27153
+ className: "text-muted-foreground",
27154
+ children: caveat ?? "Select or hover a candidate to inspect its metrics and configuration."
27155
+ })
27156
+ }),
27157
+ caveat && activeDetail && /* @__PURE__ */ jsx("div", {
27158
+ className: "border-t border-border px-4 py-1.5 type-caption text-muted-foreground",
27159
+ children: caveat
27160
+ }),
27161
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsxs("table", { children: [
27162
+ /* @__PURE__ */ jsx("caption", { children: label }),
27163
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
27164
+ /* @__PURE__ */ jsx("th", { children: "Candidate" }),
27165
+ /* @__PURE__ */ jsx("th", { children: "Group" }),
27166
+ /* @__PURE__ */ jsx("th", { children: activeX.label }),
27167
+ /* @__PURE__ */ jsx("th", { children: activeY.label }),
27168
+ /* @__PURE__ */ jsx("th", { children: "Pareto frontier" })
27169
+ ] }) }),
27170
+ /* @__PURE__ */ jsx("tbody", { children: resolved.map(({ point, id, x, y }) => /* @__PURE__ */ jsxs("tr", { children: [
27171
+ /* @__PURE__ */ jsx("td", { children: point.label }),
27172
+ /* @__PURE__ */ jsx("td", { children: point.group ?? "" }),
27173
+ /* @__PURE__ */ jsx("td", { children: activeX.format(x) }),
27174
+ /* @__PURE__ */ jsx("td", { children: activeY.format(y) }),
27175
+ /* @__PURE__ */ jsx("td", { children: frontier.ids.has(id) ? "Yes" : "No" })
27176
+ ] }, id)) })
27177
+ ] }) })
27178
+ ]
27179
+ });
27180
+ }
27181
+
27182
+ // src/components/metric-distribution.tsx
27183
+ const PAD_X = 14;
27184
+ const ROW_H = 44;
27185
+ const ECDF_H = 240;
27186
+ const ECDF_PAD = {
27187
+ top: 16,
27188
+ right: 20,
27189
+ bottom: 38,
27190
+ left: 48
27191
+ };
27192
+ /** Per-item outcome distribution (Strip + IQR box plot and ECDF toggle) with explicit missing counts. */
27193
+ function MetricDistribution({ label, series, formatValue, metricLabel, defaultMode = "strip", allowModeSwitch = true, onItemSelect, className }) {
27194
+ const [mode, setMode] = React.useState(defaultMode);
27195
+ const [hoveredItem, setHoveredItem] = React.useState(null);
27196
+ const trackRef = React.useRef(null);
27197
+ const trackWidth = useContainerWidth(trackRef, 360);
27198
+ const ecdfRef = React.useRef(null);
27199
+ const ecdfWidth = useContainerWidth(ecdfRef, 560);
27200
+ const summaries = React.useMemo(() => series.map((s) => ({
27201
+ series: s,
27202
+ summary: summarizeDistribution(s.items.map((i) => i.value))
27203
+ })), [series]);
27204
+ const scale = React.useMemo(() => {
27205
+ const vals = [];
27206
+ for (const s of series) for (const item of s.items) if (Number.isFinite(item.value)) vals.push(item.value);
27207
+ return vals.length ? niceScale(Math.min(...vals), Math.max(...vals), 5) : niceScale(0, 1, 5);
27208
+ }, [series]);
27209
+ const span = scale.max - scale.min || 1;
27210
+ const innerStripW = Math.max(120, trackWidth - 28);
27211
+ const xStrip = (v) => PAD_X + (v - scale.min) / span * innerStripW;
27212
+ const innerEcdfW = Math.max(160, ecdfWidth - ECDF_PAD.left - ECDF_PAD.right);
27213
+ const innerEcdfH = ECDF_H - ECDF_PAD.top - ECDF_PAD.bottom;
27214
+ const xEcdf = (v) => ECDF_PAD.left + (v - scale.min) / span * innerEcdfW;
27215
+ const yEcdf = (p) => ECDF_PAD.top + (1 - p) * innerEcdfH;
27216
+ return /* @__PURE__ */ jsxs("figure", {
27217
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
27218
+ children: [
27219
+ /* @__PURE__ */ jsxs("figcaption", {
27220
+ className: "flex flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-2.5",
27221
+ children: [/* @__PURE__ */ jsxs("div", {
27222
+ className: "flex flex-wrap items-baseline gap-2",
27223
+ children: [/* @__PURE__ */ jsx("span", {
27224
+ className: "type-label text-foreground",
27225
+ children: label
27226
+ }), /* @__PURE__ */ jsx("span", {
27227
+ className: "type-caption text-muted-foreground",
27228
+ children: metricLabel
27229
+ })]
27230
+ }), allowModeSwitch && /* @__PURE__ */ jsxs("div", {
27231
+ role: "group",
27232
+ "aria-label": "Distribution view",
27233
+ className: "inline-flex rounded-control border border-border bg-surface-sunken p-0.5",
27234
+ children: [/* @__PURE__ */ jsx("button", {
27235
+ type: "button",
27236
+ "aria-pressed": mode === "strip",
27237
+ onClick: () => setMode("strip"),
27238
+ className: cn("rounded-control px-2 py-0.5 type-caption transition-state focus-visible:outline-2 focus-visible:outline-ring", mode === "strip" ? "bg-card font-medium text-foreground" : "text-muted-foreground hover:text-foreground"),
27239
+ children: "Strip + IQR"
27240
+ }), /* @__PURE__ */ jsx("button", {
27241
+ type: "button",
27242
+ "aria-pressed": mode === "ecdf",
27243
+ onClick: () => setMode("ecdf"),
27244
+ className: cn("rounded-control px-2 py-0.5 type-caption transition-state focus-visible:outline-2 focus-visible:outline-ring", mode === "ecdf" ? "bg-card font-medium text-foreground" : "text-muted-foreground hover:text-foreground"),
27245
+ children: "ECDF"
27246
+ })]
27247
+ })]
27248
+ }),
27249
+ mode === "strip" ? /* @__PURE__ */ jsx("div", {
27250
+ className: "overflow-x-auto",
27251
+ children: /* @__PURE__ */ jsxs("div", {
27252
+ className: "min-w-[580px]",
27253
+ children: [
27254
+ /* @__PURE__ */ jsxs("div", {
27255
+ className: "grid items-center gap-3 border-b border-border bg-surface-sunken px-4 py-1.5 type-caption text-muted-foreground",
27256
+ style: { gridTemplateColumns: "minmax(140px, 1.2fr) minmax(220px, 2.2fr) minmax(130px, 1fr) 72px" },
27257
+ children: [
27258
+ /* @__PURE__ */ jsx("div", { children: "Candidate" }),
27259
+ /* @__PURE__ */ jsx("div", {
27260
+ ref: trackRef,
27261
+ children: metricLabel
27262
+ }),
27263
+ /* @__PURE__ */ jsx("div", {
27264
+ className: "text-right",
27265
+ children: "Median (IQR)"
27266
+ }),
27267
+ /* @__PURE__ */ jsx("div", {
27268
+ className: "text-right",
27269
+ children: "N"
27270
+ })
27271
+ ]
27272
+ }),
27273
+ /* @__PURE__ */ jsx("div", {
27274
+ className: "divide-y divide-border",
27275
+ children: summaries.map(({ series: s, summary }, idx) => {
27276
+ const colour = s.baseline ? "var(--muted-foreground)" : chartColour(idx);
27277
+ return /* @__PURE__ */ jsxs("div", {
27278
+ style: { gridTemplateColumns: "minmax(140px, 1.2fr) minmax(220px, 2.2fr) minmax(130px, 1fr) 72px" },
27279
+ className: "grid items-center gap-3 px-4 py-1",
27280
+ children: [
27281
+ /* @__PURE__ */ jsxs("div", {
27282
+ className: "min-w-0",
27283
+ children: [/* @__PURE__ */ jsx("div", {
27284
+ className: "truncate type-label text-foreground",
27285
+ children: s.label
27286
+ }), s.subtitle && /* @__PURE__ */ jsx("div", {
27287
+ className: "truncate type-caption text-muted-foreground",
27288
+ children: s.subtitle
27289
+ })]
27290
+ }),
27291
+ /* @__PURE__ */ jsx("div", {
27292
+ className: "h-[44px] w-full",
27293
+ children: /* @__PURE__ */ jsxs("svg", {
27294
+ width: trackWidth,
27295
+ height: ROW_H,
27296
+ className: "block h-full w-full overflow-visible",
27297
+ "aria-hidden": "true",
27298
+ children: [
27299
+ scale.ticks.map((t) => /* @__PURE__ */ jsx("line", {
27300
+ x1: xStrip(t),
27301
+ x2: xStrip(t),
27302
+ y1: 0,
27303
+ y2: ROW_H,
27304
+ stroke: "var(--border)",
27305
+ strokeOpacity: .5
27306
+ }, t)),
27307
+ summary && /* @__PURE__ */ jsxs(Fragment, { children: [
27308
+ /* @__PURE__ */ jsx("line", {
27309
+ x1: xStrip(summary.min),
27310
+ x2: xStrip(summary.max),
27311
+ y1: ROW_H / 2,
27312
+ y2: ROW_H / 2,
27313
+ stroke: colour,
27314
+ strokeOpacity: .45,
27315
+ strokeWidth: 1.5
27316
+ }),
27317
+ /* @__PURE__ */ jsx("rect", {
27318
+ x: xStrip(summary.p25),
27319
+ y: ROW_H / 2 - 9,
27320
+ width: Math.max(2, xStrip(summary.p75) - xStrip(summary.p25)),
27321
+ height: 18,
27322
+ rx: 2,
27323
+ fill: colour,
27324
+ fillOpacity: .18,
27325
+ stroke: colour,
27326
+ strokeWidth: 1.25
27327
+ }),
27328
+ /* @__PURE__ */ jsx("line", {
27329
+ x1: xStrip(summary.median),
27330
+ x2: xStrip(summary.median),
27331
+ y1: ROW_H / 2 - 11,
27332
+ y2: 33,
27333
+ stroke: colour,
27334
+ strokeWidth: 2.5,
27335
+ strokeLinecap: "round"
27336
+ })
27337
+ ] }),
27338
+ s.items.map((item) => {
27339
+ if (!Number.isFinite(item.value)) return null;
27340
+ const cx = xStrip(item.value);
27341
+ const cy = ROW_H / 2 + deterministicJitter(`${s.id}:${item.id}`) * 11;
27342
+ return /* @__PURE__ */ jsx("circle", {
27343
+ cx,
27344
+ cy,
27345
+ r: 3,
27346
+ fill: colour,
27347
+ fillOpacity: .78,
27348
+ stroke: "var(--card)",
27349
+ strokeWidth: .75,
27350
+ className: onItemSelect ? "cursor-pointer" : void 0,
27351
+ onMouseEnter: () => setHoveredItem({
27352
+ seriesLabel: s.label,
27353
+ item
27354
+ }),
27355
+ onMouseLeave: () => setHoveredItem(null),
27356
+ onClick: () => onItemSelect?.(s, item)
27357
+ }, item.id);
27358
+ })
27359
+ ]
27360
+ })
27361
+ }),
27362
+ /* @__PURE__ */ jsx("div", {
27363
+ className: "text-right font-mono type-caption tabular-nums",
27364
+ children: summary ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
27365
+ className: "font-medium text-foreground",
27366
+ children: formatValue(summary.median)
27367
+ }), /* @__PURE__ */ jsxs("div", {
27368
+ className: "text-muted-foreground",
27369
+ children: [
27370
+ formatValue(summary.p25),
27371
+ "–",
27372
+ formatValue(summary.p75)
27373
+ ]
27374
+ })] }) : /* @__PURE__ */ jsx("span", {
27375
+ className: "text-muted-foreground",
27376
+ children: "—"
27377
+ })
27378
+ }),
27379
+ /* @__PURE__ */ jsxs("div", {
27380
+ className: "flex flex-col items-end gap-0.5 font-mono type-caption tabular-nums",
27381
+ children: [/* @__PURE__ */ jsx("span", {
27382
+ className: "text-foreground",
27383
+ children: summary?.n ?? 0
27384
+ }), s.missing !== void 0 && s.missing > 0 && /* @__PURE__ */ jsx(Status, {
27385
+ tone: "danger",
27386
+ children: `${s.missing} miss`
27387
+ })]
27388
+ })
27389
+ ]
27390
+ }, s.id);
27391
+ })
27392
+ }),
27393
+ /* @__PURE__ */ jsxs("div", {
27394
+ className: "grid items-center gap-3 border-t border-border bg-surface-sunken px-4 py-1",
27395
+ style: { gridTemplateColumns: "minmax(140px, 1.2fr) minmax(220px, 2.2fr) minmax(130px, 1fr) 72px" },
27396
+ children: [
27397
+ /* @__PURE__ */ jsx("div", {
27398
+ className: "truncate type-caption text-muted-foreground",
27399
+ children: hoveredItem ? `${hoveredItem.seriesLabel} · ${hoveredItem.item.label ?? hoveredItem.item.id}: ${formatValue(hoveredItem.item.value)}` : "Box = IQR · line = median"
27400
+ }),
27401
+ /* @__PURE__ */ jsx("svg", {
27402
+ width: trackWidth,
27403
+ height: 24,
27404
+ className: "block w-full overflow-visible",
27405
+ "aria-hidden": "true",
27406
+ children: scale.ticks.map((t) => /* @__PURE__ */ jsxs("g", {
27407
+ transform: `translate(${xStrip(t)}, 0)`,
27408
+ children: [/* @__PURE__ */ jsx("line", {
27409
+ y1: 0,
27410
+ y2: 4,
27411
+ stroke: "var(--border)"
27412
+ }), /* @__PURE__ */ jsx("text", {
27413
+ y: 16,
27414
+ textAnchor: "middle",
27415
+ fill: "var(--muted-foreground)",
27416
+ fontSize: 11,
27417
+ fontFamily: "var(--font-mono)",
27418
+ children: formatValue(t)
27419
+ })]
27420
+ }, t))
27421
+ }),
27422
+ /* @__PURE__ */ jsx("div", {}),
27423
+ /* @__PURE__ */ jsx("div", {})
27424
+ ]
27425
+ })
27426
+ ]
27427
+ })
27428
+ }) : /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
27429
+ className: "flex flex-wrap items-center gap-x-4 gap-y-1 border-b border-border bg-surface-sunken px-4 py-1.5 type-caption text-muted-foreground",
27430
+ children: series.map((s, idx) => /* @__PURE__ */ jsxs("span", {
27431
+ className: "inline-flex items-center gap-1.5",
27432
+ children: [/* @__PURE__ */ jsx("span", {
27433
+ "aria-hidden": true,
27434
+ className: "inline-block h-0.5 w-4",
27435
+ style: { backgroundColor: s.baseline ? "var(--muted-foreground)" : chartColour(idx) }
27436
+ }), /* @__PURE__ */ jsx("span", { children: s.label })]
27437
+ }, s.id))
27438
+ }), /* @__PURE__ */ jsx("div", {
27439
+ ref: ecdfRef,
27440
+ className: "px-2 py-2",
27441
+ children: /* @__PURE__ */ jsxs("svg", {
27442
+ width: ecdfWidth,
27443
+ height: ECDF_H,
27444
+ className: "block w-full overflow-visible",
27445
+ role: "img",
27446
+ "aria-label": `${label} ECDF`,
27447
+ children: [
27448
+ [
27449
+ 0,
27450
+ .25,
27451
+ .5,
27452
+ .75,
27453
+ 1
27454
+ ].map((p) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
27455
+ x1: ECDF_PAD.left,
27456
+ x2: ECDF_PAD.left + innerEcdfW,
27457
+ y1: yEcdf(p),
27458
+ y2: yEcdf(p),
27459
+ stroke: "var(--border)",
27460
+ strokeOpacity: .55
27461
+ }), /* @__PURE__ */ jsx("text", {
27462
+ x: ECDF_PAD.left - 8,
27463
+ y: yEcdf(p) + 3.5,
27464
+ textAnchor: "end",
27465
+ fill: "var(--muted-foreground)",
27466
+ fontSize: 11,
27467
+ fontFamily: "var(--font-mono)",
27468
+ children: `${Math.round(p * 100)}%`
27469
+ })] }, p)),
27470
+ scale.ticks.map((t) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
27471
+ x1: xEcdf(t),
27472
+ x2: xEcdf(t),
27473
+ y1: ECDF_PAD.top,
27474
+ y2: ECDF_PAD.top + innerEcdfH,
27475
+ stroke: "var(--border)",
27476
+ strokeOpacity: .4
27477
+ }), /* @__PURE__ */ jsx("text", {
27478
+ x: xEcdf(t),
27479
+ y: ECDF_PAD.top + innerEcdfH + 16,
27480
+ textAnchor: "middle",
27481
+ fill: "var(--muted-foreground)",
27482
+ fontSize: 11,
27483
+ fontFamily: "var(--font-mono)",
27484
+ children: formatValue(t)
27485
+ })] }, t)),
27486
+ /* @__PURE__ */ jsx("text", {
27487
+ x: ECDF_PAD.left + innerEcdfW / 2,
27488
+ y: 236,
27489
+ textAnchor: "middle",
27490
+ fill: "var(--muted-foreground)",
27491
+ fontSize: 12,
27492
+ children: metricLabel
27493
+ }),
27494
+ series.map((s, idx) => {
27495
+ const pts = ecdfPoints(s.items.map((i) => i.value));
27496
+ if (pts.length === 0) return null;
27497
+ const colour = s.baseline ? "var(--muted-foreground)" : chartColour(idx);
27498
+ const segs = [`M${xEcdf(pts[0].x).toFixed(1)},${yEcdf(0).toFixed(1)}`];
27499
+ for (let i = 0; i < pts.length; i++) {
27500
+ const pt = pts[i];
27501
+ const x = xEcdf(pt.x).toFixed(1);
27502
+ const y = yEcdf(pt.y).toFixed(1);
27503
+ if (i > 0) segs.push(`H${x}`);
27504
+ segs.push(`V${y}`);
27505
+ }
27506
+ segs.push(`H${xEcdf(scale.max).toFixed(1)}`);
27507
+ return /* @__PURE__ */ jsx("path", {
27508
+ d: segs.join(" "),
27509
+ fill: "none",
27510
+ stroke: colour,
27511
+ strokeWidth: s.baseline ? 1.75 : 2,
27512
+ strokeDasharray: s.baseline ? "4 3" : void 0
27513
+ }, s.id);
27514
+ })
27515
+ ]
27516
+ })
27517
+ })] }),
27518
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsxs("table", { children: [
27519
+ /* @__PURE__ */ jsx("caption", { children: label }),
27520
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
27521
+ /* @__PURE__ */ jsx("th", { children: "Candidate" }),
27522
+ /* @__PURE__ */ jsx("th", { children: "N" }),
27523
+ /* @__PURE__ */ jsx("th", { children: "Missing" }),
27524
+ /* @__PURE__ */ jsx("th", { children: "Min" }),
27525
+ /* @__PURE__ */ jsx("th", { children: "P25" }),
27526
+ /* @__PURE__ */ jsx("th", { children: "Median" }),
27527
+ /* @__PURE__ */ jsx("th", { children: "P75" }),
27528
+ /* @__PURE__ */ jsx("th", { children: "Max" })
27529
+ ] }) }),
27530
+ /* @__PURE__ */ jsx("tbody", { children: summaries.map(({ series: s, summary }) => /* @__PURE__ */ jsxs("tr", { children: [
27531
+ /* @__PURE__ */ jsx("td", { children: s.label }),
27532
+ /* @__PURE__ */ jsx("td", { children: summary?.n ?? 0 }),
27533
+ /* @__PURE__ */ jsx("td", { children: s.missing ?? 0 }),
27534
+ /* @__PURE__ */ jsx("td", { children: summary ? formatValue(summary.min) : "—" }),
27535
+ /* @__PURE__ */ jsx("td", { children: summary ? formatValue(summary.p25) : "—" }),
27536
+ /* @__PURE__ */ jsx("td", { children: summary ? formatValue(summary.median) : "—" }),
27537
+ /* @__PURE__ */ jsx("td", { children: summary ? formatValue(summary.p75) : "—" }),
27538
+ /* @__PURE__ */ jsx("td", { children: summary ? formatValue(summary.max) : "—" })
27539
+ ] }, s.id)) })
27540
+ ] }) })
27541
+ ]
27542
+ });
27543
+ }
27544
+
27545
+ // src/components/slice-matrix.tsx
27546
+ /** Candidate × dataset-slice matrix with subtle performance tinting, deltas vs baseline and low-N flagging. */
27547
+ function SliceMatrix({ label, columns, rows, formatValue, formatDelta, direction, lowNThreshold = 5, note, selectedCell, onCellSelect, className }) {
27548
+ const { minVal, maxVal } = React.useMemo(() => {
27549
+ const vals = [];
27550
+ for (const r of rows) for (const c of columns) {
27551
+ const v = r.cells[c.id]?.value;
27552
+ if (typeof v === "number" && Number.isFinite(v)) vals.push(v);
27553
+ }
27554
+ return vals.length ? {
27555
+ minVal: Math.min(...vals),
27556
+ maxVal: Math.max(...vals)
27557
+ } : {
27558
+ minVal: 0,
27559
+ maxVal: 1
27560
+ };
27561
+ }, [rows, columns]);
27562
+ const span = maxVal - minVal || 1;
27563
+ const cellTint = (value, lowN) => {
27564
+ if (value === null || value === void 0 || !Number.isFinite(value) || lowN) return void 0;
27565
+ const norm = (value - minVal) / span;
27566
+ const goodness = direction === "higher" ? norm : 1 - norm;
27567
+ const pct = Math.round(goodness * 18);
27568
+ if (pct <= 1) return void 0;
27569
+ return { backgroundColor: `color-mix(in oklch, var(--primary) ${pct}%, transparent)` };
27570
+ };
27571
+ return /* @__PURE__ */ jsxs("figure", {
27572
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
27573
+ children: [/* @__PURE__ */ jsxs("figcaption", {
27574
+ className: "flex flex-wrap items-baseline justify-between gap-2 border-b border-border px-4 py-2.5",
27575
+ children: [/* @__PURE__ */ jsx("span", {
27576
+ className: "type-label text-foreground",
27577
+ children: label
27578
+ }), note && /* @__PURE__ */ jsx("span", {
27579
+ className: "type-caption text-muted-foreground",
27580
+ children: note
27581
+ })]
27582
+ }), /* @__PURE__ */ jsx("div", {
27583
+ className: "overflow-x-auto",
27584
+ children: /* @__PURE__ */ jsxs("table", {
27585
+ className: "w-full border-collapse text-left",
27586
+ children: [
27587
+ /* @__PURE__ */ jsx("caption", {
27588
+ className: "sr-only",
27589
+ children: label
27590
+ }),
27591
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
27592
+ className: "border-b border-border bg-surface-sunken type-caption text-muted-foreground",
27593
+ children: [/* @__PURE__ */ jsx("th", {
27594
+ scope: "col",
27595
+ className: "px-4 py-2 font-medium",
27596
+ children: "Candidate"
27597
+ }), columns.map((col) => /* @__PURE__ */ jsxs("th", {
27598
+ scope: "col",
27599
+ className: "px-3 py-2 text-right font-medium",
27600
+ children: [/* @__PURE__ */ jsx("div", {
27601
+ className: "text-foreground",
27602
+ children: col.label
27603
+ }), col.n !== void 0 && /* @__PURE__ */ jsxs("div", {
27604
+ className: "font-mono tabular-nums text-muted-foreground",
27605
+ children: ["n=", col.n]
27606
+ })]
27607
+ }, col.id))]
27608
+ }) }),
27609
+ /* @__PURE__ */ jsx("tbody", {
27610
+ className: "divide-y divide-border",
27611
+ children: rows.map((row) => /* @__PURE__ */ jsxs("tr", {
27612
+ className: row.baseline ? "bg-surface-sunken/40" : void 0,
27613
+ children: [/* @__PURE__ */ jsxs("th", {
27614
+ scope: "row",
27615
+ className: "px-4 py-2 font-normal",
27616
+ children: [/* @__PURE__ */ jsx("div", {
27617
+ className: cn("type-label", row.baseline ? "text-muted-foreground" : "text-foreground"),
27618
+ children: row.label
27619
+ }), row.subtitle && /* @__PURE__ */ jsx("div", {
27620
+ className: "type-caption text-muted-foreground",
27621
+ children: row.subtitle
27622
+ })]
27623
+ }), columns.map((col) => {
27624
+ const cell = row.cells[col.id];
27625
+ const effectiveN = cell?.n ?? col.n;
27626
+ const isLowN = effectiveN !== void 0 && effectiveN < lowNThreshold;
27627
+ const isSelected = selectedCell?.rowId === row.id && selectedCell?.columnId === col.id;
27628
+ const hasValue = cell !== void 0 && cell.value !== null && Number.isFinite(cell.value);
27629
+ const hasDelta = !row.baseline && formatDelta !== void 0 && cell?.delta !== void 0 && cell.delta !== null && Number.isFinite(cell.delta);
27630
+ const inner = /* @__PURE__ */ jsxs("div", {
27631
+ className: "flex flex-col items-end font-mono tabular-nums",
27632
+ children: [
27633
+ /* @__PURE__ */ jsx("span", {
27634
+ className: cn("type-body-sm font-medium", !hasValue || isLowN ? "text-muted-foreground" : "text-foreground"),
27635
+ children: hasValue ? formatValue(cell.value) : "—"
27636
+ }),
27637
+ hasDelta && /* @__PURE__ */ jsx("span", {
27638
+ className: "type-caption text-muted-foreground",
27639
+ children: formatDelta(cell.delta)
27640
+ }),
27641
+ cell?.n !== void 0 && /* @__PURE__ */ jsxs("span", {
27642
+ className: "type-caption text-muted-foreground",
27643
+ children: [
27644
+ "n=",
27645
+ cell.n,
27646
+ isLowN ? " (low N)" : ""
27647
+ ]
27648
+ }),
27649
+ cell?.n === void 0 && isLowN && /* @__PURE__ */ jsx("span", {
27650
+ className: "type-caption text-muted-foreground",
27651
+ children: "low N"
27652
+ })
27653
+ ]
27654
+ });
27655
+ return /* @__PURE__ */ jsx("td", {
27656
+ style: cellTint(cell?.value, isLowN),
27657
+ className: cn("border-l border-border/60 p-0 text-right align-middle", isSelected && "ring-2 ring-inset ring-ring"),
27658
+ children: onCellSelect ? /* @__PURE__ */ jsx("button", {
27659
+ type: "button",
27660
+ onClick: () => onCellSelect(row, col, cell),
27661
+ "aria-pressed": isSelected,
27662
+ className: "block h-full w-full px-3 py-2 text-right transition-state hover:bg-accent/50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
27663
+ children: inner
27664
+ }) : /* @__PURE__ */ jsx("div", {
27665
+ className: "px-3 py-2",
27666
+ children: inner
27667
+ })
27668
+ }, col.id);
27669
+ })]
27670
+ }, row.id))
27671
+ })
27672
+ ]
27673
+ })
27674
+ })]
27675
+ });
27676
+ }
27677
+
27678
+ // src/components/confusion-matrix.tsx
27679
+ /** Interactive confusion or judge-agreement matrix with row-normalised percentages and clickable cells. */
27680
+ function ConfusionMatrix({ label, rowLabels, colLabels = rowLabels, counts, rowAxisLabel = "Reference", colAxisLabel = "Predicted", showPercent = true, summary, selectedCell, onCellSelect, className }) {
27681
+ const rowTotals = React.useMemo(() => rowLabels.map((_, r) => (counts[r] ?? []).reduce((acc, v) => acc + (Number.isFinite(v) ? v : 0), 0)), [rowLabels, counts]);
27682
+ const grandTotal = React.useMemo(() => rowTotals.reduce((a, b) => a + b, 0), [rowTotals]);
27683
+ const cellStyle = (rowIdx, colIdx, count, rowTotal) => {
27684
+ if (count <= 0 || rowTotal <= 0) return void 0;
27685
+ const share = count / rowTotal;
27686
+ const isDiagonal = rowLabels[rowIdx] === colLabels[colIdx];
27687
+ const pct = Math.max(4, Math.round(share * 22));
27688
+ return { backgroundColor: `color-mix(in oklch, ${isDiagonal ? "var(--primary)" : "var(--danger)"} ${pct}%, transparent)` };
27689
+ };
27690
+ return /* @__PURE__ */ jsxs("figure", {
27691
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
27692
+ children: [
27693
+ /* @__PURE__ */ jsxs("figcaption", {
27694
+ className: "flex flex-wrap items-baseline justify-between gap-2 border-b border-border px-4 py-2.5",
27695
+ children: [/* @__PURE__ */ jsx("span", {
27696
+ className: "type-label text-foreground",
27697
+ children: label
27698
+ }), /* @__PURE__ */ jsxs("span", {
27699
+ className: "font-mono type-caption tabular-nums text-muted-foreground",
27700
+ children: ["N=", grandTotal]
27701
+ })]
27702
+ }),
27703
+ /* @__PURE__ */ jsx("div", {
27704
+ className: "overflow-x-auto",
27705
+ children: /* @__PURE__ */ jsxs("table", {
27706
+ className: "w-full border-collapse text-left",
27707
+ children: [
27708
+ /* @__PURE__ */ jsx("caption", {
27709
+ className: "sr-only",
27710
+ children: label
27711
+ }),
27712
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
27713
+ className: "border-b border-border bg-surface-sunken type-caption text-muted-foreground",
27714
+ children: [
27715
+ /* @__PURE__ */ jsxs("th", {
27716
+ scope: "col",
27717
+ className: "px-3 py-2 font-medium",
27718
+ children: [
27719
+ rowAxisLabel,
27720
+ " \\ ",
27721
+ colAxisLabel
27722
+ ]
27723
+ }),
27724
+ colLabels.map((c) => /* @__PURE__ */ jsx("th", {
27725
+ scope: "col",
27726
+ className: "px-3 py-2 text-right font-medium text-foreground",
27727
+ children: c
27728
+ }, c)),
27729
+ /* @__PURE__ */ jsx("th", {
27730
+ scope: "col",
27731
+ className: "border-l border-border px-3 py-2 text-right font-medium",
27732
+ children: "Total"
27733
+ })
27734
+ ]
27735
+ }) }),
27736
+ /* @__PURE__ */ jsx("tbody", {
27737
+ className: "divide-y divide-border",
27738
+ children: rowLabels.map((rLabel, rIdx) => {
27739
+ const rTotal = rowTotals[rIdx] ?? 0;
27740
+ return /* @__PURE__ */ jsxs("tr", { children: [
27741
+ /* @__PURE__ */ jsx("th", {
27742
+ scope: "row",
27743
+ className: "px-3 py-2 type-label font-medium text-foreground",
27744
+ children: rLabel
27745
+ }),
27746
+ colLabels.map((cLabel, cIdx) => {
27747
+ const count = counts[rIdx]?.[cIdx] ?? 0;
27748
+ const share = rTotal > 0 ? count / rTotal : 0;
27749
+ const isSelected = selectedCell?.row === rIdx && selectedCell?.col === cIdx;
27750
+ const inner = /* @__PURE__ */ jsxs("div", {
27751
+ className: "flex flex-col items-end font-mono tabular-nums",
27752
+ children: [/* @__PURE__ */ jsx("span", {
27753
+ className: cn("type-body-sm", count === 0 ? "text-muted-foreground/50" : rLabel === cLabel ? "font-semibold text-foreground" : "font-medium text-foreground"),
27754
+ children: count
27755
+ }), showPercent && /* @__PURE__ */ jsx("span", {
27756
+ className: "type-caption text-muted-foreground",
27757
+ children: count === 0 ? "0%" : `${Math.round(share * 100)}%`
27758
+ })]
27759
+ });
27760
+ return /* @__PURE__ */ jsx("td", {
27761
+ style: cellStyle(rIdx, cIdx, count, rTotal),
27762
+ className: cn("border-l border-border/60 p-0 text-right align-middle", isSelected && "ring-2 ring-inset ring-ring"),
27763
+ children: onCellSelect ? /* @__PURE__ */ jsx("button", {
27764
+ type: "button",
27765
+ onClick: () => onCellSelect({
27766
+ row: rIdx,
27767
+ col: cIdx,
27768
+ rowLabel: rLabel,
27769
+ colLabel: cLabel,
27770
+ count
27771
+ }),
27772
+ "aria-pressed": isSelected,
27773
+ "aria-label": `${rowAxisLabel} ${rLabel}, ${colAxisLabel} ${cLabel}: ${count}`,
27774
+ className: "block h-full w-full px-3 py-2 text-right transition-state hover:bg-accent/50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
27775
+ children: inner
27776
+ }) : /* @__PURE__ */ jsx("div", {
27777
+ className: "px-3 py-2",
27778
+ children: inner
27779
+ })
27780
+ }, cLabel);
27781
+ }),
27782
+ /* @__PURE__ */ jsx("td", {
27783
+ className: "border-l border-border bg-surface-sunken/50 px-3 py-2 text-right font-mono type-caption tabular-nums text-muted-foreground",
27784
+ children: rTotal
27785
+ })
27786
+ ] }, rLabel);
27787
+ })
27788
+ })
27789
+ ]
27790
+ })
27791
+ }),
27792
+ summary && summary.length > 0 && /* @__PURE__ */ jsx("div", {
27793
+ className: "flex flex-wrap items-center gap-x-5 gap-y-1 border-t border-border bg-surface-sunken px-4 py-2 type-caption",
27794
+ children: summary.map((s) => /* @__PURE__ */ jsxs("div", {
27795
+ className: "inline-flex items-baseline gap-1.5",
27796
+ children: [/* @__PURE__ */ jsxs("span", {
27797
+ className: "text-muted-foreground",
27798
+ children: [s.label, ":"]
27799
+ }), /* @__PURE__ */ jsx("span", {
27800
+ className: "font-mono font-medium tabular-nums text-foreground",
27801
+ children: s.value
27802
+ })]
27803
+ }, s.label))
27804
+ })
27805
+ ]
27806
+ });
27807
+ }
27808
+
27809
+ // src/components/pipeline-diagram.tsx
27810
+ function isParallelStep(step) {
27811
+ return "parallel" in step;
27812
+ }
27813
+ function StageCard({ stage, selected, onSelect }) {
27814
+ const inner = /* @__PURE__ */ jsxs(Fragment, { children: [
27815
+ /* @__PURE__ */ jsxs("div", {
27816
+ className: "flex items-start justify-between gap-2",
27817
+ children: [/* @__PURE__ */ jsxs("div", {
27818
+ className: "min-w-0",
27819
+ children: [/* @__PURE__ */ jsx("div", {
27820
+ className: "truncate type-label text-foreground",
27821
+ children: stage.label
27822
+ }), stage.subtitle && /* @__PURE__ */ jsx("div", {
27823
+ className: "truncate font-mono type-caption text-muted-foreground",
27824
+ children: stage.subtitle
27825
+ })]
27826
+ }), stage.status && /* @__PURE__ */ jsx(Status, {
27827
+ tone: stage.status.tone,
27828
+ children: stage.status.label
27829
+ })]
27830
+ }),
27831
+ stage.metrics && stage.metrics.length > 0 && /* @__PURE__ */ jsx("dl", {
27832
+ className: "mt-2 flex flex-wrap gap-x-3 gap-y-1 border-t border-border/70 pt-2 type-caption",
27833
+ children: stage.metrics.map((m) => /* @__PURE__ */ jsxs("div", {
27834
+ className: "inline-flex items-baseline gap-1",
27835
+ children: [/* @__PURE__ */ jsxs("dt", {
27836
+ className: "text-muted-foreground",
27837
+ children: [m.label, ":"]
27838
+ }), /* @__PURE__ */ jsx("dd", {
27839
+ className: "font-mono font-medium tabular-nums text-foreground",
27840
+ children: m.value
27841
+ })]
27842
+ }, m.label))
27843
+ }),
27844
+ stage.detail && /* @__PURE__ */ jsx("div", {
27845
+ className: "mt-2 rounded-control bg-surface-sunken px-2 py-1.5 type-caption text-muted-foreground",
27846
+ children: stage.detail
27847
+ })
27848
+ ] });
27849
+ const baseClass = cn("w-full rounded-surface border bg-card p-3 text-left transition-state", selected ? "border-primary bg-accent ring-1 ring-ring" : "border-border");
27850
+ if (onSelect) return /* @__PURE__ */ jsx("button", {
27851
+ type: "button",
27852
+ onClick: () => onSelect(stage),
27853
+ "aria-pressed": selected,
27854
+ className: cn(baseClass, "cursor-pointer hover:border-primary/60 hover:bg-muted/40 focus-visible:outline-2 focus-visible:outline-ring"),
27855
+ children: inner
27856
+ });
27857
+ return /* @__PURE__ */ jsx("div", {
27858
+ className: baseClass,
27859
+ children: inner
27860
+ });
27861
+ }
27862
+ /** Multi-stage pipeline and architecture flow diagram with parallel lane support and timing/cost summary. */
27863
+ function PipelineDiagram({ label, steps, note, summary, selectedId, onSelect, className }) {
27864
+ return /* @__PURE__ */ jsxs("figure", {
27865
+ className: cn("rounded-surface border border-border bg-card text-card-foreground", className),
27866
+ children: [
27867
+ /* @__PURE__ */ jsxs("figcaption", {
27868
+ className: "flex flex-wrap items-baseline justify-between gap-2 border-b border-border px-4 py-2.5",
27869
+ children: [/* @__PURE__ */ jsx("span", {
27870
+ className: "type-label text-foreground",
27871
+ children: label
27872
+ }), note && /* @__PURE__ */ jsx("span", {
27873
+ className: "type-caption text-muted-foreground",
27874
+ children: note
27875
+ })]
27876
+ }),
27877
+ /* @__PURE__ */ jsx("div", {
27878
+ className: "overflow-x-auto p-4",
27879
+ children: /* @__PURE__ */ jsx("ol", {
27880
+ "aria-label": label,
27881
+ className: "flex flex-col items-stretch gap-3 md:flex-row md:items-center",
27882
+ children: steps.map((step, idx) => {
27883
+ const isLast = idx === steps.length - 1;
27884
+ const edgeLabel = step.edgeLabel;
27885
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsx("li", {
27886
+ className: "min-w-[190px] flex-1",
27887
+ children: isParallelStep(step) ? /* @__PURE__ */ jsxs("div", {
27888
+ className: "rounded-surface border border-dashed border-border bg-surface-sunken/60 p-2.5",
27889
+ children: [step.groupLabel && /* @__PURE__ */ jsx("div", {
27890
+ className: "mb-2 type-caption font-medium text-muted-foreground",
27891
+ children: step.groupLabel
27892
+ }), /* @__PURE__ */ jsx("div", {
27893
+ className: "flex flex-col gap-2",
27894
+ children: step.parallel.map((stage) => /* @__PURE__ */ jsx(StageCard, {
27895
+ stage,
27896
+ selected: selectedId === stage.id,
27897
+ onSelect
27898
+ }, stage.id))
27899
+ })]
27900
+ }) : /* @__PURE__ */ jsx(StageCard, {
27901
+ stage: step,
27902
+ selected: selectedId === step.id,
27903
+ onSelect
27904
+ })
27905
+ }), !isLast && /* @__PURE__ */ jsxs("li", {
27906
+ "aria-hidden": "true",
27907
+ className: "flex shrink-0 flex-col items-center justify-center gap-0.5 text-muted-foreground",
27908
+ children: [
27909
+ /* @__PURE__ */ jsx(ArrowRight, { className: "hidden size-4 md:block" }),
27910
+ /* @__PURE__ */ jsx(ArrowDown, { className: "block size-4 md:hidden" }),
27911
+ edgeLabel && /* @__PURE__ */ jsx("span", {
27912
+ className: "max-w-[96px] text-center font-mono type-caption",
27913
+ children: edgeLabel
27914
+ })
27915
+ ]
27916
+ })] }, step.id);
27917
+ })
27918
+ })
27919
+ }),
27920
+ summary && summary.length > 0 && /* @__PURE__ */ jsx("div", {
27921
+ className: "flex flex-wrap items-center gap-x-5 gap-y-1 border-t border-border bg-surface-sunken px-4 py-2 type-caption",
27922
+ children: summary.map((item) => /* @__PURE__ */ jsxs("div", {
27923
+ className: "inline-flex items-baseline gap-1.5",
27924
+ children: [/* @__PURE__ */ jsxs("span", {
27925
+ className: "text-muted-foreground",
27926
+ children: [item.label, ":"]
27927
+ }), /* @__PURE__ */ jsx("span", {
27928
+ className: "font-mono font-medium tabular-nums text-foreground",
27929
+ children: item.value
27930
+ })]
27931
+ }, item.label))
27932
+ })
27933
+ ]
27934
+ });
27935
+ }
27936
+
27937
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BRUSHES, Balance, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, CHART_COLOURS, CLOCK_FACE_STYLES, CLOCK_STYLES, COINS, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, Clock, ClockFace, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Concealed, ConfusionMatrix, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DIGITAL_CLOCK_STYLES, DataTable, DataView$1 as DataView, Density, Dialog, DigitalClock, Disclosure, Done, DragSource, DrawingLayer, DrawingToolbar, EditListPlayer, EmptyState, EventLog, FACINGS, FIT, FRACTION_OUTLINES, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FillLevel, FilmStrip, FolderPicker, ForestPlot, FractionShape, FullscreenFrame, Glimpse, HttpError, INK_COLOURS, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, JsonView, KeysLegend, LEVEL_FLOOR_DB, LengthBar, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricDistribution, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, Money, NBSP, NOTES, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PartialDateField, PauseButton, PipelineDiagram, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RangeSlider, RateChoice, ReadAlong, RegionEditor, RichText, RowAction, SOLID_SHAPES, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, SayPicture, ScatterFrontier, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SetClock, ShortcutEditor, SideNav, Skeleton, SliceMatrix, Slider, Solid, SortableList, SpanActions, SpanStrip, SpeakerTimeline, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, TurnArrow, UNCLEAR, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, applyOp, assignTurns, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, chartColour, checkKey, clampToRoom, clampViewport, clipsQueryKey, clockParts, clockWords, cn, coinOutline, colorSchemeScript, commandShortcut, continues, copyTurns, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, currentOf, curvePoints, dayPart, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, deterministicJitter, diffWords, differences, digitalTime, diskThresholds, drawRect, drawingToSvg, ease, ecdfPoints, editTimeOf, editTimes, emptyDrawing, encodeWav, errorPayload, explainMicrophoneError, feedbackMarker, fetchJson, fieldErrorsOf, fillWords, filterMarkup, findPage, fitPoints, fitRect, followAim, format, formatChord, formatPartialDate, fractionParts, fractionWords, frameAt, freshId, gainToVolume, geo, gridPoints, gutterOf, hitsStroke, hourAt, inkMatch, inputLevelThresholds, invertOp, isDigitalStyle, isDoubtful, isRefusal, isReservedChord, isSpeaking, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, jsonBranchPaths, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, mediaStatRows, mergeWithNext, minutesAt, moneyWords, moveGutter, moveMinuteHand, movePoints, moveRect, newStrokeId, newVoiceName, nextBreak, niceScale, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, paretoFrontier, parseChord, parseInline, parsePartialDate, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, pointsBox, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, removeTurns, renameVoice, replay, resample, resamplePeaks, rescaleDrawing, resizeRect, rgbaToBlob, rmsDb, romanHour, safeHref, sayPosition, serialiseSort, setEdge, settleCut, simplifyPoints, skipAction, smoothPath, snapToGrid, solidWords, sortRows, speak, speechLevel, splitRect, splitTurn, staleOf, stepId, stepMinuteHand, stepOnGrid, stopSpeaking, strokeAt, strokeBox, strokeShape, summariseWorkflow, summarizeDistribution, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnWords, turned, turnedSize, turnsAt, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useCountdown, useDifference, useDrawing, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useInkMatch, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMediaStats, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useReadAloud, useRebindableShortcuts, useRecorder, useReserve, useRevealed, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeaking, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, voicesOf, widthsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
26233
27938
  //# sourceMappingURL=index.js.map