import { useState } from 'react' /** R-9: handle sizes in CSS px, constant under zoom. */ export interface HandleSizes { vertex: number insert: number /** The radius around a handle's centre that a press reaches. */ hit: number /** The « − » bubble over the chosen vertex. */ bubble: { w: number; h: number } } // shortcut: the fine bubble size is read off board 05 (no number given by R-9). Upgrade: // take the owner's value if the trial asks for another. const FINE: HandleSizes = { vertex: 12, insert: 16, hit: 10, bubble: { w: 28, h: 22 }, } const COARSE: HandleSizes = { vertex: 18, insert: 24, hit: 22, bubble: { w: 44, h: 36 }, } function deviceSizes(): HandleSizes { const coarse = typeof window.matchMedia === 'function' && window.matchMedia('(any-pointer: coarse)').matches return coarse ? COARSE : FINE } /** * The device's sizes, read ONCE per handle layer from `(any-pointer: coarse)` (R-9): a * hybrid device keeps the size the layer started with, so no handle is re-created under * the finger. */ export function useHandleSizes(): HandleSizes { const [sizes] = useState(deviceSizes) return sizes }