@lincyaw/aegis-ui 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/AgentHud.cjs +2 -0
- package/dist/components/ui/AgentHud.cjs.map +1 -0
- package/dist/components/ui/AgentHud.d.ts +23 -0
- package/dist/components/ui/AgentHud.js +45 -0
- package/dist/components/ui/AgentHud.js.map +1 -0
- package/dist/components/ui/ChartLegend.cjs +1 -1
- package/dist/components/ui/ChartLegend.cjs.map +1 -1
- package/dist/components/ui/ChartLegend.d.ts +2 -0
- package/dist/components/ui/ChartLegend.js +11 -10
- package/dist/components/ui/ChartLegend.js.map +1 -1
- package/dist/components/ui/ColumnChart.cjs +2 -0
- package/dist/components/ui/ColumnChart.cjs.map +1 -0
- package/dist/components/ui/ColumnChart.d.ts +46 -0
- package/dist/components/ui/ColumnChart.js +154 -0
- package/dist/components/ui/ColumnChart.js.map +1 -0
- package/dist/components/ui/DotRangeChart.cjs +2 -0
- package/dist/components/ui/DotRangeChart.cjs.map +1 -0
- package/dist/components/ui/DotRangeChart.d.ts +44 -0
- package/dist/components/ui/DotRangeChart.js +80 -0
- package/dist/components/ui/DotRangeChart.js.map +1 -0
- package/dist/components/ui/HeadlineStat.cjs +2 -0
- package/dist/components/ui/HeadlineStat.cjs.map +1 -0
- package/dist/components/ui/HeadlineStat.d.ts +10 -0
- package/dist/components/ui/HeadlineStat.js +22 -0
- package/dist/components/ui/HeadlineStat.js.map +1 -0
- package/dist/components/ui/Heatmap.cjs +2 -0
- package/dist/components/ui/Heatmap.cjs.map +1 -0
- package/dist/components/ui/Heatmap.d.ts +52 -0
- package/dist/components/ui/Heatmap.js +82 -0
- package/dist/components/ui/Heatmap.js.map +1 -0
- package/dist/components/ui/KeyMomentCard.cjs +2 -0
- package/dist/components/ui/KeyMomentCard.cjs.map +1 -0
- package/dist/components/ui/KeyMomentCard.d.ts +19 -0
- package/dist/components/ui/KeyMomentCard.js +45 -0
- package/dist/components/ui/KeyMomentCard.js.map +1 -0
- package/dist/components/ui/LineChart.cjs +2 -0
- package/dist/components/ui/LineChart.cjs.map +1 -0
- package/dist/components/ui/LineChart.d.ts +48 -0
- package/dist/components/ui/LineChart.js +199 -0
- package/dist/components/ui/LineChart.js.map +1 -0
- package/dist/components/ui/ParetoChart.cjs +1 -1
- package/dist/components/ui/ParetoChart.cjs.map +1 -1
- package/dist/components/ui/ParetoChart.d.ts +34 -2
- package/dist/components/ui/ParetoChart.js +250 -173
- package/dist/components/ui/ParetoChart.js.map +1 -1
- package/dist/components/ui/RankBar.cjs +1 -1
- package/dist/components/ui/RankBar.cjs.map +1 -1
- package/dist/components/ui/RankBar.d.ts +7 -3
- package/dist/components/ui/RankBar.js +64 -45
- package/dist/components/ui/RankBar.js.map +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs +1 -1
- package/dist/components/ui/ReplayStepStrip.cjs.map +1 -1
- package/dist/components/ui/ReplayStepStrip.d.ts +13 -1
- package/dist/components/ui/ReplayStepStrip.js +99 -76
- package/dist/components/ui/ReplayStepStrip.js.map +1 -1
- package/dist/components/ui/ResultMatrix.cjs +2 -0
- package/dist/components/ui/ResultMatrix.cjs.map +1 -0
- package/dist/components/ui/ResultMatrix.d.ts +23 -0
- package/dist/components/ui/ResultMatrix.js +53 -0
- package/dist/components/ui/ResultMatrix.js.map +1 -0
- package/dist/components/ui/ScrollStory.cjs +2 -2
- package/dist/components/ui/ScrollStory.cjs.map +1 -1
- package/dist/components/ui/ScrollStory.d.ts +3 -1
- package/dist/components/ui/ScrollStory.js +34 -32
- package/dist/components/ui/ScrollStory.js.map +1 -1
- package/dist/components/ui/SeriesLabel.cjs +2 -0
- package/dist/components/ui/SeriesLabel.cjs.map +1 -0
- package/dist/components/ui/SeriesLabel.d.ts +21 -0
- package/dist/components/ui/SeriesLabel.js +38 -0
- package/dist/components/ui/SeriesLabel.js.map +1 -0
- package/dist/components/ui/StackedBar.cjs +1 -1
- package/dist/components/ui/StackedBar.cjs.map +1 -1
- package/dist/components/ui/StackedBar.d.ts +13 -1
- package/dist/components/ui/StackedBar.js +95 -74
- package/dist/components/ui/StackedBar.js.map +1 -1
- package/dist/components/ui/TableOfContents.cjs +1 -1
- package/dist/components/ui/TableOfContents.cjs.map +1 -1
- package/dist/components/ui/TableOfContents.js +31 -89
- package/dist/components/ui/TableOfContents.js.map +1 -1
- package/dist/components/ui/ThoughtCard.cjs +2 -0
- package/dist/components/ui/ThoughtCard.cjs.map +1 -0
- package/dist/components/ui/ThoughtCard.d.ts +23 -0
- package/dist/components/ui/ThoughtCard.js +55 -0
- package/dist/components/ui/ThoughtCard.js.map +1 -0
- package/dist/components/ui/index.d.ts +20 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useSectionSpy.cjs +2 -0
- package/dist/hooks/useSectionSpy.cjs.map +1 -0
- package/dist/hooks/useSectionSpy.d.ts +23 -0
- package/dist/hooks/useSectionSpy.js +78 -0
- package/dist/hooks/useSectionSpy.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +337 -310
- package/dist/index.js.map +1 -1
- package/dist/layouts/site/SiteAnchorNav.cjs +2 -0
- package/dist/layouts/site/SiteAnchorNav.cjs.map +1 -0
- package/dist/layouts/site/SiteAnchorNav.d.ts +22 -0
- package/dist/layouts/site/SiteAnchorNav.js +51 -0
- package/dist/layouts/site/SiteAnchorNav.js.map +1 -0
- package/dist/layouts/site/SiteSectionHeader.cjs +2 -0
- package/dist/layouts/site/SiteSectionHeader.cjs.map +1 -0
- package/dist/layouts/site/SiteSectionHeader.d.ts +20 -0
- package/dist/layouts/site/SiteSectionHeader.js +30 -0
- package/dist/layouts/site/SiteSectionHeader.js.map +1 -0
- package/dist/layouts/site/index.d.ts +4 -0
- package/dist/lib/chart.cjs +1 -1
- package/dist/lib/chart.cjs.map +1 -1
- package/dist/lib/chart.d.ts +8 -2
- package/dist/lib/chart.js +20 -16
- package/dist/lib/chart.js.map +1 -1
- package/dist/locale/strings.cjs +1 -1
- package/dist/locale/strings.cjs.map +1 -1
- package/dist/locale/strings.d.ts +2 -0
- package/dist/locale/strings.js +2 -0
- package/dist/locale/strings.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParetoChart.js","sources":["../../../src/components/ui/ParetoChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useMemo,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport { ChartLegend } from './ChartLegend';\nimport { EmptyState } from './EmptyState';\nimport './ParetoChart.css';\n\nexport interface ParetoPoint {\n key: string;\n label: string;\n x: number;\n y: number;\n /** Point fill, e.g. `cat-2` or a series token, to match the series elsewhere. */\n color?: ChartColor;\n}\n\n/** One series in the legend under the plot, e.g. a model and its colour. */\nexport interface ParetoLegendItem {\n key: string;\n label: ReactNode;\n /** Swatch fill; the same value its points use. */\n color?: ChartColor;\n}\n\ninterface ParetoChartProps {\n points: ParetoPoint[];\n xLabel: string;\n yLabel: string;\n /** Which direction counts as better on each axis. */\n xDirection?: 'lower' | 'higher';\n yDirection?: 'lower' | 'higher';\n /** Formats the 0 and maximum labels of each axis. */\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n onSelect?: (key: string) => void;\n /** Series swatches with labels, listed under the plot. */\n legend?: ParetoLegendItem[];\n /**\n * Shown in place of the plot, at its minimum height, while there are no\n * points — e.g. an EmptyState with an icon asking for both axes. Replaces\n * the default empty state built from `emptyTitle`.\n */\n empty?: ReactNode;\n emptyTitle?: string;\n emptyDescription?: string;\n /**\n * How far the chart is drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`): points fade in from left to\n * right, then the frontier. Omitted, they fade in once on mount.\n */\n progress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst MAX_HEIGHT = 320;\nconst MIN_HEIGHT = 220;\nconst PAD_LEFT = 56;\nconst PAD_RIGHT = 16;\nconst PAD_TOP = 28;\nconst PAD_BOTTOM = 44;\nconst POINT_RADIUS = 5;\nconst LABEL_GAP = 8;\nconst GRID_STEPS = 4;\n\ntype Direction = 'lower' | 'higher';\n\nfunction better(a: number, b: number, direction: Direction): boolean {\n return direction === 'lower' ? a < b : a > b;\n}\n\nexport function ParetoChart({\n points,\n xLabel,\n yLabel,\n xDirection = 'lower',\n yDirection = 'higher',\n formatX = String,\n formatY = String,\n onSelect,\n legend,\n empty,\n emptyTitle,\n emptyDescription,\n progress,\n className,\n}: ParetoChartProps) {\n const strings = useStrings();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const cls = [\n 'aegis-pareto',\n progress === undefined ? '' : 'aegis-pareto--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const geometry = useMemo(() => {\n if (points.length === 0 || width === 0) {\n return null;\n }\n const height = Math.round(\n Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, width / 2)),\n );\n const [xLo, xHi] = zeroAnchoredDomain(points.map((point) => point.x));\n const [yLo, yHi] = zeroAnchoredDomain(points.map((point) => point.y));\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = height - PAD_BOTTOM;\n const sx = (value: number): number =>\n left + ((value - xLo) / (xHi - xLo)) * (right - left);\n const sy = (value: number): number =>\n bottom - ((value - yLo) / (yHi - yLo)) * (bottom - top);\n const front = points\n .filter(\n (candidate) =>\n !points.some(\n (other) =>\n other.key !== candidate.key &&\n (better(other.x, candidate.x, xDirection) ||\n other.x === candidate.x) &&\n (better(other.y, candidate.y, yDirection) ||\n other.y === candidate.y) &&\n (better(other.x, candidate.x, xDirection) ||\n better(other.y, candidate.y, yDirection)),\n ),\n )\n .sort((a, b) => a.x - b.x);\n const steps = Array.from(\n { length: GRID_STEPS },\n (_, i) => (i + 1) / GRID_STEPS,\n );\n // Points draw in from left to right; the frontier comes last.\n const order = new Map(\n [...points]\n .sort((a, b) => sx(a.x) - sx(b.x))\n .map((point, rank) => [point.key, rank]),\n );\n return {\n height,\n order,\n left,\n right,\n top,\n bottom,\n sx,\n sy,\n front,\n frontKeys: new Set(front.map((point) => point.key)),\n gridX: steps.map((t) => sx(xLo + (xHi - xLo) * t)),\n gridY: steps.map((t) => sy(yLo + (yHi - yLo) * t)),\n xLo,\n xHi,\n yLo,\n yHi,\n };\n }, [points, width, xDirection, yDirection]);\n\n if (points.length === 0) {\n return (\n <div ref={wrapRef} className={cls}>\n {empty === undefined ? (\n <EmptyState\n title={emptyTitle ?? strings.paretoEmptyTitle}\n description={emptyDescription}\n />\n ) : (\n <div\n className=\"aegis-pareto__empty\"\n style={\n {\n '--aegis-pareto-min-height': `${MIN_HEIGHT.toString()}px`,\n } as CSSProperties\n }\n >\n {empty}\n </div>\n )}\n </div>\n );\n }\n\n if (!geometry) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const { height, left, right, top, bottom, sx, sy, front, frontKeys } =\n geometry;\n const selectOnKey = (event: KeyboardEvent<SVGCircleElement>, key: string) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onSelect?.(key);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-pareto__svg\"\n width={width}\n height={height}\n viewBox={`0 0 ${width.toString()} ${height.toString()}`}\n role={onSelect ? 'group' : 'img'}\n aria-label={strings.paretoChartLabel(xLabel, yLabel)}\n style={\n {\n '--aegis-pareto-count': points.length,\n ...(progress === undefined\n ? {}\n : {\n '--aegis-pareto-front-progress': staggeredProgress(\n progress,\n points.length,\n points.length + 1,\n ),\n }),\n } as CSSProperties\n }\n >\n {geometry.gridY.map((y) => (\n <line\n key={`gy-${y.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={left}\n y1={y}\n x2={right}\n y2={y}\n />\n ))}\n {geometry.gridX.map((x) => (\n <line\n key={`gx-${x.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={x}\n y1={top}\n x2={x}\n y2={bottom}\n />\n ))}\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={bottom}\n x2={right}\n y2={bottom}\n />\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={top}\n x2={left}\n y2={bottom}\n />\n {front.length > 1 && (\n <polyline\n className=\"aegis-pareto__front\"\n points={front\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n />\n )}\n {points.map((point, index) => (\n <circle\n key={point.key}\n className={[\n 'aegis-pareto__point',\n frontKeys.has(point.key) ? '' : 'aegis-pareto__point--dominated',\n onSelect ? 'aegis-pareto__point--interactive' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n fill:\n point.color === undefined\n ? undefined\n : chartColorValue(point.color),\n '--aegis-pareto-index': index,\n ...(progress === undefined\n ? {}\n : {\n '--aegis-pareto-point-progress': staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? index,\n points.length + 1,\n ),\n }),\n } as CSSProperties\n }\n cx={sx(point.x)}\n cy={sy(point.y)}\n r={POINT_RADIUS}\n role={onSelect ? 'button' : undefined}\n tabIndex={onSelect ? 0 : undefined}\n aria-label={onSelect ? point.label : undefined}\n onClick={\n onSelect\n ? () => {\n onSelect(point.key);\n }\n : undefined\n }\n onKeyDown={\n onSelect\n ? (event) => {\n selectOnKey(event, point.key);\n }\n : undefined\n }\n >\n <title>{point.label}</title>\n </circle>\n ))}\n {front.map((point) => {\n const x = sx(point.x);\n const y = sy(point.y);\n const flip = x > left + (right - left) * 0.7;\n return (\n <text\n key={`label-${point.key}`}\n className=\"aegis-pareto__point-label\"\n x={flip ? x - LABEL_GAP : x + LABEL_GAP}\n y={y < top + LABEL_GAP * 2 ? y + LABEL_GAP * 2 : y - LABEL_GAP}\n textAnchor={flip ? 'end' : 'start'}\n >\n {point.label}\n </text>\n );\n })}\n <text\n className=\"aegis-pareto__tick\"\n x={left}\n y={bottom + LABEL_GAP * 2}\n textAnchor=\"middle\"\n >\n {formatX(geometry.xLo)}\n </text>\n <text\n className=\"aegis-pareto__tick\"\n x={right}\n y={bottom + LABEL_GAP * 2}\n textAnchor=\"end\"\n >\n {formatX(geometry.xHi)}\n </text>\n <text\n className=\"aegis-pareto__tick\"\n x={left - LABEL_GAP}\n y={bottom}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(geometry.yLo)}\n </text>\n <text\n className=\"aegis-pareto__tick\"\n x={left - LABEL_GAP}\n y={top}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(geometry.yHi)}\n </text>\n <text\n className=\"aegis-pareto__axis-label\"\n x={right}\n y={height - LABEL_GAP}\n textAnchor=\"end\"\n >\n {xLabel}\n </text>\n <text\n className=\"aegis-pareto__axis-label\"\n x={left - LABEL_GAP}\n y={top - LABEL_GAP * 2}\n textAnchor=\"start\"\n >\n {yLabel}\n </text>\n </svg>\n {legend !== undefined && legend.length > 0 ? (\n <ChartLegend\n className=\"aegis-pareto__legend\"\n shape=\"dot\"\n items={legend.map((item) => ({\n key: item.key,\n label: item.label,\n color: item.color ?? 'var(--bg-inverted)',\n }))}\n />\n ) : null}\n </div>\n );\n}\n"],"names":["MAX_HEIGHT","MIN_HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","POINT_RADIUS","LABEL_GAP","GRID_STEPS","better","b","direction","ParetoChart","points","xLabel","yLabel","xDirection","yDirection","formatX","formatY","onSelect","legend","empty","emptyTitle","emptyDescription","progress","className","strings","useStrings","wrapRef","useRef","width","useElementWidth","cls","geometry","useMemo","height","xLo","xHi","zeroAnchoredDomain","point","yLo","yHi","left","right","top","bottom","sx","value","sy","front","candidate","other","a","steps","_","i","order","rank","jsx","EmptyState","frontKeys","selectOnKey","event","key","jsxs","staggeredProgress","y","x","index","chartColorValue","flip","ChartLegend","item"],"mappings":";;;;;;;;AAoEA,MAAMA,KAAa,KACbC,IAAa,KACbC,KAAW,IACXC,KAAY,IACZC,KAAU,IACVC,KAAa,IACbC,KAAe,GACfC,IAAY,GACZC,IAAa;AAInB,SAASC,EAAO,GAAWC,GAAWC,GAA+B;AACnE,SAAOA,MAAc,UAAU,IAAID,IAAI,IAAIA;AAC7C;AAEO,SAASE,GAAY;AAAA,EAC1B,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,YAAAC,IAAa;AAAA,EACb,SAAAC,IAAU;AAAA,EACV,SAAAC,IAAU;AAAA,EACV,UAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AACF,GAAqB;AACnB,QAAMC,IAAUC,GAAA,GACVC,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,GAAgBH,CAAO,GAC/BI,IAAM;AAAA,IACV;AAAA,IACAR,MAAa,SAAY,KAAK;AAAA,IAC9BC,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,GAELQ,IAAWC,GAAQ,MAAM;AAC7B,QAAItB,EAAO,WAAW,KAAKkB,MAAU;AACnC,aAAO;AAET,UAAMK,IAAS,KAAK;AAAA,MAClB,KAAK,IAAIpC,IAAY,KAAK,IAAIC,GAAY8B,IAAQ,CAAC,CAAC;AAAA,IAAA,GAEhD,CAACM,GAAKC,CAAG,IAAIC,EAAmB1B,EAAO,IAAI,CAAC2B,MAAUA,EAAM,CAAC,CAAC,GAC9D,CAACC,GAAKC,CAAG,IAAIH,EAAmB1B,EAAO,IAAI,CAAC2B,MAAUA,EAAM,CAAC,CAAC,GAC9DG,IAAOzC,IACP0C,IAAQb,IAAQ5B,IAChB0C,IAAMzC,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AAA1B,EAAQe,EAAS,GAAG;AAAA,YAAA;AAAA,UAAA;AAAA,UAEvB,gBAAAyB;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,GAAGf;AAAA,cACH,GAAGR,IAAS7B;AAAA,cACZ,YAAW;AAAA,cAEV,UAAAO;AAAA,YAAA;AAAA,UAAA;AAAA,UAEH,gBAAA6C;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,GAAGhB,IAAOpC;AAAA,cACV,GAAGsC,IAAMtC,IAAY;AAAA,cACrB,YAAW;AAAA,cAEV,UAAAQ;AAAA,YAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAAA;AAAA,IAEDM,MAAW,UAAaA,EAAO,SAAS,IACvC,gBAAAsC;AAAA,MAACa;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,OAAM;AAAA,QACN,OAAOnD,EAAO,IAAI,CAACoD,OAAU;AAAA,UAC3B,KAAKA,EAAK;AAAA,UACV,OAAOA,EAAK;AAAA,UACZ,OAAOA,EAAK,SAAS;AAAA,QAAA,EACrB;AAAA,MAAA;AAAA,IAAA,IAEF;AAAA,EAAA,GACN;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"ParetoChart.js","sources":["../../../src/components/ui/ParetoChart.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n} from 'react';\n\nimport { useElementWidth } from '../../hooks/useElementWidth';\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport { ChartLegend } from './ChartLegend';\nimport { EmptyState } from './EmptyState';\nimport './ParetoChart.css';\n\nexport interface ParetoPoint {\n key: string;\n label: string;\n x: number;\n y: number;\n /** Point fill, e.g. `cat-2` or a series token, to match the series elsewhere. */\n color?: ChartColor;\n}\n\n/** One series in the legend under the plot, e.g. a model and its colour. */\nexport interface ParetoLegendItem {\n key: string;\n label: ReactNode;\n /** Swatch fill; the same value its points use. */\n color?: ChartColor;\n}\n\ninterface ParetoChartProps {\n points: ParetoPoint[];\n xLabel: string;\n yLabel: string;\n /** Which direction counts as better on each axis. */\n xDirection?: 'lower' | 'higher';\n yDirection?: 'lower' | 'higher';\n /** Formats the labels of each axis. */\n formatX?: (value: number) => string;\n formatY?: (value: number) => string;\n /**\n * `log` spaces the horizontal axis by ratio, e.g. for a cost that spans\n * orders of magnitude; its values must be above 0. Defaults to `linear`.\n */\n xScale?: 'linear' | 'log';\n /** The ends of each axis. Defaults to from 0, or the data's own range on a log axis. */\n xDomain?: [number, number];\n yDomain?: [number, number];\n /**\n * The labelled gridlines of each axis. Defaults to plain gridlines with\n * labels at the two ends.\n */\n xTicks?: number[];\n yTicks?: number[];\n /**\n * Which points carry their name. `front` names the frontier; `all` names\n * every point, so the chart needs no legend. A plot too narrow for them\n * names the frontier and `highlightKeys` and lists every point under it.\n * Defaults to `front`.\n */\n labels?: 'front' | 'all';\n /** Fades the points off the frontier. Defaults to true. */\n fadeDominated?: boolean;\n /** Fades every other point, to pick out the ones a finding is about. */\n highlightKeys?: string[];\n /** The tallest the plot grows. */\n maxHeight?: number;\n onSelect?: (key: string) => void;\n /** Series swatches with labels, listed under the plot. */\n legend?: ParetoLegendItem[];\n /**\n * Shown in place of the plot, at its minimum height, while there are no\n * points — e.g. an EmptyState with an icon asking for both axes. Replaces\n * the default empty state built from `emptyTitle`.\n */\n empty?: ReactNode;\n emptyTitle?: string;\n emptyDescription?: string;\n /**\n * How far the chart is drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`): points fade in from left to\n * right, then the frontier. Omitted, they fade in once on mount.\n */\n progress?: number;\n /**\n * How far the frontier is traced, 0 to 1, for a host that draws it apart\n * from the points, such as one step of a scrolling story.\n */\n frontProgress?: number;\n className?: string;\n}\n\n// The SVG is drawn at its measured CSS width, so these are true px.\nconst MAX_HEIGHT = 320;\nconst MIN_HEIGHT = 220;\nconst PAD_LEFT = 56;\nconst PAD_RIGHT = 16;\nconst PAD_TOP = 28;\nconst PAD_BOTTOM = 44;\nconst POINT_RADIUS = 5;\nconst LABEL_GAP = 8;\nconst GRID_STEPS = 4;\n// Estimates for placing labels: --fs-11 text, and the width below which\n// `labels='all'` would crowd the plot.\nconst LABEL_CHAR = 6.2;\nconst LABEL_WIDE_CHAR = 11;\nconst LABEL_LINE = 14;\nconst ALL_LABELS_MIN_WIDTH = 520;\n\ntype Direction = 'lower' | 'higher';\n\nfunction better(a: number, b: number, direction: Direction): boolean {\n return direction === 'lower' ? a < b : a > b;\n}\n\ninterface LabelBox {\n x: number;\n y: number;\n anchor: 'start' | 'end';\n}\n\nfunction labelWidth(text: string): number {\n return [...text].reduce(\n (sum, char) =>\n sum + ((char.codePointAt(0) ?? 0) > 255 ? LABEL_WIDE_CHAR : LABEL_CHAR),\n 0,\n );\n}\n\n/**\n * Puts each label beside its point on the first side where it stays on the\n * plot and clear of the labels already placed and of the other points.\n */\nfunction placeLabels(\n labelled: Array<{ key: string; label: string; x: number; y: number }>,\n allPoints: Array<{ key: string; x: number; y: number }>,\n bounds: { left: number; right: number; top: number; bottom: number },\n): Map<string, LabelBox> {\n const placed: Array<{ l: number; r: number; t: number; b: number }> = [];\n const result = new Map<string, LabelBox>();\n const reach = POINT_RADIUS + LABEL_GAP / 2;\n for (const point of labelled) {\n const w = labelWidth(point.label);\n const candidates: LabelBox[] = [\n { x: point.x + reach, y: point.y + LABEL_LINE / 3, anchor: 'start' },\n { x: point.x - reach, y: point.y + LABEL_LINE / 3, anchor: 'end' },\n { x: point.x - w / 2, y: point.y - reach, anchor: 'start' },\n { x: point.x - w / 2, y: point.y + reach + LABEL_LINE, anchor: 'start' },\n ];\n const box = (candidate: LabelBox) => {\n const l = candidate.anchor === 'end' ? candidate.x - w : candidate.x;\n return {\n l,\n r: l + w,\n t: candidate.y - LABEL_LINE,\n b: candidate.y,\n };\n };\n const onPlot = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n l >= bounds.left &&\n r <= bounds.right &&\n t >= bounds.top &&\n b <= bounds.bottom\n );\n };\n const clear = (candidate: LabelBox): boolean => {\n const { l, r, t, b } = box(candidate);\n return (\n onPlot(candidate) &&\n placed.every(\n (other) => r < other.l || l > other.r || b < other.t || t > other.b,\n ) &&\n allPoints.every(\n (other) =>\n other.key === point.key ||\n other.x + POINT_RADIUS < l ||\n other.x - POINT_RADIUS > r ||\n other.y + POINT_RADIUS < t ||\n other.y - POINT_RADIUS > b,\n )\n );\n };\n // With no side free the label still stays on the plot, towards its middle.\n const chosen =\n candidates.find(clear) ??\n candidates.find(onPlot) ??\n candidates[point.x > (bounds.left + bounds.right) / 2 ? 1 : 0];\n placed.push(box(chosen));\n result.set(point.key, chosen);\n }\n return result;\n}\n\nexport function ParetoChart({\n points,\n xLabel,\n yLabel,\n xDirection = 'lower',\n yDirection = 'higher',\n formatX = String,\n formatY = String,\n xScale = 'linear',\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n labels = 'front',\n fadeDominated = true,\n highlightKeys,\n maxHeight = MAX_HEIGHT,\n onSelect,\n legend,\n empty,\n emptyTitle,\n emptyDescription,\n progress,\n frontProgress,\n className,\n}: ParetoChartProps) {\n const strings = useStrings();\n const clipId = useId();\n const wrapRef = useRef<HTMLDivElement>(null);\n const width = useElementWidth(wrapRef);\n const cls = [\n 'aegis-pareto',\n progress === undefined && frontProgress === undefined\n ? ''\n : 'aegis-pareto--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const geometry = useMemo(() => {\n if (points.length === 0 || width === 0) {\n return null;\n }\n const height = Math.round(\n Math.min(maxHeight, Math.max(MIN_HEIGHT, width / 2)),\n );\n const xValues = points.map((point) => point.x);\n const logLo = Math.min(...xValues);\n const logHi = Math.max(...xValues);\n const [xLo, xHi] =\n xDomain ??\n (xScale === 'log'\n ? // One value has no span to divide, so it sits mid-axis.\n ([\n logHi > logLo ? logLo : logLo / 2,\n logHi > logLo ? logHi : logHi * 2,\n ] as const)\n : zeroAnchoredDomain(xValues));\n const [yLo, yHi] =\n yDomain ?? zeroAnchoredDomain(points.map((point) => point.y));\n const scaleX = xScale === 'log' ? Math.log10 : (value: number) => value;\n const left = PAD_LEFT;\n const right = width - PAD_RIGHT;\n const top = PAD_TOP;\n const bottom = height - PAD_BOTTOM;\n const sx = (value: number): number =>\n left +\n ((scaleX(value) - scaleX(xLo)) / (scaleX(xHi) - scaleX(xLo))) *\n (right - left);\n const sy = (value: number): number =>\n bottom - ((value - yLo) / (yHi - yLo)) * (bottom - top);\n const front = points\n .filter(\n (candidate) =>\n !points.some(\n (other) =>\n other.key !== candidate.key &&\n (better(other.x, candidate.x, xDirection) ||\n other.x === candidate.x) &&\n (better(other.y, candidate.y, yDirection) ||\n other.y === candidate.y) &&\n (better(other.x, candidate.x, xDirection) ||\n better(other.y, candidate.y, yDirection)),\n ),\n )\n .sort((a, b) => a.x - b.x);\n const steps = Array.from(\n { length: GRID_STEPS },\n (_, i) => (i + 1) / GRID_STEPS,\n );\n // Points draw in from left to right; the frontier comes last.\n const order = new Map(\n [...points]\n .sort((a, b) => sx(a.x) - sx(b.x))\n .map((point, rank) => [point.key, rank]),\n );\n return {\n height,\n order,\n left,\n right,\n top,\n bottom,\n sx,\n sy,\n front,\n frontKeys: new Set(front.map((point) => point.key)),\n // Even shares of the plot, which on a log axis are even ratios.\n gridX: xTicks?.map(sx) ?? steps.map((t) => left + (right - left) * t),\n gridY: yTicks?.map(sy) ?? steps.map((t) => sy(yLo + (yHi - yLo) * t)),\n xLabels: xTicks ?? [xLo, xHi],\n yLabels: yTicks ?? [yLo, yHi],\n };\n }, [\n points,\n width,\n xDirection,\n yDirection,\n xScale,\n xDomain,\n yDomain,\n xTicks,\n yTicks,\n maxHeight,\n ]);\n\n if (points.length === 0) {\n return (\n <div ref={wrapRef} className={cls}>\n {empty === undefined ? (\n <EmptyState\n title={emptyTitle ?? strings.paretoEmptyTitle}\n description={emptyDescription}\n />\n ) : (\n <div\n className=\"aegis-pareto__empty\"\n style={\n {\n '--aegis-pareto-min-height': `${MIN_HEIGHT.toString()}px`,\n } as CSSProperties\n }\n >\n {empty}\n </div>\n )}\n </div>\n );\n }\n\n if (!geometry) {\n return <div ref={wrapRef} className={cls} />;\n }\n\n const { height, left, right, top, bottom, sx, sy, front, frontKeys } =\n geometry;\n const highlighted =\n highlightKeys === undefined ? null : new Set(highlightKeys);\n const dimmed = (key: string): boolean =>\n highlighted !== null && !highlighted.has(key);\n const showAllLabels = labels === 'all' && width >= ALL_LABELS_MIN_WIDTH;\n const labelBoxes = placeLabels(\n points\n .filter(\n (point) =>\n showAllLabels ||\n frontKeys.has(point.key) ||\n (highlighted?.has(point.key) ?? false),\n )\n .map((point) => ({\n key: point.key,\n label: point.label,\n x: sx(point.x),\n y: sy(point.y),\n })),\n points.map((point) => ({\n key: point.key,\n x: sx(point.x),\n y: sy(point.y),\n })),\n // A label may run up into the space above the plot.\n { left, right, top: 0, bottom },\n );\n // A plot too narrow to name every point names them under it instead, so\n // none is left to a tooltip a phone cannot show.\n const legendItems =\n legend?.map((item) => ({\n key: item.key,\n label: item.label,\n color: item.color ?? ('var(--bg-inverted)' as const),\n })) ??\n (labels === 'all' && !showAllLabels\n ? points.map((point) => ({\n key: point.key,\n label: point.label,\n color: point.color ?? ('var(--bg-inverted)' as const),\n }))\n : []);\n const frontDrawn =\n frontProgress ??\n (progress === undefined\n ? undefined\n : staggeredProgress(progress, points.length, points.length + 1));\n const selectOnKey = (event: KeyboardEvent<SVGCircleElement>, key: string) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onSelect?.(key);\n }\n };\n\n return (\n <div ref={wrapRef} className={cls}>\n <svg\n className=\"aegis-pareto__svg\"\n width={width}\n height={height}\n viewBox={`0 0 ${width.toString()} ${height.toString()}`}\n role={onSelect ? 'group' : 'img'}\n aria-label={strings.paretoChartLabel(xLabel, yLabel)}\n style={\n {\n '--aegis-pareto-count': points.length,\n ...(frontDrawn === undefined\n ? {}\n : { '--aegis-pareto-front-progress': frontDrawn }),\n } as CSSProperties\n }\n >\n {geometry.gridY.map((y) => (\n <line\n key={`gy-${y.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={left}\n y1={y}\n x2={right}\n y2={y}\n />\n ))}\n {geometry.gridX.map((x) => (\n <line\n key={`gx-${x.toString()}`}\n className=\"aegis-pareto__grid\"\n x1={x}\n y1={top}\n x2={x}\n y2={bottom}\n />\n ))}\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={bottom}\n x2={right}\n y2={bottom}\n />\n <line\n className=\"aegis-pareto__axis\"\n x1={left}\n y1={top}\n x2={left}\n y2={bottom}\n />\n {frontDrawn !== undefined && (\n <clipPath id={clipId}>\n <rect\n x={left}\n y={0}\n width={(right - left) * frontDrawn}\n height={height}\n />\n </clipPath>\n )}\n {front.length > 1 && (\n <polyline\n className=\"aegis-pareto__front\"\n clipPath={frontDrawn === undefined ? undefined : `url(#${clipId})`}\n points={front\n .map(\n (point) =>\n `${sx(point.x).toString()},${sy(point.y).toString()}`,\n )\n .join(' ')}\n />\n )}\n {points.map((point, index) => (\n <circle\n key={point.key}\n className={[\n 'aegis-pareto__point',\n fadeDominated && !frontKeys.has(point.key)\n ? 'aegis-pareto__point--dominated'\n : '',\n dimmed(point.key) ? 'aegis-pareto__point--dimmed' : '',\n onSelect ? 'aegis-pareto__point--interactive' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n fill:\n point.color === undefined\n ? undefined\n : chartColorValue(point.color),\n '--aegis-pareto-index': index,\n '--aegis-pareto-point-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? index,\n points.length + 1,\n ),\n } as CSSProperties\n }\n cx={sx(point.x)}\n cy={sy(point.y)}\n r={POINT_RADIUS}\n role={onSelect ? 'button' : undefined}\n tabIndex={onSelect ? 0 : undefined}\n aria-label={onSelect ? point.label : undefined}\n onClick={\n onSelect\n ? () => {\n onSelect(point.key);\n }\n : undefined\n }\n onKeyDown={\n onSelect\n ? (event) => {\n selectOnKey(event, point.key);\n }\n : undefined\n }\n >\n <title>{point.label}</title>\n </circle>\n ))}\n {points.map((point) => {\n const box = labelBoxes.get(point.key);\n return box === undefined ? null : (\n <text\n key={`label-${point.key}`}\n className={[\n 'aegis-pareto__point-label',\n dimmed(point.key) ? 'aegis-pareto__point-label--dimmed' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n labels === 'all'\n ? ({\n '--aegis-pareto-front-progress':\n progress === undefined\n ? 1\n : staggeredProgress(\n progress,\n geometry.order.get(point.key) ?? 0,\n points.length + 1,\n ),\n } as CSSProperties)\n : undefined\n }\n x={box.x}\n y={box.y}\n textAnchor={box.anchor}\n >\n {point.label}\n </text>\n );\n })}\n {geometry.xLabels.map((value, index) => (\n <text\n key={`x-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={sx(value)}\n y={bottom + LABEL_GAP * 2}\n textAnchor={\n index === geometry.xLabels.length - 1 && sx(value) >= right - 1\n ? 'end'\n : 'middle'\n }\n >\n {formatX(value)}\n </text>\n ))}\n {geometry.yLabels.map((value) => (\n <text\n key={`y-${value.toString()}`}\n className=\"aegis-pareto__tick\"\n x={left - LABEL_GAP}\n y={sy(value)}\n textAnchor=\"end\"\n dominantBaseline=\"middle\"\n >\n {formatY(value)}\n </text>\n ))}\n <text\n className=\"aegis-pareto__axis-label\"\n x={right}\n y={height - LABEL_GAP}\n textAnchor=\"end\"\n >\n {xLabel}\n </text>\n <text\n className=\"aegis-pareto__axis-label\"\n x={left - LABEL_GAP}\n y={top - LABEL_GAP * 2}\n textAnchor=\"start\"\n >\n {yLabel}\n </text>\n </svg>\n {legendItems.length > 0 ? (\n <ChartLegend\n className=\"aegis-pareto__legend\"\n shape=\"dot\"\n items={legendItems}\n />\n ) : null}\n </div>\n );\n}\n"],"names":["MAX_HEIGHT","MIN_HEIGHT","PAD_LEFT","PAD_RIGHT","PAD_TOP","PAD_BOTTOM","POINT_RADIUS","LABEL_GAP","GRID_STEPS","LABEL_CHAR","LABEL_WIDE_CHAR","LABEL_LINE","ALL_LABELS_MIN_WIDTH","better","a","b","direction","labelWidth","text","sum","char","placeLabels","labelled","allPoints","bounds","placed","result","reach","point","w","candidates","box","candidate","l","onPlot","r","t","clear","other","chosen","ParetoChart","points","xLabel","yLabel","xDirection","yDirection","formatX","formatY","xScale","xDomain","yDomain","xTicks","yTicks","labels","fadeDominated","highlightKeys","maxHeight","onSelect","legend","empty","emptyTitle","emptyDescription","progress","frontProgress","className","strings","useStrings","clipId","useId","wrapRef","useRef","width","useElementWidth","cls","geometry","useMemo","height","xValues","logLo","logHi","xLo","xHi","zeroAnchoredDomain","yLo","yHi","scaleX","value","left","right","top","bottom","sx","sy","front","steps","_","i","order","rank","jsx","EmptyState","frontKeys","highlighted","dimmed","key","showAllLabels","labelBoxes","legendItems","item","frontDrawn","staggeredProgress","selectOnKey","event","jsxs","y","x","index","chartColorValue","ChartLegend"],"mappings":";;;;;;;;AAqGA,MAAMA,KAAa,KACbC,KAAa,KACbC,KAAW,IACXC,KAAY,IACZC,KAAU,IACVC,KAAa,IACbC,IAAe,GACfC,IAAY,GACZC,KAAa,GAGbC,KAAa,KACbC,KAAkB,IAClBC,IAAa,IACbC,KAAuB;AAI7B,SAASC,EAAOC,GAAWC,GAAWC,GAA+B;AACnE,SAAOA,MAAc,UAAUF,IAAIC,IAAID,IAAIC;AAC7C;AAQA,SAASE,GAAWC,GAAsB;AACxC,SAAO,CAAC,GAAGA,CAAI,EAAE;AAAA,IACf,CAACC,GAAKC,MACJD,MAAQC,EAAK,YAAY,CAAC,KAAK,KAAK,MAAMV,KAAkBD;AAAA,IAC9D;AAAA,EAAA;AAEJ;AAMA,SAASY,GACPC,GACAC,GACAC,GACuB;AACvB,QAAMC,IAAgE,CAAA,GAChEC,wBAAa,IAAA,GACbC,IAAQrB,IAAeC,IAAY;AAC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AA,YAAC;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,GAAGZ,IAAOhF;AAAA,cACV,GAAGkF,IAAMlF,IAAY;AAAA,cACrB,YAAW;AAAA,cAEV,UAAAoC;AAAA,YAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAAA;AAAA,IAEDgE,GAAY,SAAS,IACpB,gBAAAR;AAAA,MAACmB;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,OAAM;AAAA,QACN,OAAOX;AAAA,MAAA;AAAA,IAAA,IAEP;AAAA,EAAA,GACN;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),l=require("../../lib/chart.cjs");;/* empty css */const m=require("../../locale/useStrings.cjs");function $({items:k,max:h,direction:d,format:n=t=>t.toFixed(2),size:j="md",onSelect:i,progress:c,className:x}){const t=m.useStrings(),p=k.flatMap(s=>[...s.value===null?[]:[s.value],...s.interval??[]]),[,o]=l.zeroAnchoredDomain(p,h),N=["aegis-rank-bar",j==="sm"?"aegis-rank-bar--sm":"",c===void 0?"":"aegis-rank-bar--scroll",x??""].filter(Boolean).join(" ");return a.jsxs("div",{className:N,children:[k.map((s,g)=>{const{value:r,interval:e}=s,b=y=>`${(o>0?y/o*100:0).toString()}%`,_=c===void 0?1:l.staggeredProgress(c,g,k.length),u=e&&a.jsx("span",{className:"aegis-rank-bar__interval",style:{left:b(e[0]),width:b(e[1]-e[0]),opacity:`calc(var(--chart-interval-opacity) * ${l.stageProgress(_,.8,1).toString()})`}}),v=r===null?null:a.jsx("div",{className:["aegis-rank-bar__fill",r===0?"aegis-rank-bar__fill--zero":""].filter(Boolean).join(" "),style:{width:b(r),"--aegis-rank-bar-index":g,...s.color===void 0||r===0?{}:{background:l.chartColorValue(s.color)},...c===void 0?{}:{"--aegis-rank-bar-progress":l.stageProgress(_,0,e?.8:1)}},children:a.jsx("span",{className:"aegis-rank-bar__ink"})});return a.jsxs("div",{className:"aegis-rank-bar__row",children:[i?a.jsx("button",{type:"button",className:"aegis-rank-bar__label aegis-rank-bar__label--link",onClick:()=>{i(s.key)},children:s.label}):a.jsx("span",{className:"aegis-rank-bar__label",children:s.label}),i?a.jsxs("button",{type:"button",tabIndex:-1,"aria-hidden":"true",className:"aegis-rank-bar__track aegis-rank-bar__track--link",onClick:()=>{i(s.key)},children:[v,u]}):a.jsxs("div",{className:"aegis-rank-bar__track",role:"img","aria-label":r===null?t.noValue:`${t.barValue(n(r),n(o))}${e?` (${n(e[0])}–${n(e[1])})`:""}`,children:[v,u]}),a.jsx("span",{className:r===null?"aegis-rank-bar__value aegis-rank-bar__value--empty":"aegis-rank-bar__value",children:r===null?"—":n(r)}),a.jsx("span",{className:"aegis-rank-bar__action",children:s.action})]},s.key)}),a.jsxs("div",{className:"aegis-rank-bar__scale",children:[a.jsx("span",{className:"aegis-rank-bar__spacer"}),a.jsxs("div",{className:"aegis-rank-bar__ticks",children:[a.jsx("span",{children:"0"}),d!==void 0&&a.jsx("span",{className:"aegis-rank-bar__direction",children:d}),a.jsx("span",{children:n(o)})]})]})]})}exports.RankBar=$;
|
|
2
2
|
//# sourceMappingURL=RankBar.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RankBar.cjs","sources":["../../../src/components/ui/RankBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './RankBar.css';\n\nexport interface RankBarItem {\n key: string;\n label: ReactNode;\n /**\n * `null` is a missing value: an em dash over an empty track, distinct\n * from a real 0, which keeps a visible endpoint.\n */\n value: number | null;\n /** Trailing slot for a per-row link, e.g. \"逐题表现\". */\n action?: ReactNode;\n /**\n * The bar's colour, e.g. the series colour of the model's vendor.\n * Defaults to `--rank-bar-fill`.\n */\n color?: ChartColor;\n}\n\ninterface RankBarProps {\n items: RankBarItem[];\n /**\n * Upper bound of the scale. Defaults to the largest value, or 1 when all
|
|
1
|
+
{"version":3,"file":"RankBar.cjs","sources":["../../../src/components/ui/RankBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport {\n type ChartColor,\n chartColorValue,\n stageProgress,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './RankBar.css';\n\nexport interface RankBarItem {\n key: string;\n label: ReactNode;\n /**\n * `null` is a missing value: an em dash over an empty track, distinct\n * from a real 0, which keeps a visible endpoint.\n */\n value: number | null;\n /** The value's confidence interval, drawn as a line over the bar. */\n interval?: [number, number];\n /** Trailing slot for a per-row link, e.g. \"逐题表现\". */\n action?: ReactNode;\n /**\n * The bar's colour, e.g. the series colour of the model's vendor.\n * Defaults to `--rank-bar-fill`.\n */\n color?: ChartColor;\n}\n\ninterface RankBarProps {\n items: RankBarItem[];\n /**\n * Upper bound of the scale. Defaults to the largest value or interval\n * end, or 1 when all are 0; pass `1` for a share or a 0–1 score.\n */\n max?: number;\n /** Scale hint rendered at the bottom, e.g. \"越高越好\". */\n direction?: ReactNode;\n format?: (value: number) => string;\n /** `sm` is a thin bar, for rows that lead with their label. Defaults to `md`. */\n size?: 'md' | 'sm';\n /** Makes each row's label and bar track select that row. */\n onSelect?: (key: string) => void;\n /**\n * How far the bars are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, the bars draw in\n * once when they mount.\n */\n progress?: number;\n className?: string;\n}\n\nexport function RankBar({\n items,\n max,\n direction,\n format = (value) => value.toFixed(2),\n size = 'md',\n onSelect,\n progress,\n className,\n}: RankBarProps) {\n const strings = useStrings();\n const values = items.flatMap((item) => [\n ...(item.value === null ? [] : [item.value]),\n ...(item.interval ?? []),\n ]);\n const [, upperBound] = zeroAnchoredDomain(values, max);\n const cls = [\n 'aegis-rank-bar',\n size === 'sm' ? 'aegis-rank-bar--sm' : '',\n progress === undefined ? '' : 'aegis-rank-bar--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <div className={cls}>\n {items.map((item, index) => {\n const { value, interval } = item;\n const share = (part: number): string =>\n `${(upperBound > 0 ? (part / upperBound) * 100 : 0).toString()}%`;\n const drawn =\n progress === undefined\n ? 1\n : staggeredProgress(progress, index, items.length);\n const intervalMark = interval && (\n <span\n className=\"aegis-rank-bar__interval\"\n style={{\n left: share(interval[0]),\n width: share(interval[1] - interval[0]),\n opacity: `calc(var(--chart-interval-opacity) * ${stageProgress(drawn, 0.8, 1).toString()})`,\n }}\n />\n );\n const fill =\n value === null ? null : (\n <div\n className={[\n 'aegis-rank-bar__fill',\n value === 0 ? 'aegis-rank-bar__fill--zero' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n width: share(value),\n '--aegis-rank-bar-index': index,\n ...(item.color === undefined || value === 0\n ? {}\n : { background: chartColorValue(item.color) }),\n ...(progress === undefined\n ? {}\n : {\n '--aegis-rank-bar-progress': stageProgress(\n drawn,\n 0,\n interval ? 0.8 : 1,\n ),\n }),\n } as CSSProperties\n }\n >\n <span className=\"aegis-rank-bar__ink\" />\n </div>\n );\n return (\n <div className=\"aegis-rank-bar__row\" key={item.key}>\n {onSelect ? (\n <button\n type=\"button\"\n className=\"aegis-rank-bar__label aegis-rank-bar__label--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {item.label}\n </button>\n ) : (\n <span className=\"aegis-rank-bar__label\">{item.label}</span>\n )}\n {onSelect ? (\n // The label button is the keyboard and screen-reader target;\n // the track only widens the pointer target.\n <button\n type=\"button\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"aegis-rank-bar__track aegis-rank-bar__track--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {fill}\n {intervalMark}\n </button>\n ) : (\n <div\n className=\"aegis-rank-bar__track\"\n role=\"img\"\n aria-label={\n value === null\n ? strings.noValue\n : `${strings.barValue(format(value), format(upperBound))}${\n interval\n ? ` (${format(interval[0])}–${format(interval[1])})`\n : ''\n }`\n }\n >\n {fill}\n {intervalMark}\n </div>\n )}\n <span\n className={\n value === null\n ? 'aegis-rank-bar__value aegis-rank-bar__value--empty'\n : 'aegis-rank-bar__value'\n }\n >\n {value === null ? '—' : format(value)}\n </span>\n <span className=\"aegis-rank-bar__action\">{item.action}</span>\n </div>\n );\n })}\n <div className=\"aegis-rank-bar__scale\">\n <span className=\"aegis-rank-bar__spacer\" />\n <div className=\"aegis-rank-bar__ticks\">\n <span>0</span>\n {direction !== undefined && (\n <span className=\"aegis-rank-bar__direction\">{direction}</span>\n )}\n <span>{format(upperBound)}</span>\n </div>\n </div>\n </div>\n );\n}\n"],"names":["RankBar","items","max","direction","format","value","size","onSelect","progress","className","strings","useStrings","values","item","upperBound","zeroAnchoredDomain","cls","jsxs","index","interval","share","part","drawn","staggeredProgress","intervalMark","jsx","stageProgress","fill","chartColorValue"],"mappings":"kOAsDO,SAASA,EAAQ,CACtB,MAAAC,EACA,IAAAC,EACA,UAAAC,EACA,OAAAC,EAAUC,GAAUA,EAAM,QAAQ,CAAC,EACnC,KAAAC,EAAO,KACP,SAAAC,EACA,SAAAC,EACA,UAAAC,CACF,EAAiB,CACf,MAAMC,EAAUC,EAAAA,WAAA,EACVC,EAASX,EAAM,QAASY,GAAS,CACrC,GAAIA,EAAK,QAAU,KAAO,CAAA,EAAK,CAACA,EAAK,KAAK,EAC1C,GAAIA,EAAK,UAAY,CAAA,CAAC,CACvB,EACK,CAAA,CAAGC,CAAU,EAAIC,qBAAmBH,EAAQV,CAAG,EAC/Cc,EAAM,CACV,iBACAV,IAAS,KAAO,qBAAuB,GACvCE,IAAa,OAAY,GAAK,yBAC9BC,GAAa,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG,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
|
11
|
+
/** The value's confidence interval, drawn as a line over the bar. */
|
|
12
|
+
interval?: [number, number];
|
|
11
13
|
/** Trailing slot for a per-row link, e.g. "逐题表现". */
|
|
12
14
|
action?: ReactNode;
|
|
13
15
|
/**
|
|
@@ -19,13 +21,15 @@ export interface RankBarItem {
|
|
|
19
21
|
interface RankBarProps {
|
|
20
22
|
items: RankBarItem[];
|
|
21
23
|
/**
|
|
22
|
-
* Upper bound of the scale. Defaults to the largest value
|
|
23
|
-
* are 0; pass `1` for a share or a 0–1 score.
|
|
24
|
+
* Upper bound of the scale. Defaults to the largest value or interval
|
|
25
|
+
* end, or 1 when all are 0; pass `1` for a share or a 0–1 score.
|
|
24
26
|
*/
|
|
25
27
|
max?: number;
|
|
26
28
|
/** Scale hint rendered at the bottom, e.g. "越高越好". */
|
|
27
29
|
direction?: ReactNode;
|
|
28
30
|
format?: (value: number) => string;
|
|
31
|
+
/** `sm` is a thin bar, for rows that lead with their label. Defaults to `md`. */
|
|
32
|
+
size?: 'md' | 'sm';
|
|
29
33
|
/** Makes each row's label and bar track select that row. */
|
|
30
34
|
onSelect?: (key: string) => void;
|
|
31
35
|
/**
|
|
@@ -36,5 +40,5 @@ interface RankBarProps {
|
|
|
36
40
|
progress?: number;
|
|
37
41
|
className?: string;
|
|
38
42
|
}
|
|
39
|
-
export declare function RankBar({ items, max, direction, format, onSelect, progress, className, }: RankBarProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function RankBar({ items, max, direction, format, size, onSelect, progress, className, }: RankBarProps): import("react/jsx-runtime").JSX.Element;
|
|
40
44
|
export {};
|
|
@@ -1,63 +1,76 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { zeroAnchoredDomain as
|
|
1
|
+
import { jsxs as e, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { zeroAnchoredDomain as x, staggeredProgress as j, stageProgress as h, chartColorValue as w } from "../../lib/chart.js";
|
|
3
3
|
/* empty css */
|
|
4
|
-
import { useStrings as
|
|
5
|
-
function
|
|
6
|
-
items:
|
|
7
|
-
max:
|
|
8
|
-
direction:
|
|
9
|
-
format:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import { useStrings as B } from "../../locale/useStrings.js";
|
|
5
|
+
function P({
|
|
6
|
+
items: k,
|
|
7
|
+
max: p,
|
|
8
|
+
direction: b,
|
|
9
|
+
format: s = (o) => o.toFixed(2),
|
|
10
|
+
size: N = "md",
|
|
11
|
+
onSelect: i,
|
|
12
|
+
progress: c,
|
|
13
|
+
className: m
|
|
13
14
|
}) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const o = B(), y = k.flatMap((a) => [
|
|
16
|
+
...a.value === null ? [] : [a.value],
|
|
17
|
+
...a.interval ?? []
|
|
18
|
+
]), [, t] = x(y, p), f = [
|
|
17
19
|
"aegis-rank-bar",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
N === "sm" ? "aegis-rank-bar--sm" : "",
|
|
21
|
+
c === void 0 ? "" : "aegis-rank-bar--scroll",
|
|
22
|
+
m ?? ""
|
|
20
23
|
].filter(Boolean).join(" ");
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
|
|
23
|
-
const { value: l } = a,
|
|
24
|
+
return /* @__PURE__ */ e("div", { className: f, children: [
|
|
25
|
+
k.map((a, d) => {
|
|
26
|
+
const { value: n, interval: l } = a, _ = ($) => `${(t > 0 ? $ / t * 100 : 0).toString()}%`, g = c === void 0 ? 1 : j(c, d, k.length), u = l && /* @__PURE__ */ r(
|
|
27
|
+
"span",
|
|
28
|
+
{
|
|
29
|
+
className: "aegis-rank-bar__interval",
|
|
30
|
+
style: {
|
|
31
|
+
left: _(l[0]),
|
|
32
|
+
width: _(l[1] - l[0]),
|
|
33
|
+
opacity: `calc(var(--chart-interval-opacity) * ${h(g, 0.8, 1).toString()})`
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
), v = n === null ? null : /* @__PURE__ */ r(
|
|
24
37
|
"div",
|
|
25
38
|
{
|
|
26
39
|
className: [
|
|
27
40
|
"aegis-rank-bar__fill",
|
|
28
|
-
|
|
41
|
+
n === 0 ? "aegis-rank-bar__fill--zero" : ""
|
|
29
42
|
].filter(Boolean).join(" "),
|
|
30
43
|
style: {
|
|
31
|
-
width:
|
|
32
|
-
"--aegis-rank-bar-index":
|
|
33
|
-
...a.color === void 0 ||
|
|
34
|
-
...
|
|
35
|
-
"--aegis-rank-bar-progress":
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
width: _(n),
|
|
45
|
+
"--aegis-rank-bar-index": d,
|
|
46
|
+
...a.color === void 0 || n === 0 ? {} : { background: w(a.color) },
|
|
47
|
+
...c === void 0 ? {} : {
|
|
48
|
+
"--aegis-rank-bar-progress": h(
|
|
49
|
+
g,
|
|
50
|
+
0,
|
|
51
|
+
l ? 0.8 : 1
|
|
39
52
|
)
|
|
40
53
|
}
|
|
41
54
|
},
|
|
42
55
|
children: /* @__PURE__ */ r("span", { className: "aegis-rank-bar__ink" })
|
|
43
56
|
}
|
|
44
57
|
);
|
|
45
|
-
return /* @__PURE__ */
|
|
46
|
-
|
|
58
|
+
return /* @__PURE__ */ e("div", { className: "aegis-rank-bar__row", children: [
|
|
59
|
+
i ? /* @__PURE__ */ r(
|
|
47
60
|
"button",
|
|
48
61
|
{
|
|
49
62
|
type: "button",
|
|
50
63
|
className: "aegis-rank-bar__label aegis-rank-bar__label--link",
|
|
51
64
|
onClick: () => {
|
|
52
|
-
|
|
65
|
+
i(a.key);
|
|
53
66
|
},
|
|
54
67
|
children: a.label
|
|
55
68
|
}
|
|
56
69
|
) : /* @__PURE__ */ r("span", { className: "aegis-rank-bar__label", children: a.label }),
|
|
57
|
-
|
|
70
|
+
i ? (
|
|
58
71
|
// The label button is the keyboard and screen-reader target;
|
|
59
72
|
// the track only widens the pointer target.
|
|
60
|
-
/* @__PURE__ */
|
|
73
|
+
/* @__PURE__ */ e(
|
|
61
74
|
"button",
|
|
62
75
|
{
|
|
63
76
|
type: "button",
|
|
@@ -65,41 +78,47 @@ function B({
|
|
|
65
78
|
"aria-hidden": "true",
|
|
66
79
|
className: "aegis-rank-bar__track aegis-rank-bar__track--link",
|
|
67
80
|
onClick: () => {
|
|
68
|
-
|
|
81
|
+
i(a.key);
|
|
69
82
|
},
|
|
70
|
-
children:
|
|
83
|
+
children: [
|
|
84
|
+
v,
|
|
85
|
+
u
|
|
86
|
+
]
|
|
71
87
|
}
|
|
72
88
|
)
|
|
73
|
-
) : /* @__PURE__ */
|
|
89
|
+
) : /* @__PURE__ */ e(
|
|
74
90
|
"div",
|
|
75
91
|
{
|
|
76
92
|
className: "aegis-rank-bar__track",
|
|
77
93
|
role: "img",
|
|
78
|
-
"aria-label":
|
|
79
|
-
children:
|
|
94
|
+
"aria-label": n === null ? o.noValue : `${o.barValue(s(n), s(t))}${l ? ` (${s(l[0])}–${s(l[1])})` : ""}`,
|
|
95
|
+
children: [
|
|
96
|
+
v,
|
|
97
|
+
u
|
|
98
|
+
]
|
|
80
99
|
}
|
|
81
100
|
),
|
|
82
101
|
/* @__PURE__ */ r(
|
|
83
102
|
"span",
|
|
84
103
|
{
|
|
85
|
-
className:
|
|
86
|
-
children:
|
|
104
|
+
className: n === null ? "aegis-rank-bar__value aegis-rank-bar__value--empty" : "aegis-rank-bar__value",
|
|
105
|
+
children: n === null ? "—" : s(n)
|
|
87
106
|
}
|
|
88
107
|
),
|
|
89
108
|
/* @__PURE__ */ r("span", { className: "aegis-rank-bar__action", children: a.action })
|
|
90
109
|
] }, a.key);
|
|
91
110
|
}),
|
|
92
|
-
/* @__PURE__ */
|
|
111
|
+
/* @__PURE__ */ e("div", { className: "aegis-rank-bar__scale", children: [
|
|
93
112
|
/* @__PURE__ */ r("span", { className: "aegis-rank-bar__spacer" }),
|
|
94
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ e("div", { className: "aegis-rank-bar__ticks", children: [
|
|
95
114
|
/* @__PURE__ */ r("span", { children: "0" }),
|
|
96
|
-
|
|
97
|
-
/* @__PURE__ */ r("span", { children:
|
|
115
|
+
b !== void 0 && /* @__PURE__ */ r("span", { className: "aegis-rank-bar__direction", children: b }),
|
|
116
|
+
/* @__PURE__ */ r("span", { children: s(t) })
|
|
98
117
|
] })
|
|
99
118
|
] })
|
|
100
119
|
] });
|
|
101
120
|
}
|
|
102
121
|
export {
|
|
103
|
-
|
|
122
|
+
P as RankBar
|
|
104
123
|
};
|
|
105
124
|
//# sourceMappingURL=RankBar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RankBar.js","sources":["../../../src/components/ui/RankBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport {\n type ChartColor,\n chartColorValue,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './RankBar.css';\n\nexport interface RankBarItem {\n key: string;\n label: ReactNode;\n /**\n * `null` is a missing value: an em dash over an empty track, distinct\n * from a real 0, which keeps a visible endpoint.\n */\n value: number | null;\n /** Trailing slot for a per-row link, e.g. \"逐题表现\". */\n action?: ReactNode;\n /**\n * The bar's colour, e.g. the series colour of the model's vendor.\n * Defaults to `--rank-bar-fill`.\n */\n color?: ChartColor;\n}\n\ninterface RankBarProps {\n items: RankBarItem[];\n /**\n * Upper bound of the scale. Defaults to the largest value, or 1 when all\n * are 0; pass `1` for a share or a 0–1 score.\n */\n max?: number;\n /** Scale hint rendered at the bottom, e.g. \"越高越好\". */\n direction?: ReactNode;\n format?: (value: number) => string;\n /** Makes each row's label and bar track select that row. */\n onSelect?: (key: string) => void;\n /**\n * How far the bars are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, the bars draw in\n * once when they mount.\n */\n progress?: number;\n className?: string;\n}\n\nexport function RankBar({\n items,\n max,\n direction,\n format = (value) => value.toFixed(2),\n onSelect,\n progress,\n className,\n}: RankBarProps) {\n const strings = useStrings();\n const values = items.flatMap((item) =>\n item.value === null ? [] : [item.value],\n );\n const [, upperBound] = zeroAnchoredDomain(values, max);\n const cls = [\n 'aegis-rank-bar',\n progress === undefined ? '' : 'aegis-rank-bar--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <div className={cls}>\n {items.map((item, index) => {\n const { value } = item;\n const fill =\n value === null ? null : (\n <div\n className={[\n 'aegis-rank-bar__fill',\n value === 0 ? 'aegis-rank-bar__fill--zero' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n width: `${(upperBound > 0 ? (value / upperBound) * 100 : 0).toString()}%`,\n '--aegis-rank-bar-index': index,\n ...(item.color === undefined || value === 0\n ? {}\n : { background: chartColorValue(item.color) }),\n ...(progress === undefined\n ? {}\n : {\n '--aegis-rank-bar-progress': staggeredProgress(\n progress,\n index,\n items.length,\n ),\n }),\n } as CSSProperties\n }\n >\n <span className=\"aegis-rank-bar__ink\" />\n </div>\n );\n return (\n <div className=\"aegis-rank-bar__row\" key={item.key}>\n {onSelect ? (\n <button\n type=\"button\"\n className=\"aegis-rank-bar__label aegis-rank-bar__label--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {item.label}\n </button>\n ) : (\n <span className=\"aegis-rank-bar__label\">{item.label}</span>\n )}\n {onSelect ? (\n // The label button is the keyboard and screen-reader target;\n // the track only widens the pointer target.\n <button\n type=\"button\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"aegis-rank-bar__track aegis-rank-bar__track--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {fill}\n </button>\n ) : (\n <div\n className=\"aegis-rank-bar__track\"\n role=\"img\"\n aria-label={\n value === null\n ? strings.noValue\n : strings.barValue(format(value), format(upperBound))\n }\n >\n {fill}\n </div>\n )}\n <span\n className={\n value === null\n ? 'aegis-rank-bar__value aegis-rank-bar__value--empty'\n : 'aegis-rank-bar__value'\n }\n >\n {value === null ? '—' : format(value)}\n </span>\n <span className=\"aegis-rank-bar__action\">{item.action}</span>\n </div>\n );\n })}\n <div className=\"aegis-rank-bar__scale\">\n <span className=\"aegis-rank-bar__spacer\" />\n <div className=\"aegis-rank-bar__ticks\">\n <span>0</span>\n {direction !== undefined && (\n <span className=\"aegis-rank-bar__direction\">{direction}</span>\n )}\n <span>{format(upperBound)}</span>\n </div>\n </div>\n </div>\n );\n}\n"],"names":["RankBar","items","max","direction","format","value","onSelect","progress","className","strings","useStrings","values","item","upperBound","zeroAnchoredDomain","cls","jsxs","index","fill","jsx","chartColorValue","staggeredProgress"],"mappings":";;;;AAiDO,SAASA,EAAQ;AAAA,EACtB,OAAAC;AAAA,EACA,KAAAC;AAAA,EACA,WAAAC;AAAA,EACA,QAAAC,IAAS,CAACC,MAAUA,EAAM,QAAQ,CAAC;AAAA,EACnC,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AACF,GAAiB;AACf,QAAMC,IAAUC,EAAA,GACVC,IAASV,EAAM;AAAA,IAAQ,CAACW,MAC5BA,EAAK,UAAU,OAAO,CAAA,IAAK,CAACA,EAAK,KAAK;AAAA,EAAA,GAElC,CAAA,EAAGC,CAAU,IAAIC,EAAmBH,GAAQT,CAAG,GAC/Ca,IAAM;AAAA,IACV;AAAA,IACAR,MAAa,SAAY,KAAK;AAAA,IAC9BC,KAAa;AAAA,EAAA,EAEZ,OAAO,OAAO,EACd,KAAK,GAAG;AACX,SACE,gBAAAQ,EAAC,OAAA,EAAI,WAAWD,GACb,UAAA;AAAA,IAAAd,EAAM,IAAI,CAACW,GAAMK,MAAU;AAC1B,YAAM,EAAE,OAAAZ,MAAUO,GACZM,IACJb,MAAU,OAAO,OACf,gBAAAc;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW;AAAA,YACT;AAAA,YACAd,MAAU,IAAI,+BAA+B;AAAA,UAAA,EAE5C,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,UACX,OACE;AAAA,YACE,OAAO,IAAIQ,IAAa,IAAKR,I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AU,OACN,uDACA;AAAA,YAGL,UAAAA,MAAU,OAAO,MAAMD,EAAOC,CAAK;AAAA,UAAA;AAAA,QAAA;AAAA,QAEtC,gBAAAc,EAAC,QAAA,EAAK,WAAU,0BAA0B,YAAK,OAAA,CAAO;AAAA,MAAA,EAAA,GAlDdP,EAAK,GAmD/C;AAAA,IAEJ,CAAC;AAAA,IACD,gBAAAI,EAAC,OAAA,EAAI,WAAU,yBACb,UAAA;AAAA,MAAA,gBAAAG,EAAC,QAAA,EAAK,WAAU,yBAAA,CAAyB;AAAA,MACzC,gBAAAH,EAAC,OAAA,EAAI,WAAU,yBACb,UAAA;AAAA,QAAA,gBAAAG,EAAC,UAAK,UAAA,IAAA,CAAC;AAAA,QACNhB,MAAc,UACb,gBAAAgB,EAAC,QAAA,EAAK,WAAU,6BAA6B,UAAAhB,GAAU;AAAA,QAEzD,gBAAAgB,EAAC,QAAA,EAAM,UAAAf,EAAOS,CAAU,EAAA,CAAE;AAAA,MAAA,EAAA,CAC5B;AAAA,IAAA,EAAA,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"RankBar.js","sources":["../../../src/components/ui/RankBar.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\n\nimport {\n type ChartColor,\n chartColorValue,\n stageProgress,\n staggeredProgress,\n zeroAnchoredDomain,\n} from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './RankBar.css';\n\nexport interface RankBarItem {\n key: string;\n label: ReactNode;\n /**\n * `null` is a missing value: an em dash over an empty track, distinct\n * from a real 0, which keeps a visible endpoint.\n */\n value: number | null;\n /** The value's confidence interval, drawn as a line over the bar. */\n interval?: [number, number];\n /** Trailing slot for a per-row link, e.g. \"逐题表现\". */\n action?: ReactNode;\n /**\n * The bar's colour, e.g. the series colour of the model's vendor.\n * Defaults to `--rank-bar-fill`.\n */\n color?: ChartColor;\n}\n\ninterface RankBarProps {\n items: RankBarItem[];\n /**\n * Upper bound of the scale. Defaults to the largest value or interval\n * end, or 1 when all are 0; pass `1` for a share or a 0–1 score.\n */\n max?: number;\n /** Scale hint rendered at the bottom, e.g. \"越高越好\". */\n direction?: ReactNode;\n format?: (value: number) => string;\n /** `sm` is a thin bar, for rows that lead with their label. Defaults to `md`. */\n size?: 'md' | 'sm';\n /** Makes each row's label and bar track select that row. */\n onSelect?: (key: string) => void;\n /**\n * How far the bars are drawn, 0 to 1, for a chart that draws as its\n * section scrolls in (`useScrollProgress`). Omitted, the bars draw in\n * once when they mount.\n */\n progress?: number;\n className?: string;\n}\n\nexport function RankBar({\n items,\n max,\n direction,\n format = (value) => value.toFixed(2),\n size = 'md',\n onSelect,\n progress,\n className,\n}: RankBarProps) {\n const strings = useStrings();\n const values = items.flatMap((item) => [\n ...(item.value === null ? [] : [item.value]),\n ...(item.interval ?? []),\n ]);\n const [, upperBound] = zeroAnchoredDomain(values, max);\n const cls = [\n 'aegis-rank-bar',\n size === 'sm' ? 'aegis-rank-bar--sm' : '',\n progress === undefined ? '' : 'aegis-rank-bar--scroll',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ');\n return (\n <div className={cls}>\n {items.map((item, index) => {\n const { value, interval } = item;\n const share = (part: number): string =>\n `${(upperBound > 0 ? (part / upperBound) * 100 : 0).toString()}%`;\n const drawn =\n progress === undefined\n ? 1\n : staggeredProgress(progress, index, items.length);\n const intervalMark = interval && (\n <span\n className=\"aegis-rank-bar__interval\"\n style={{\n left: share(interval[0]),\n width: share(interval[1] - interval[0]),\n opacity: `calc(var(--chart-interval-opacity) * ${stageProgress(drawn, 0.8, 1).toString()})`,\n }}\n />\n );\n const fill =\n value === null ? null : (\n <div\n className={[\n 'aegis-rank-bar__fill',\n value === 0 ? 'aegis-rank-bar__fill--zero' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n {\n width: share(value),\n '--aegis-rank-bar-index': index,\n ...(item.color === undefined || value === 0\n ? {}\n : { background: chartColorValue(item.color) }),\n ...(progress === undefined\n ? {}\n : {\n '--aegis-rank-bar-progress': stageProgress(\n drawn,\n 0,\n interval ? 0.8 : 1,\n ),\n }),\n } as CSSProperties\n }\n >\n <span className=\"aegis-rank-bar__ink\" />\n </div>\n );\n return (\n <div className=\"aegis-rank-bar__row\" key={item.key}>\n {onSelect ? (\n <button\n type=\"button\"\n className=\"aegis-rank-bar__label aegis-rank-bar__label--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {item.label}\n </button>\n ) : (\n <span className=\"aegis-rank-bar__label\">{item.label}</span>\n )}\n {onSelect ? (\n // The label button is the keyboard and screen-reader target;\n // the track only widens the pointer target.\n <button\n type=\"button\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"aegis-rank-bar__track aegis-rank-bar__track--link\"\n onClick={() => {\n onSelect(item.key);\n }}\n >\n {fill}\n {intervalMark}\n </button>\n ) : (\n <div\n className=\"aegis-rank-bar__track\"\n role=\"img\"\n aria-label={\n value === null\n ? strings.noValue\n : `${strings.barValue(format(value), format(upperBound))}${\n interval\n ? ` (${format(interval[0])}–${format(interval[1])})`\n : ''\n }`\n }\n >\n {fill}\n {intervalMark}\n </div>\n )}\n <span\n className={\n value === null\n ? 'aegis-rank-bar__value aegis-rank-bar__value--empty'\n : 'aegis-rank-bar__value'\n }\n >\n {value === null ? '—' : format(value)}\n </span>\n <span className=\"aegis-rank-bar__action\">{item.action}</span>\n </div>\n );\n })}\n <div className=\"aegis-rank-bar__scale\">\n <span className=\"aegis-rank-bar__spacer\" />\n <div className=\"aegis-rank-bar__ticks\">\n <span>0</span>\n {direction !== undefined && (\n <span className=\"aegis-rank-bar__direction\">{direction}</span>\n )}\n <span>{format(upperBound)}</span>\n </div>\n </div>\n </div>\n );\n}\n"],"names":["RankBar","items","max","direction","format","value","size","onSelect","progress","className","strings","useStrings","values","item","upperBound","zeroAnchoredDomain","cls","jsxs","index","interval","share","part","drawn","staggeredProgress","intervalMark","jsx","stageProgress","fill","chartColorValue"],"mappings":";;;;AAsDO,SAASA,EAAQ;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AAAA,YACL,cACEZ,MAAU,OACNK,EAAQ,UACR,GAAGA,EAAQ,SAASN,EAAOC,CAAK,GAAGD,EAAOU,CAAU,CAAC,CAAC,GACpDK,IACI,KAAKf,EAAOe,EAAS,CAAC,CAAC,CAAC,IAAIf,EAAOe,EAAS,CAAC,CAAC,CAAC,MAC/C,EACN;AAAA,YAGL,UAAA;AAAA,cAAAQ;AAAA,cACAH;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,QAGL,gBAAAC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WACEpB,MAAU,OACN,uDACA;AAAA,YAGL,UAAAA,MAAU,OAAO,MAAMD,EAAOC,CAAK;AAAA,UAAA;AAAA,QAAA;AAAA,QAEtC,gBAAAoB,EAAC,QAAA,EAAK,WAAU,0BAA0B,YAAK,OAAA,CAAO;AAAA,MAAA,EAAA,GAxDdZ,EAAK,GAyD/C;AAAA,IAEJ,CAAC;AAAA,IACD,gBAAAI,EAAC,OAAA,EAAI,WAAU,yBACb,UAAA;AAAA,MAAA,gBAAAQ,EAAC,QAAA,EAAK,WAAU,yBAAA,CAAyB;AAAA,MACzC,gBAAAR,EAAC,OAAA,EAAI,WAAU,yBACb,UAAA;AAAA,QAAA,gBAAAQ,EAAC,UAAK,UAAA,IAAA,CAAC;AAAA,QACNtB,MAAc,UACb,gBAAAsB,EAAC,QAAA,EAAK,WAAU,6BAA6B,UAAAtB,GAAU;AAAA,QAEzD,gBAAAsB,EAAC,QAAA,EAAM,UAAArB,EAAOU,CAAU,EAAA,CAAE;AAAA,MAAA,EAAA,CAC5B;AAAA,IAAA,EAAA,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),j=require("react"),q=require("../../lib/chart.cjs");;/* empty css */const R=require("../../locale/useStrings.cjs");function $(p,r){const i=p-1,o=new Set(p>0?[0,i]:[]);for(let n=r-1;n<i;n+=r)i-n>=r/2&&o.add(n);return o}function A({steps:p,currentIndex:r,onSelect:i,keyMoments:o=[],formatStep:n=g=>`#${String(g+1)}`,tickEvery:k,size:y="md",playhead:c,className:S}){const g=R.useStrings(),h=j.useRef(null),a=p.length,v=k??Math.max(1,Math.ceil(a/20)*5),N=$(a,v),_=new Map(o.map((s,e)=>[s,e+1])),[w,d]=j.useState(0),u=Math.min(r??w,Math.max(a-1,0)),M=s=>{if(!i||a===0)return;const e={ArrowLeft:u-1,ArrowRight:u+1,Home:0,End:a-1};if(!(s.key in e))return;s.preventDefault();const l=Math.min(Math.max(e[s.key],0),a-1);d(l),i(l),h.current?.querySelectorAll(".aegis-replay-step-strip__step").item(l).focus()},x={"--aegis-replay-step-strip-count":Math.max(a,1),...c===void 0?{}:{"--aegis-replay-step-strip-head":c,"--aegis-replay-step-strip-head-step":c*a}};return t.jsxs("div",{className:["aegis-replay-step-strip",`aegis-replay-step-strip--${y}`,c===void 0?"":"aegis-replay-step-strip--playhead",S??""].filter(Boolean).join(" "),style:x,children:[o.length>0&&t.jsx("div",{className:"aegis-replay-step-strip__moments","aria-hidden":"true",children:p.map((s,e)=>{const l=_.get(e);return l===void 0?t.jsx("span",{},s.key):t.jsx("span",{className:["aegis-replay-step-strip__moment",e===r?"aegis-replay-step-strip__moment--current":""].filter(Boolean).join(" "),children:l},s.key)})}),t.jsxs("div",{ref:h,className:"aegis-replay-step-strip__bars",role:i?"toolbar":"list","aria-label":g.replaySteps,onKeyDown:M,children:[p.map((s,e)=>{const l=_.get(e),m=l===void 0?s.label:`${s.label} · ${g.replayKeyMoment(l)}`,f={"--aegis-replay-step-strip-color":q.chartColorValue(s.color),"--aegis-replay-step-strip-index":e,...s.weight===void 0?{}:{height:`${(s.weight*100).toString()}%`}},b=["aegis-replay-step-strip__step",s.emphasis?"aegis-replay-step-strip__step--emphasis":"",e===r?"aegis-replay-step-strip__step--current":""].filter(Boolean).join(" ");return i?t.jsx("button",{type:"button",className:b,style:f,title:m,"aria-label":m,"aria-current":e===r?"step":void 0,tabIndex:e===u?0:-1,onClick:()=>{d(e),i(e)}},s.key):t.jsx("span",{role:"listitem",className:b,style:f,title:m,"aria-label":m,"aria-current":e===r?"step":void 0},s.key)}),c!==void 0&&t.jsx("span",{className:"aegis-replay-step-strip__head-track","aria-hidden":"true",children:t.jsx("span",{className:"aegis-replay-step-strip__head"})})]}),y==="md"&&t.jsx("div",{className:"aegis-replay-step-strip__ticks","aria-hidden":"true",children:p.map((s,e)=>t.jsx("span",{className:e===a-1&&a>1?"aegis-replay-step-strip__tick aegis-replay-step-strip__tick--last":"aegis-replay-step-strip__tick",children:N.has(e)?n(e):null},s.key))})]})}exports.ReplayStepStrip=A;
|
|
2
2
|
//# sourceMappingURL=ReplayStepStrip.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReplayStepStrip.cjs","sources":["../../../src/components/ui/ReplayStepStrip.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n useRef,\n useState,\n} from 'react';\n\nimport { type ChartColor, chartColorValue } from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './ReplayStepStrip.css';\n\nexport interface ReplayStepStripItem {\n key: string;\n /** The step kind's colour, e.g. thinking, tool call, failure. */\n color: ChartColor;\n /** Names the step for screen readers and its tooltip, e.g. \"#12 · 验证\". */\n label: string;\n /** A step that changes the course (a check, a failure, the goal): taller. */\n emphasis?: boolean;\n}\n\nexport interface ReplayStepStripProps {\n steps: ReplayStepStripItem[];\n /** The step shown elsewhere on the page; outlined. */\n currentIndex?: number;\n /** Makes each step a button that selects it. */\n onSelect?: (index: number) => void;\n /** Step indices of the key moments, numbered above the strip in order. */\n keyMoments?: number[];\n /** The tick label of a step under the strip. Defaults to `#n`. */\n formatStep?: (index: number) => ReactNode;\n /** A tick every this many steps; defaults to about five ticks. */\n tickEvery?: number;\n className?: string;\n}\n\n/**\n * The steps that get a tick: the first, the last, and every `every`\n * steps between, leaving out one that would crowd the last.\n */\nfunction tickedSteps(count: number, every: number): Set<number> {\n const last = count - 1;\n const ticks = new Set<number>(count > 0 ? [0, last] : []);\n for (let index = every - 1; index < last; index += every) {\n if (last - index >= every / 2) {\n ticks.add(index);\n }\n }\n return ticks;\n}\n\n/**\n * Every step of a run as a bar coloured by its kind, with the key\n * moments numbered above it and step ticks below. With `onSelect`, a bar\n * selects its step; arrow keys move between steps with one tab stop.\n * The gap between bars narrows as steps are added, so a long run still\n * draws every step.\n */\nexport function ReplayStepStrip({\n steps,\n currentIndex,\n onSelect,\n keyMoments = [],\n formatStep = (index) => `#${String(index + 1)}`,\n tickEvery,\n className,\n}: ReplayStepStripProps): ReactElement {\n const strings = useStrings();\n const barsRef = useRef<HTMLDivElement>(null);\n const count = steps.length;\n const every = tickEvery ?? Math.max(1, Math.ceil(count / 20) * 5);\n const ticks = tickedSteps(count, every);\n const momentNumber = new Map(keyMoments.map((step, n) => [step, n + 1]));\n\n // The roving tab stop follows the current step, or the last step the\n // keyboard reached when the host does not mark one.\n const [ownFocus, setOwnFocus] = useState(0);\n const focusIndex = Math.min(currentIndex ?? ownFocus, Math.max(count - 1, 0));\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n if (!onSelect || count === 0) {\n return;\n }\n const target: Record<string, number> = {\n ArrowLeft: focusIndex - 1,\n ArrowRight: focusIndex + 1,\n Home: 0,\n End: count - 1,\n };\n if (!(event.key in target)) {\n return;\n }\n event.preventDefault();\n const next = Math.min(Math.max(target[event.key], 0), count - 1);\n setOwnFocus(next);\n onSelect(next);\n barsRef.current\n ?.querySelectorAll<HTMLButtonElement>('.aegis-replay-step-strip__step')\n .item(next)\n .focus();\n };\n\n const style = {\n '--aegis-replay-step-strip-count': Math.max(count, 1),\n } as CSSProperties;\n return (\n <div\n className={['aegis-replay-step-strip', className ?? '']\n .filter(Boolean)\n .join(' ')}\n style={style}\n >\n <div className=\"aegis-replay-step-strip__moments\" aria-hidden=\"true\">\n {steps.map((step, index) => {\n const n = momentNumber.get(index);\n return n === undefined ? (\n <span key={step.key} />\n ) : (\n <span\n key={step.key}\n className={[\n 'aegis-replay-step-strip__moment',\n index === currentIndex\n ? 'aegis-replay-step-strip__moment--current'\n : '',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {n}\n </span>\n );\n })}\n </div>\n <div\n ref={barsRef}\n className=\"aegis-replay-step-strip__bars\"\n role={onSelect ? 'toolbar' : 'list'}\n aria-label={strings.replaySteps}\n onKeyDown={onKeyDown}\n >\n {steps.map((step, index) => {\n const n = momentNumber.get(index);\n const label =\n n === undefined\n ? step.label\n : `${step.label} · ${strings.replayKeyMoment(n)}`;\n const barStyle = {\n '--aegis-replay-step-strip-color': chartColorValue(step.color),\n } as CSSProperties;\n const cls = [\n 'aegis-replay-step-strip__step',\n step.emphasis ? 'aegis-replay-step-strip__step--emphasis' : '',\n index === currentIndex\n ? 'aegis-replay-step-strip__step--current'\n : '',\n ]\n .filter(Boolean)\n .join(' ');\n return onSelect ? (\n <button\n key={step.key}\n type=\"button\"\n className={cls}\n style={barStyle}\n title={label}\n aria-label={label}\n aria-current={index === currentIndex ? 'step' : undefined}\n tabIndex={index === focusIndex ? 0 : -1}\n onClick={() => {\n setOwnFocus(index);\n onSelect(index);\n }}\n />\n ) : (\n <span\n key={step.key}\n role=\"listitem\"\n className={cls}\n style={barStyle}\n title={label}\n aria-label={label}\n aria-current={index === currentIndex ? 'step' : undefined}\n />\n );\n })}\n </div>\n <div className=\"aegis-replay-step-strip__ticks\" aria-hidden=\"true\">\n {steps.map((step, index) => (\n <span\n key={step.key}\n className={\n index === count - 1 && count > 1\n ? 'aegis-replay-step-strip__tick aegis-replay-step-strip__tick--last'\n : 'aegis-replay-step-strip__tick'\n }\n >\n {ticks.has(index) ? formatStep(index) : null}\n </span>\n ))}\n </div>\n </div>\n );\n}\n"],"names":["tickedSteps","count","every","last","ticks","index","ReplayStepStrip","steps","currentIndex","onSelect","keyMoments","formatStep","tickEvery","className","strings","useStrings","barsRef","useRef","momentNumber","step","n","ownFocus","setOwnFocus","useState","focusIndex","onKeyDown","event","target","next","style","jsxs","jsx","label","barStyle","chartColorValue","cls"],"mappings":"6PA0CA,SAASA,EAAYC,EAAeC,EAA4B,CAC9D,MAAMC,EAAOF,EAAQ,EACfG,EAAQ,IAAI,IAAYH,EAAQ,EAAI,CAAC,EAAGE,CAAI,EAAI,EAAE,EACxD,QAASE,EAAQH,EAAQ,EAAGG,EAAQF,EAAME,GAASH,EAC7CC,EAAOE,GAASH,EAAQ,GAC1BE,EAAM,IAAIC,CAAK,EAGnB,OAAOD,CACT,CASO,SAASE,EAAgB,CAC9B,MAAAC,EACA,aAAAC,EACA,SAAAC,EACA,WAAAC,EAAa,CAAA,EACb,WAAAC,EAAcN,GAAU,IAAI,OAAOA,EAAQ,CAAC,CAAC,GAC7C,UAAAO,EACA,UAAAC,CACF,EAAuC,CACrC,MAAMC,EAAUC,EAAAA,WAAA,EACVC,EAAUC,EAAAA,OAAuB,IAAI,EACrChB,EAAQM,EAAM,OACdL,EAAQU,GAAa,KAAK,IAAI,EAAG,KAAK,KAAKX,EAAQ,EAAE,EAAI,CAAC,EAC1DG,EAAQJ,EAAYC,EAAOC,CAAK,EAChCgB,EAAe,IAAI,IAAIR,EAAW,IAAI,CAACS,EAAMC,IAAM,CAACD,EAAMC,EAAI,CAAC,CAAC,CAAC,EAIjE,CAACC,EAAUC,CAAW,EAAIC,EAAAA,SAAS,CAAC,EACpCC,EAAa,KAAK,IAAIhB,GAAgBa,EAAU,KAAK,IAAIpB,EAAQ,EAAG,CAAC,CAAC,EAEtEwB,EAAaC,GAA+C,CAChE,GAAI,CAACjB,GAAYR,IAAU,EACzB,OAEF,MAAM0B,EAAiC,CACrC,UAAWH,EAAa,EACxB,WAAYA,EAAa,EACzB,KAAM,EACN,IAAKvB,EAAQ,CA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SAAW,0CAA4C,GAC5Dd,IAAUG,EACN,yCACA,EAAA,EAEH,OAAO,OAAO,EACd,KAAK,GAAG,EACX,OAAOC,EACLsB,EAAAA,IAAC,SAAA,CAEC,KAAK,SACL,UAAWI,EACX,MAAOF,EACP,MAAOD,EACP,aAAYA,EACZ,eAAc3B,IAAUG,EAAe,OAAS,OAChD,SAAUH,IAAUmB,EAAa,EAAI,GACrC,QAAS,IAAM,CACbF,EAAYjB,CAAK,EACjBI,EAASJ,CAAK,CAChB,CAAA,EAXKc,EAAK,GAAA,EAcZY,EAAAA,IAAC,OAAA,CAEC,KAAK,WACL,UAAWI,EACX,MAAOF,EACP,MAAOD,EACP,aAAYA,EACZ,eAAc3B,IAAUG,EAAe,OAAS,MAAA,EAN3CW,EAAK,GAAA,CAShB,CAAC,CAAA,CAAA,EAEHY,EAAAA,IAAC,MAAA,CAAI,UAAU,iCAAiC,cAAY,OACzD,SAAAxB,EAAM,IAAI,CAACY,EAAMd,IAChB0B,EAAAA,IAAC,OAAA,CAEC,UACE1B,IAAUJ,EAAQ,GAAKA,EAAQ,EAC3B,oEACA,gCAGL,WAAM,IAAII,CAAK,EAAIM,EAAWN,CAAK,EAAI,IAAA,EAPnCc,EAAK,GAAA,CASb,CAAA,CACH,CAAA,CAAA,CAAA,CAGN"}
|
|
1
|
+
{"version":3,"file":"ReplayStepStrip.cjs","sources":["../../../src/components/ui/ReplayStepStrip.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type KeyboardEvent,\n type ReactElement,\n type ReactNode,\n useRef,\n useState,\n} from 'react';\n\nimport { type ChartColor, chartColorValue } from '../../lib/chart';\nimport { useStrings } from '../../locale';\nimport './ReplayStepStrip.css';\n\nexport interface ReplayStepStripItem {\n key: string;\n /** The step kind's colour, e.g. thinking, tool call, failure. */\n color: ChartColor;\n /** Names the step for screen readers and its tooltip, e.g. \"#12 · 验证\". */\n label: string;\n /** A step that changes the course (a check, a failure, the goal): taller. */\n emphasis?: boolean;\n /**\n * The bar's height as a share of the strip, 0 to 1, for a host that\n * grades its kinds more finely than `emphasis`; it wins over `emphasis`.\n */\n weight?: number;\n}\n\nexport interface ReplayStepStripProps {\n steps: ReplayStepStripItem[];\n /** The step shown elsewhere on the page; outlined. */\n currentIndex?: number;\n /** Makes each step a button that selects it. */\n onSelect?: (index: number) => void;\n /** Step indices of the key moments, numbered above the strip in order. */\n keyMoments?: number[];\n /** The tick label of a step under the strip. Defaults to `#n`. */\n formatStep?: (index: number) => ReactNode;\n /** A tick every this many steps; defaults to about five ticks. */\n tickEvery?: number;\n /** `sm` is a shorter strip without ticks, for a card or a list row. Defaults to `md`. */\n size?: 'md' | 'sm';\n /**\n * Draws a playhead this share of the way along the strip, 0 to 1, and\n * dims the steps past it, e.g. for a strip that plays as the page scrolls.\n */\n playhead?: number;\n className?: string;\n}\n\n/**\n * The steps that get a tick: the first, the last, and every `every`\n * steps between, leaving out one that would crowd the last.\n */\nfunction tickedSteps(count: number, every: number): Set<number> {\n const last = count - 1;\n const ticks = new Set<number>(count > 0 ? [0, last] : []);\n for (let index = every - 1; index < last; index += every) {\n if (last - index >= every / 2) {\n ticks.add(index);\n }\n }\n return ticks;\n}\n\n/**\n * Every step of a run as a bar coloured by its kind, with the key\n * moments numbered above it and step ticks below. With `onSelect`, a bar\n * selects its step; arrow keys move between steps with one tab stop.\n * The gap between bars narrows as steps are added, so a long run still\n * draws every step.\n */\nexport function ReplayStepStrip({\n steps,\n currentIndex,\n onSelect,\n keyMoments = [],\n formatStep = (index) => `#${String(index + 1)}`,\n tickEvery,\n size = 'md',\n playhead,\n className,\n}: ReplayStepStripProps): ReactElement {\n const strings = useStrings();\n const barsRef = useRef<HTMLDivElement>(null);\n const count = steps.length;\n const every = tickEvery ?? Math.max(1, Math.ceil(count / 20) * 5);\n const ticks = tickedSteps(count, every);\n const momentNumber = new Map(keyMoments.map((step, n) => [step, n + 1]));\n\n // The roving tab stop follows the current step, or the last step the\n // keyboard reached when the host does not mark one.\n const [ownFocus, setOwnFocus] = useState(0);\n const focusIndex = Math.min(currentIndex ?? ownFocus, Math.max(count - 1, 0));\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n if (!onSelect || count === 0) {\n return;\n }\n const target: Record<string, number> = {\n ArrowLeft: focusIndex - 1,\n ArrowRight: focusIndex + 1,\n Home: 0,\n End: count - 1,\n };\n if (!(event.key in target)) {\n return;\n }\n event.preventDefault();\n const next = Math.min(Math.max(target[event.key], 0), count - 1);\n setOwnFocus(next);\n onSelect(next);\n barsRef.current\n ?.querySelectorAll<HTMLButtonElement>('.aegis-replay-step-strip__step')\n .item(next)\n .focus();\n };\n\n const style = {\n '--aegis-replay-step-strip-count': Math.max(count, 1),\n ...(playhead === undefined\n ? {}\n : {\n '--aegis-replay-step-strip-head': playhead,\n '--aegis-replay-step-strip-head-step': playhead * count,\n }),\n } as CSSProperties;\n return (\n <div\n className={[\n 'aegis-replay-step-strip',\n `aegis-replay-step-strip--${size}`,\n playhead === undefined ? '' : 'aegis-replay-step-strip--playhead',\n className ?? '',\n ]\n .filter(Boolean)\n .join(' ')}\n style={style}\n >\n {keyMoments.length > 0 && (\n <div className=\"aegis-replay-step-strip__moments\" aria-hidden=\"true\">\n {steps.map((step, index) => {\n const n = momentNumber.get(index);\n return n === undefined ? (\n <span key={step.key} />\n ) : (\n <span\n key={step.key}\n className={[\n 'aegis-replay-step-strip__moment',\n index === currentIndex\n ? 'aegis-replay-step-strip__moment--current'\n : '',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {n}\n </span>\n );\n })}\n </div>\n )}\n <div\n ref={barsRef}\n className=\"aegis-replay-step-strip__bars\"\n role={onSelect ? 'toolbar' : 'list'}\n aria-label={strings.replaySteps}\n onKeyDown={onKeyDown}\n >\n {steps.map((step, index) => {\n const n = momentNumber.get(index);\n const label =\n n === undefined\n ? step.label\n : `${step.label} · ${strings.replayKeyMoment(n)}`;\n const barStyle = {\n '--aegis-replay-step-strip-color': chartColorValue(step.color),\n '--aegis-replay-step-strip-index': index,\n ...(step.weight === undefined\n ? {}\n : { height: `${(step.weight * 100).toString()}%` }),\n } as CSSProperties;\n const cls = [\n 'aegis-replay-step-strip__step',\n step.emphasis ? 'aegis-replay-step-strip__step--emphasis' : '',\n index === currentIndex\n ? 'aegis-replay-step-strip__step--current'\n : '',\n ]\n .filter(Boolean)\n .join(' ');\n return onSelect ? (\n <button\n key={step.key}\n type=\"button\"\n className={cls}\n style={barStyle}\n title={label}\n aria-label={label}\n aria-current={index === currentIndex ? 'step' : undefined}\n tabIndex={index === focusIndex ? 0 : -1}\n onClick={() => {\n setOwnFocus(index);\n onSelect(index);\n }}\n />\n ) : (\n <span\n key={step.key}\n role=\"listitem\"\n className={cls}\n style={barStyle}\n title={label}\n aria-label={label}\n aria-current={index === currentIndex ? 'step' : undefined}\n />\n );\n })}\n {playhead !== undefined && (\n <span\n className=\"aegis-replay-step-strip__head-track\"\n aria-hidden=\"true\"\n >\n <span className=\"aegis-replay-step-strip__head\" />\n </span>\n )}\n </div>\n {size === 'md' && (\n <div className=\"aegis-replay-step-strip__ticks\" aria-hidden=\"true\">\n {steps.map((step, index) => (\n <span\n key={step.key}\n className={\n index === count - 1 && count > 1\n ? 'aegis-replay-step-strip__tick aegis-replay-step-strip__tick--last'\n : 'aegis-replay-step-strip__tick'\n }\n >\n {ticks.has(index) ? formatStep(index) : null}\n </span>\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"names":["tickedSteps","count","every","last","ticks","index","ReplayStepStrip","steps","currentIndex","onSelect","keyMoments","formatStep","tickEvery","size","playhead","className","strings","useStrings","barsRef","useRef","momentNumber","step","n","ownFocus","setOwnFocus","useState","focusIndex","onKeyDown","event","target","next","style","jsxs","jsx","label","barStyle","chartColorValue","cls"],"mappings":"6PAsDA,SAASA,EAAYC,EAAeC,EAA4B,CAC9D,MAAMC,EAAOF,EAAQ,EACfG,EAAQ,IAAI,IAAYH,EAAQ,EAAI,CAAC,EAAGE,CAAI,EAAI,EAAE,EACxD,QAASE,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,OAAO,OAAO,EACd,KAAK,GAAG,EACX,OAAOC,EACLwB,EAAAA,IAAC,SAAA,CAEC,KAAK,SACL,UAAWI,EACX,MAAOF,EACP,MAAOD,EACP,aAAYA,EACZ,eAAc7B,IAAUG,EAAe,OAAS,OAChD,SAAUH,IAAUqB,EAAa,EAAI,GACrC,QAAS,IAAM,CACbF,EAAYnB,CAAK,EACjBI,EAASJ,CAAK,CAChB,CAAA,EAXKgB,EAAK,GAAA,EAcZY,EAAAA,IAAC,OAAA,CAEC,KAAK,WACL,UAAWI,EACX,MAAOF,EACP,MAAOD,EACP,aAAYA,EACZ,eAAc7B,IAAUG,EAAe,OAAS,MAAA,EAN3Ca,EAAK,GAAA,CAShB,CAAC,EACAP,IAAa,QACZmB,EAAAA,IAAC,OAAA,CACC,UAAU,sCACV,cAAY,OAEZ,SAAAA,EAAAA,IAAC,OAAA,CAAK,UAAU,+BAAA,CAAgC,CAAA,CAAA,CAClD,CAAA,CAAA,EAGHpB,IAAS,MACRoB,EAAAA,IAAC,MAAA,CAAI,UAAU,iCAAiC,cAAY,OACzD,SAAA1B,EAAM,IAAI,CAACc,EAAMhB,IAChB4B,EAAAA,IAAC,OAAA,CAEC,UACE5B,IAAUJ,EAAQ,GAAKA,EAAQ,EAC3B,oEACA,gCAGL,WAAM,IAAII,CAAK,EAAIM,EAAWN,CAAK,EAAI,IAAA,EAPnCgB,EAAK,GAAA,CASb,CAAA,CACH,CAAA,CAAA,CAAA,CAIR"}
|
|
@@ -8,6 +8,11 @@ export interface ReplayStepStripItem {
|
|
|
8
8
|
label: string;
|
|
9
9
|
/** A step that changes the course (a check, a failure, the goal): taller. */
|
|
10
10
|
emphasis?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The bar's height as a share of the strip, 0 to 1, for a host that
|
|
13
|
+
* grades its kinds more finely than `emphasis`; it wins over `emphasis`.
|
|
14
|
+
*/
|
|
15
|
+
weight?: number;
|
|
11
16
|
}
|
|
12
17
|
export interface ReplayStepStripProps {
|
|
13
18
|
steps: ReplayStepStripItem[];
|
|
@@ -21,6 +26,13 @@ export interface ReplayStepStripProps {
|
|
|
21
26
|
formatStep?: (index: number) => ReactNode;
|
|
22
27
|
/** A tick every this many steps; defaults to about five ticks. */
|
|
23
28
|
tickEvery?: number;
|
|
29
|
+
/** `sm` is a shorter strip without ticks, for a card or a list row. Defaults to `md`. */
|
|
30
|
+
size?: 'md' | 'sm';
|
|
31
|
+
/**
|
|
32
|
+
* Draws a playhead this share of the way along the strip, 0 to 1, and
|
|
33
|
+
* dims the steps past it, e.g. for a strip that plays as the page scrolls.
|
|
34
|
+
*/
|
|
35
|
+
playhead?: number;
|
|
24
36
|
className?: string;
|
|
25
37
|
}
|
|
26
38
|
/**
|
|
@@ -30,4 +42,4 @@ export interface ReplayStepStripProps {
|
|
|
30
42
|
* The gap between bars narrows as steps are added, so a long run still
|
|
31
43
|
* draws every step.
|
|
32
44
|
*/
|
|
33
|
-
export declare function ReplayStepStrip({ steps, currentIndex, onSelect, keyMoments, formatStep, tickEvery, className, }: ReplayStepStripProps): ReactElement;
|
|
45
|
+
export declare function ReplayStepStrip({ steps, currentIndex, onSelect, keyMoments, formatStep, tickEvery, size, playhead, className, }: ReplayStepStripProps): ReactElement;
|