master @ 23 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ // Track text for the range slider: ├────█────┤. Runs in the browser │
│ // too (the component script re-renders it on input). │
│ export interface Props { │
│ name: string; │
│ value?: number; │
│ min?: number; │
│ max?: number; │
│ step?: number; │
│ /** Track width in cells, including the ├ ┤ ends. */ │
│ cells?: number; │
│ /** Render the numeric value after the track. */ │
│ showValue?: boolean; │
│ } │
│ │
│ export function buildSliderTrack(value: number, min: number, max: number, cells = │
│ 20): string { │
│ const inner = Math.max(1, cells - 2); │
│ const span = max - min || 1; │
│ const ratio = Math.max(0, Math.min(1, (value - min) / span)); │
│ const pos = Math.round(ratio * (inner - 1)); │
│ const track = Array.from({ length: inner }, (_, i) => (i === pos ? "█" : "─")); │
│ return `├${track.join("")}┤`; │
│ } │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ // Track text for the range slider: ├────█── │
│ ──┤. Runs in the browser │
│ // too (the component script re-renders it o │
│ n input). │
│ export interface Props { │
│ name: string; │
│ value?: number; │
│ min?: number; │
│ max?: number; │
│ step?: number; │
│ /** Track width in cells, including the ├ │
│ ┤ ends. */ │
│ cells?: number; │
│ /** Render the numeric value after the tra │
│ ck. */ │
│ showValue?: boolean; │
│ } │
│ │
│ export function buildSliderTrack(value: numb │
│ er, min: number, max: number, cells = 20): s │
│ tring { │
│ const inner = Math.max(1, cells - 2); │
│ const span = max - min || 1; │
│ const ratio = Math.max(0, Math.min(1, (val │
│ ue - min) / span)); │
│ const pos = Math.round(ratio * (inner - 1) │
│ ); │
│ const track = Array.from({ length: inner } │
│ , (_, i) => (i === pos ? "█" : "─")); │
│ return `├${track.join("")}┤`; │
│ } │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET