One scene, drawn by both platforms
Describe a drawing once as JSX — rectangles, lines, paths, text, groups and clips — and Hozo draws the same retained scene with the browser's Canvas 2D API on the Web and with React Native Skia on iOS and Android. Pointer and touch hit-testing come from the scene's geometry, and every surface has to say what it means to a screen reader.
One series, drawn and read
Point at a day, hold it on a touch screen, or Tab to it: each candle is a shape with its own hit area and its own hidden button.
A screen reader is given the table below instead of the pixels. It is in the page either way; this only makes it visible.
Pixels are not content, so the type says what is
A canvas is one element; what is drawn on it is invisible to a keyboard and a screen reader. Every <Canvas> therefore has to choose one of three meanings, and leaving all three out is a type error.
A named image
The surface is exposed as one image with that name. Right for a sparkline whose point fits in a sentence.
A real alternative
The pixels leave the accessibility tree and your fallback — a table, a list — is placed beside them, visually hidden. You build it from the same data as the drawing, as the demo above does.
Nothing to say
Ornament. The canvas and its surface are hidden from assistive technology completely.
A shape you can press is a control
Give a shape onPress or href and an accessibilityLabel, and Hozo puts a real button or link for it in a hidden layer, in drawing order. Focusing it indicates the shape the way hovering does, so the demo's tooltip follows the keyboard too. Shapes drawn in several parts share one control through accessibilityControlId. A pressable shape with no name stays pointer-only and says so in development.
Canvas or SVG?
Hozo has both, and they are different tools rather than two speeds of one. Choose by how much is drawn and by what each mark has to be.
SVG (@hozo/svg)
- Icons, logos and other marks that are design
- Charts of hundreds of marks, each a DOM element you can style and hover with CSS
- Filter effects such as blur, which @hozo/canvas does not apply to shapes
- Emits real
<svg>on the Web
Canvas (@hozo/canvas)
- Thousands of marks, where one DOM node each would be the cost
- Scenes redrawn often, and textured or vertex-coloured triangle meshes
- Hit-testing from geometry rather than from one element per mark
- One surface; meaning comes from a label or a fallback you provide
Writing one
The shapes are properties of Canvas. The fallback is built from the same rows as the bars, so the two cannot drift apart.
import { Canvas } from '@hozo/canvas'export function Revenue({ quarters }) { return ( <Canvas viewBox={[0, 0, 400, 200]} accessibilityLabel="Revenue by quarter" accessibleFallback={<RevenueTable quarters={quarters} />} > {quarters.map((q, i) => ( <Canvas.Rect key={q.name} x={i * 100 + 20} y={200 - q.value} width={60} height={q.value} fill="#c8a882" accessibilityLabel={q.name} onPress={() => select(q)} /> ))} </Canvas> )}