1- <section >
1+ <section aria-labelledby = " benchmarks-heading " >
22 <header >
3- <h2 >Ada is fast</h2 >
3+ <h2 id = " benchmarks-heading " >Ada is fast</h2 >
44 <p >
55 On a benchmark where we need to validate and normalize{ " " }
66 <a
1212 </header >
1313 <div >
1414 <div style =" width: 800px;" class =" container-chart" >
15- <canvas id =" acquisitions" ></canvas >
15+ <canvas
16+ id =" acquisitions"
17+ role =" img"
18+ aria-label =" Bar chart comparing URL parsing speed: Ada 188 ns/URL, Servo URL 664 ns/URL, cURL 1471 ns/URL"
19+ ></canvas >
1620 </div >
21+ <!-- Visually-hidden text alternative for screen readers -->
22+ <table class =" sr-only" >
23+ <caption >URL parsing speed comparison (lower is faster)</caption >
24+ <thead >
25+ <tr >
26+ <th scope =" col" >Parser</th >
27+ <th scope =" col" >Speed (ns/URL)</th >
28+ </tr >
29+ </thead >
30+ <tbody >
31+ <tr ><td >Ada</td ><td >188</td ></tr >
32+ <tr ><td >Servo URL</td ><td >664</td ></tr >
33+ <tr ><td >cURL</td ><td >1471</td ></tr >
34+ </tbody >
35+ </table >
1736 </div >
1837</section >
1938
5978 margin-inline: auto;
6079 }
6180
81+ /* Visually hidden but accessible to screen readers */
82+ .sr-only {
83+ position: absolute;
84+ width: 1px;
85+ height: 1px;
86+ padding: 0;
87+ margin: -1px;
88+ overflow: hidden;
89+ clip: rect(0, 0, 0, 0);
90+ white-space: nowrap;
91+ border-width: 0;
92+ }
93+
6294 :root[data-theme="dark"] {
6395 & p {
6496 color: var(--sl-color-gray-2);
94126
95127<script >
96128 import Chart from "chart.js/auto";
97-
98- (async function () {
99- const data = [
100- { competitors: "Ada", count: 188 },
101- { competitors: "Servo URL", count: 664 },
102- { competitors: "cURL", count: 1471 },
103- ];
104-
105- new Chart(document.getElementById("acquisitions") as HTMLCanvasElement, {
129+
130+ function getChartColors() {
131+ const style = getComputedStyle(document.documentElement);
132+ // Use Starlight's own grey tokens so colours adapt to both themes
133+ const tickColor =
134+ style.getPropertyValue("--sl-color-gray-3").trim() || "#6b7280";
135+ const gridColor =
136+ style.getPropertyValue("--sl-color-gray-6").trim() ||
137+ "rgba(107,114,128,0.2)";
138+ return { tickColor, gridColor };
139+ }
140+
141+ const data = [
142+ { competitors: "Ada", count: 188 },
143+ { competitors: "Servo URL", count: 664 },
144+ { competitors: "cURL", count: 1471 },
145+ ];
146+
147+ let chart: Chart | null = null;
148+
149+ function buildChart() {
150+ const canvas = document.getElementById(
151+ "acquisitions"
152+ ) as HTMLCanvasElement | null;
153+ if (!canvas) return;
154+
155+ if (chart) chart.destroy();
156+
157+ const { tickColor, gridColor } = getChartColors();
158+
159+ chart = new Chart(canvas, {
106160 type: "bar",
107161 options: {
108162 indexAxis: "y",
114168 callback: function (value) {
115169 return `${value}ns`;
116170 },
117- color: "#757887" ,
171+ color: tickColor ,
118172 },
119173 grid: {
120174 display: true,
121- color: "#757887" ,
175+ color: gridColor ,
122176 },
123177 },
124178 y: {
125179 ticks: {
126- color: "#757887" ,
180+ color: tickColor ,
127181 },
128182 grid: {
129183 display: false,
161215 ],
162216 },
163217 });
164- })();
165- </script >
218+ }
219+
220+ buildChart();
221+
222+ // Rebuild the chart whenever Starlight switches between light and dark themes
223+ // so tick/grid colours stay legible in both modes.
224+ new MutationObserver(() => buildChart()).observe(document.documentElement, {
225+ attributes: true,
226+ attributeFilter: ["data-theme"],
227+ });
228+ </script >
0 commit comments