/** * This is a fork of Rheostat for Preact X. * * @see https://github.com/airbnb/rheostat */ /** @jsx h */ import type { ComponentChildren, ComponentType, JSX } from 'preact'; import { h, Component, createRef } from 'preact'; type BoundingBox = { height: number; left: number; top: number; width: number; }; const KEYS = { DOWN: 40, END: 35, ESC: 27, HOME: 36, LEFT: 37, PAGE_DOWN: 34, PAGE_UP: 33, RIGHT: 39, UP: 38, } as const; const PERCENT_EMPTY = 0; const PERCENT_FULL = 100; function getPosition(value: number, min: number, max: number) { return ((value - min) / (max - min)) * 100; } function getValue(pos: number, min: number, max: number) { const decimal = pos / 100; if (pos === 0) { return min; } else if (pos === 100) { return max; } return Math.round((max - min) * decimal + min); } function getClassName(props: Props) { const orientation = props.orientation === 'vertical' ? 'rheostat-vertical' : 'rheostat-horizontal'; return ['rheostat', orientation] .concat(props.className!.split(' ')) .join(' '); } function getHandleFor(ev: Event) { return Number( (ev.currentTarget as HTMLElement).getAttribute('data-handle-key') ); } function killEvent(ev: Event) { ev.stopPropagation(); ev.preventDefault(); } function Button(props: JSX.IntrinsicElements['button']) { return