@weasel-js/ui-input 0.0.0-stage → 1.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/heldAt.ts","../src/tree.ts","../src/typeahead.ts","../src/list.ts","../src/tabOrder.ts","../src/keySteps.ts","../src/scalar.ts","../src/slider.ts","../src/span.ts","../src/textCommit.ts","../src/reorder.ts","../src/edgeScroll.ts","../src/spatial.ts","../src/scheduler.ts","../src/stepRepeat.ts","../src/sweep.ts","../src/grid.ts","../src/selection.ts"],"names":["first","range","ms","_","values"],"mappings":";;;;AAEO,SAAS,MAAA,CAAO,QAAgB,EAAA,EAAkC;AACvE,EAAA,OAAO,EAAA,KAAO,IAAA,IAAQ,MAAA,CAAO,SAAA,CAAU,EAAE,KAAK,EAAA,IAAM,CAAA,IAAK,EAAA,GAAK,MAAA,GAAS,EAAA,GAAK,IAAA;AAC9E;;;ACqBO,SAAS,OAAA,CAAW,KAAA,EAAqB,EAAA,EAAY,GAAA,EAAa,KAAA,EAAoC;AAC3G,EAAA,MAAM,IAAA,GAAO,MAAM,EAAE,CAAA;AACrB,EAAA,IAAI,IAAA,KAAS,MAAA,EAAW,OAAO,EAAE,SAAS,KAAA,EAAM;AAChD,EAAA,MAAM,SAAA,GAAY,KAAA,CAAM,SAAA,GAAY,IAAI,CAAA,IAAK,IAAA;AAC7C,EAAA,MAAM,CAAC,KAAA,EAAO,MAAM,CAAA,GAAI,KAAA,CAAM,GAAA,KAAQ,KAAA,GAAQ,CAAC,WAAA,EAAa,YAAY,CAAA,GAAI,CAAC,cAAc,WAAW,CAAA;AACtG,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,IAAI,CAAC,MAAM,QAAA,CAAS,IAAI,GAAG,OAAO,EAAE,SAAS,KAAA,EAAM;AACnD,IAAA,IAAI,CAAC,KAAA,CAAM,MAAA,CAAO,IAAI,CAAA,SAAU,SAAA,GAA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M,MAAM,MAAA,GAAS,CAAA;AACtF,IAAA,OAAO,EAAE,SAAS,MAAA,IAAU,CAAA,GAAI,SAAS,MAAA,EAAW,MAAA,EAAQ,CAAC,CAAA,KAAM;AAAE,MAAA,IAAI,OAAA,CAAQ,CAAC,CAAA,EAAG,KAAA,CAAM,MAAK,CAAE,GAAA,CAAI,GAAG,IAAI,CAAA;AAAA,IAAG,CAAA,EAAE;AAAA,EACpH;AACA,EAAA,OAAO,EAAE,QAAA,EAAU,CAAC,CAAA,KAAM;AAAE,IAAA,IAAI,OAAA,CAAQ,CAAC,CAAA,EAAG,KAAA,CAAM,MAAM,CAAC,CAAA;AAAA,EAAG,CAAA,EAAE;AAChE","file":"index.js","sourcesContent":["/** `at` when it names an item of a list `length` long, else null: a highlight left past the end of a list that\n * shrank, or an index that names nothing, reads as no highlight. */\nexport function heldAt(length: number, at: number | null): number | null {\n return at !== null && Number.isInteger(at) && at >= 0 && at < length ? at : null;\n}\n","/** How a list that folds is read: which items are branches, which are open, and which item is whose child. */\nexport interface TreeShape<T> {\n /** Whether `item` can open, its children shown or not. */\n isBranch(item: T): boolean;\n isOpen(item: T): boolean;\n /** Whether `child` is one of `parent`'s own children. */\n isChildOf(child: T, parent: T): boolean;\n /** Whether a branch can open or close now. A disabled one can't. Default: every branch. */\n canToggle?(item: T): boolean;\n /** The inline direction the rows read in. Under `'rtl'` Left opens and Right closes. Default `'ltr'`. */\n dir?: 'ltr' | 'rtl';\n}\n\n/** What Right or Left does on one item of a tree: open or close it, move the highlight, or nothing (`handled` false).\n * `at` null is a key the tree takes without moving. */\nexport type TreeKeyResult =\n | { handled: false }\n | { handled: true; toggle: number }\n | { handled: true; at: number | null };\n\n/**\n * Right and Left on the item at `at`, the WAI-ARIA tree way: Right opens a closed branch, else steps to its first\n * child; Left closes an open branch, else steps to the parent. Mirrored under `dir: 'rtl'`. `items` are the rows\n * shown, in drawn order.\n */\nexport function treeKey<T>(items: readonly T[], at: number, key: string, shape: TreeShape<T>): TreeKeyResult {\n const item = items[at];\n if (item === undefined) return { handled: false };\n const canToggle = shape.canToggle?.(item) ?? true;\n const [opens, closes] = shape.dir === 'rtl' ? ['ArrowLeft', 'ArrowRight'] : ['ArrowRight', 'ArrowLeft'];\n if (key === opens) {\n if (!shape.isBranch(item)) return { handled: false };\n if (!shape.isOpen(item)) return canToggle ? { handled: true, toggle: at } : { handled: true, at: null };\n const next = items[at + 1];\n return { handled: true, at: next !== undefined && shape.isChildOf(next, item) ? at + 1 : null };\n }\n if (key !== closes) return { handled: false };\n if (shape.isOpen(item) && canToggle) return { handled: true, toggle: at };\n const parent = items.findIndex((p) => shape.isChildOf(item, p));\n return parent < 0 ? { handled: false } : { handled: true, at: parent };\n}\n","import { heldAt } from './heldAt';\nimport type { ListShape } from './list';\n\n/** How typeahead reads a list: its shape, and the text each item is found by. */\nexport interface TypeaheadShape<T> extends Pick<ListShape<T>, 'canStop'> {\n label(item: T): string;\n}\n\n/** How long typing can pause before the typeahead buffer starts over, in milliseconds. */\nexport const TYPEAHEAD_RESET_MS = 500;\n\n/** Whether `text` is one typed character, counted by code point: an emoji is one, though it takes two UTF-16 units. */\nexport function isOneChar(text: string): boolean {\n return text.length > 0 && text.length <= 2 && [...text].length === 1;\n}\n\n/** What has been typed so far, and when the last key came. */\nexport interface TypeaheadBuffer {\n text: string;\n at: number;\n}\n\n/** A buffer nothing has been typed into. */\nexport const EMPTY_TYPEAHEAD: TypeaheadBuffer = { text: '', at: -Infinity };\n\n/** The item a typed `query` lands on, searching forward from `at` with\n * wrap. A one-letter query starts after the highlight so repeating a letter\n * cycles; a longer one starts at it so typing on keeps the match. An index\n * that names no item searches from the start. */\nexport function typeaheadMatch<T>(\n items: readonly T[], at: number | null, query: string, shape: TypeaheadShape<T>,\n): number | null {\n const q = fold(query);\n const n = items.length;\n const from = heldAt(n, at);\n const start = from == null ? 0 : isOneChar(query) ? from + 1 : from;\n for (let k = 0; k < n; k++) {\n const i = (start + k) % n;\n const item = items[i]!;\n if ((shape.canStop?.(item) ?? true) && fold(shape.label(item)).startsWith(q)) return i;\n }\n return null;\n}\n\n/** `s` lowercased and composed, so a label spelling `é` as `e` + U+0301 is found by typing `é`. */\nfunction fold(s: string): string {\n return s.toLowerCase().normalize('NFC');\n}\n\n/** One typed character: the new buffer and the item it lands on. A key that\n * repeats the whole buffer searches that one letter, so it cycles. */\nexport function typeaheadStep<T>(\n items: readonly T[],\n from: number | null,\n buffer: TypeaheadBuffer,\n key: string,\n now: number,\n shape: TypeaheadShape<T>,\n resetMs: number = TYPEAHEAD_RESET_MS,\n): { buffer: TypeaheadBuffer; hit: number | null } {\n const prev = now - buffer.at < resetMs ? buffer.text : '';\n const k = key.toLowerCase();\n const cycling = prev !== '' && [...prev].every((c) => c.toLowerCase() === k);\n const text = cycling ? key : prev + key;\n return { buffer: { text, at: now }, hit: typeaheadMatch(items, from, text, shape) };\n}\n","import { heldAt } from './heldAt';\nimport { treeKey, type TreeShape } from './tree';\nimport { isOneChar } from './typeahead';\n\n/** How a list's items are read: which ones the highlight can land on, and which way its arrows run. */\nexport interface ListShape<T> {\n /** Whether the highlight can land on `item`. A separator or a heading can't. Default: every item. */\n canStop?(item: T): boolean;\n /** Which arrow keys move the highlight. `'both'` answers to all four, the way a radio group does. Default `'vertical'`. */\n orientation?: 'vertical' | 'horizontal' | 'both';\n /** The inline direction the items are laid out in. Under `'rtl'` Left steps forward and Right back. Default `'ltr'`. */\n dir?: 'ltr' | 'rtl';\n /** An arrow past either end comes round to the other. Default true. */\n wrap?: boolean;\n}\n\nconst always = () => true;\n\n/** Index of the first item the highlight can land on, or null for a list with none. */\nexport function firstStop<T>(items: readonly T[], shape: ListShape<T> = {}): number | null {\n const i = items.findIndex(shape.canStop ?? always);\n return i < 0 ? null : i;\n}\n\n/** The next item the highlight can land on from `at` in direction `dir`; from `null`, or an index that names no\n * item, the first or last. Without wrap, an end stays where it is. Null for a list with no such item. */\nexport function stepStop<T>(\n items: readonly T[], at: number | null, dir: 1 | -1, shape: ListShape<T> = {},\n): number | null {\n const canStop = shape.canStop ?? always;\n const wrap = shape.wrap ?? true;\n const n = items.length;\n const from = heldAt(n, at);\n let i = from ?? (dir === 1 ? -1 : n);\n for (let k = 0; k < n; k++) {\n i += dir;\n if (i < 0 || i >= n) {\n if (!wrap) break;\n i = (i + n) % n;\n }\n if (canStop(items[i]!)) return i;\n }\n return !wrap && from !== null && canStop(items[from]!) ? from : null;\n}\n\n/** What one key does to a list's highlight. `handled` false for a key that is not the list's to move. */\nexport type RovingResult = { handled: false } | { handled: true; at: number | null };\n\n/** Which way an arrow key steps a list of `shape`: 1, -1, or 0 for a key that is not one of its arrows. */\nexport function arrowDir(key: string, shape: ListShape<unknown>): 1 | -1 | 0 {\n const orientation = shape.orientation ?? 'vertical';\n if (orientation !== 'horizontal') {\n if (key === 'ArrowDown') return 1;\n if (key === 'ArrowUp') return -1;\n }\n if (orientation !== 'vertical') {\n const forward = shape.dir === 'rtl' ? -1 : 1;\n if (key === 'ArrowRight') return forward;\n if (key === 'ArrowLeft') return -forward as 1 | -1;\n }\n return 0;\n}\n\n/** Move the highlight `at` by one key: the arrows along the list's orientation, Home and End. */\nexport function rovingKey<T>(items: readonly T[], at: number | null, key: string, shape: ListShape<T> = {}): RovingResult {\n if (key === 'Home') return { handled: true, at: stepStop(items, null, 1, shape) };\n if (key === 'End') return { handled: true, at: stepStop(items, null, -1, shape) };\n const dir = arrowDir(key, shape as ListShape<unknown>);\n return dir === 0 ? { handled: false } : { handled: true, at: stepStop(items, at, dir, shape) };\n}\n\n/** A key as {@link rowKey} reads it: the key and the modifiers held. */\nexport interface KeyPress {\n key: string;\n shiftKey?: boolean;\n ctrlKey?: boolean;\n metaKey?: boolean;\n altKey?: boolean;\n}\n\n/** A list of rows, and which of the keys past the arrows its caller answers. */\nexport interface RowKeysShape<T> extends ListShape<T> {\n /** Set for a list that folds: Right and Left open, close, and walk it ({@link treeKey}). */\n tree?: TreeShape<T>;\n /** Cmd/Ctrl+A selects every row. */\n selectAll?: boolean;\n /** Enter and Space activate a row. */\n activate?: boolean;\n /** Typing a character searches the rows' text. */\n typeahead?: boolean;\n}\n\n/** What one key on a row asks for, for the caller to carry out. */\nexport type RowKeyAction =\n /** Select every row. */\n | { kind: 'selectAll' }\n /** Move to row `at`, extending a range from the anchor when `extend`. `at` null takes the key without moving. */\n | { kind: 'move'; at: number | null; extend: boolean }\n /** Open or close the branch at `at`. */\n | { kind: 'toggle'; at: number }\n | { kind: 'activate' }\n /** Hand the key to typeahead. `held` when the key is the list's whether or not the search finds a row. */\n | { kind: 'type'; held: boolean };\n\n/**\n * What a key on row `at` of a list of rows does, in the order the keys are tried: Mod+A, the arrows with Home\n * and End (Shift to extend), a tree's Right and Left, a space typed mid-search, Enter or Space to activate, then any\n * other character to search. `searching` says a typeahead search is under way. `apple` says `mod` is Command, as\n * `isApplePlatform` from `@weasel-js/gestures` reads it; otherwise it is Ctrl. Null for a key that is not the list's.\n */\nexport function rowKey<T>(\n items: readonly T[], at: number, press: KeyPress, shape: RowKeysShape<T> = {}, searching = false, apple = false,\n): RowKeyAction | null {\n const { key } = press;\n const chord = !!(press.ctrlKey || press.metaKey);\n const mod = !!(apple ? press.metaKey && !press.ctrlKey : press.ctrlKey && !press.metaKey);\n if (shape.selectAll && key.toLowerCase() === 'a' && mod && !press.altKey && !press.shiftKey) return { kind: 'selectAll' };\n const step = rovingKey(items, at, key, shape);\n if (step.handled) return { kind: 'move', at: step.at, extend: !!press.shiftKey };\n if (shape.tree && (key === 'ArrowRight' || key === 'ArrowLeft')) {\n const t = treeKey(items, at, key, shape.dir && !shape.tree.dir ? { ...shape.tree, dir: shape.dir } : shape.tree);\n if (!t.handled) return null;\n return 'toggle' in t ? { kind: 'toggle', at: t.toggle } : { kind: 'move', at: t.at, extend: false };\n }\n // Mid-search a space is a typed character: \"new f\" must not activate at the space.\n if (key === ' ' && shape.typeahead && searching) return { kind: 'type', held: true };\n if (key === 'Enter' || key === ' ') return shape.activate ? { kind: 'activate' } : null;\n if (shape.typeahead && isOneChar(key) && !chord && !press.altKey) return { kind: 'type', held: false };\n return null;\n}\n","/** Tab order: targets that declare a place come first, ascending, then the rest in the order given. In the DOM a\n * positive `tabindex` declares one and `0` does not. */\nexport function tabSort<T>(targets: readonly T[], declared: (target: T) => number | undefined): T[] {\n const key = (t: T) => declared(t) ?? Number.POSITIVE_INFINITY;\n // Array.prototype.sort is stable, so ties and the undeclared keep the given order.\n return [...targets].sort((a, b) => key(a) - key(b));\n}\n\n/** The target one Tab step from `from` through `order`, or null past either end. From nothing, `'next'` is the\n * first and `'prev'` the last. A `from` that is out of the order (hidden since it took focus, say) steps from where\n * it sits, which `isBefore` says; without it, such a `from` steps as nothing does. */\nexport function tabStep<T>(\n order: readonly T[], from: T | null, direction: 'next' | 'prev', isBefore?: (a: T, b: T) => boolean,\n): T | null {\n const forward = direction === 'next';\n const here = from === null ? -1 : order.indexOf(from);\n let at: number;\n if (here !== -1) at = here + (forward ? 1 : -1);\n else if (from === null || !isBefore) at = forward ? 0 : order.length - 1;\n else {\n const after = order.findIndex((t) => isBefore(from, t));\n const end = after === -1 ? order.length : after;\n at = forward ? end : end - 1;\n }\n return order[at] ?? null;\n}\n","import { COARSE_STEPS } from '@weasel-js/quantity';\nimport { arrowDir } from './list';\n\nexport { COARSE_STEPS };\n\n/** Steps an arrow key asks for along one axis: one, or {@link COARSE_STEPS} with Shift, positive\n * toward ArrowRight and ArrowUp. Under `'rtl'` ArrowLeft and ArrowRight swap, as a native range\n * input's do. `null` for any other key. A caller multiplies by its own step. */\nexport function arrowSteps(key: string, shift: boolean, dir: 'ltr' | 'rtl' = 'ltr'): number | null {\n const steps = shift ? COARSE_STEPS : 1;\n if (key === 'ArrowUp') return steps;\n if (key === 'ArrowDown') return -steps;\n const d = arrowDir(key, { orientation: 'horizontal', dir });\n return d === 0 ? null : d * steps;\n}\n\n/** Steps an arrow key asks for on a plane, in screen axes: `dy` is positive toward ArrowDown.\n * One step, or {@link COARSE_STEPS} with Shift; `null` for any other key. */\nexport function arrowMove(key: string, shift: boolean): { dx: number; dy: number } | null {\n const steps = arrowSteps(key, shift);\n if (steps === null) return null;\n return key === 'ArrowRight' || key === 'ArrowLeft' ? { dx: steps, dy: 0 } : { dx: 0, dy: -steps };\n}\n\n/** What a key does along a range: {@link arrowSteps}, the Page keys ({@link COARSE_STEPS} steps),\n * or Home and End (an end of the range). `null` for any other key. */\nexport function rangeKey(key: string, shift: boolean, dir: 'ltr' | 'rtl' = 'ltr'): number | 'home' | 'end' | null {\n switch (key) {\n case 'PageUp': return COARSE_STEPS;\n case 'PageDown': return -COARSE_STEPS;\n case 'Home': return 'home';\n case 'End': return 'end';\n default: return arrowSteps(key, shift, dir);\n }\n}\n","/** A box on a surface, by its top-left corner and size. */\nexport interface Box {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** `v` held to `lo`..`hi`. `lo` wins when the bounds cross; `NaN` passes through. */\nexport function clamp(v: number, lo: number, hi: number): number {\n const c = v > hi ? hi : v;\n return c < lo ? lo : c;\n}\n","import { clamp } from './scalar';\nimport { snapToStep } from '@weasel-js/quantity';\nimport { rangeKey } from './keySteps';\n\n/** A value on a slider's track the thumb can come to rest on, with whatever label draws under it. */\nexport interface SliderStop<L = unknown> {\n value: number;\n label?: L;\n}\n\n/** The stops that are actually reachable: inside the range, deduped, ascending.\n * A duplicate keeps the first label given for its value. */\nexport function usableStops<L>(\n stops: readonly (number | SliderStop<L>)[] | undefined, min: number, max: number,\n): SliderStop<L>[] {\n if (!stops || stops.length === 0) return [];\n const byValue = new Map<number, SliderStop<L>>();\n for (const stop of stops) {\n const s = typeof stop === 'number' ? { value: stop } : stop;\n if (!(s.value >= min && s.value <= max)) continue;\n const seen = byValue.get(s.value);\n if (!seen || (seen.label === undefined && s.label !== undefined)) byValue.set(s.value, s);\n }\n return [...byValue.values()].sort((a, b) => a.value - b.value);\n}\n\n/** The two-way map between a value and its place along a track, as a fraction: 0 at one end, 1 at the other. */\nexport interface TrackMap {\n toFraction(v: number): number;\n toValue(f: number): number;\n}\n\n/** The stop nearest `v`, or `v` itself when none lies within `tolerance`. With `toFraction` the distance is\n * measured along the track and `tolerance` is a track fraction, so evenly spaced stops attract over the same\n * distance; without it both are in `v`'s own units. */\nexport function attract(\n v: number, stops: readonly number[], tolerance: number, toFraction: (v: number) => number = (x) => x,\n): number {\n const f = toFraction(v);\n let best = v;\n let bestGap = tolerance;\n for (const stop of stops) {\n const gap = Math.abs(toFraction(stop) - f);\n if (gap <= bestGap) {\n best = stop;\n bestGap = gap;\n }\n }\n return best;\n}\n\n/** The map for a track its stops divide evenly, whatever their values: each gap between two stops takes the\n * same length, and a value sits between its neighbors in proportion. Needs two stops, ascending. */\nexport function evenMap(stops: readonly number[]): TrackMap {\n const gaps = stops.length - 1;\n return {\n toFraction(v) {\n const x = clamp(v, stops[0]!, stops[gaps]!);\n let i = 0;\n while (i < gaps - 1 && x > stops[i + 1]!) i++;\n return (i + (x - stops[i]!) / (stops[i + 1]! - stops[i]!)) / gaps;\n },\n toValue(f) {\n const c = clamp(f, 0, 1);\n const i = Math.min(gaps - 1, Math.floor(c * gaps));\n return stops[i]! + (c * gaps - i) * (stops[i + 1]! - stops[i]!);\n },\n };\n}\n\n/** What a pointer on a slider's track reads: how the track maps to values, and what has a say in the value picked. */\nexport interface SliderAtShape extends TrackMap {\n /** The least and greatest value a pointer can pick. Either may be infinite. */\n min: number;\n max: number;\n step?: number;\n /** Where the step grid starts. Default `min`. */\n origin?: number;\n /** Values the pointer is pulled onto. */\n stops?: readonly number[];\n /** How near a stop pulls, as a track fraction. Default 0: only a pointer exactly on a stop lands on it. */\n pull?: number;\n /** Only a stop can be picked: the nearest, however far. */\n strict?: boolean;\n /** Pass the stops by. Not read under `strict`. */\n free?: boolean;\n}\n\n/** The value a pointer at track fraction `f` picks: the track's value there, on the step grid and inside\n * `min` to `max`, then pulled onto a stop within reach. */\nexport function sliderAt(f: number, shape: SliderAtShape): number {\n const stops = shape.stops ?? [];\n const v = shape.toValue(f);\n if (shape.strict) return attract(v, stops, Infinity, shape.toFraction);\n const q = clamp(snapToStep(v, shape.step, shape.origin ?? shape.min), shape.min, shape.max);\n return stops.length > 0 && !shape.free ? attract(q, stops, shape.pull ?? 0, shape.toFraction) : q;\n}\n\n/** The stop `count` places past `v` in `direction`, saturating at either end. */\nexport function stepStops(stops: readonly number[], v: number, direction: 1 | -1, count: number): number {\n if (direction > 0) {\n const first = stops.findIndex(stop => stop > v);\n if (first === -1) return stops[stops.length - 1]!;\n return stops[Math.min(stops.length - 1, first + count - 1)]!;\n }\n let first = -1;\n for (let i = stops.length - 1; i >= 0; i--) {\n if (stops[i]! < v) {\n first = i;\n break;\n }\n }\n if (first === -1) return stops[0]!;\n return stops[Math.max(0, first - (count - 1))]!;\n}\n\n/** `step` when it is positive; otherwise a hundredth of the span. */\nexport function defaultStep(step: number | undefined, min: number, max: number): number {\n if (step !== undefined && step > 0) return step;\n return (max - min) / 100;\n}\n\n/** Keep thumb `index` strictly between its neighbors: a step apart, or a thousandth of the span without one, and\n * inside `min` to `max`. Neighbors too close for that hold it between them, or failing that inside `min` to `max`. */\nexport function clampOrdered(\n v: number,\n thumbs: readonly { value: number }[],\n index: number,\n min: number,\n max: number,\n step: number | undefined,\n): number {\n const gap = step !== undefined && step > 0 ? step : (max - min) / 1000;\n const below = index > 0 ? thumbs[index - 1]!.value : -Infinity;\n const above = index < thumbs.length - 1 ? thumbs[index + 1]!.value : Infinity;\n const lower = Math.max(min, below + gap);\n const upper = Math.min(max, above - gap);\n if (lower <= upper) return clamp(v, lower, upper);\n const lo = Math.max(min, below);\n const hi = Math.min(max, above);\n return lo <= hi ? clamp(v, lo, hi) : clamp(v, min, max);\n}\n\n/**\n * Where a keystroke of `delta` takes a thumb at `from` when the move meets an\n * end of the slider's finite `range`, or `null` when it stays inside. An\n * endless end's stop lies on the `track` beyond the range, at a distance drawn\n * for the eye; to the keyboard it is one press past the range's end. A move\n * that would overshoot the end lands on the end first, and one back from an\n * end stop that would cross the whole range lands on its other end.\n */\nexport function crossEnd(\n from: number,\n delta: number,\n stepSize: number,\n range: readonly [number, number],\n track: readonly [number, number],\n): number | null {\n const [lo, hi] = range;\n if (from > hi) return delta < 0 ? Math.max(lo, hi + delta + stepSize) : from;\n if (from < lo) return delta > 0 ? Math.min(hi, lo + delta - stepSize) : from;\n if (from + delta > hi) return from < hi ? hi : track[1];\n if (from + delta < lo) return from > lo ? lo : track[0];\n return null;\n}\n\n/** What a key press on one thumb of a slider reads. */\nexport interface SliderKeyShape {\n thumbs: readonly { value: number }[];\n /** The thumb the key went to. */\n index: number;\n /** The ends of the track. */\n min: number;\n max: number;\n step?: number;\n /** Usable stops, ascending. With any, a keystroke moves by whole stops rather than by value. */\n stops?: readonly number[];\n /** Keep the thumb between its neighbors. */\n ordered?: boolean;\n /** The finite range, where the track runs past it to an endless end's stop. Default the track. */\n range?: readonly [number, number];\n /** Under `'rtl'` the horizontal arrows are mirrored, as the values run from the right end. */\n dir?: 'ltr' | 'rtl';\n /** This thumb's own limits inside the track. Read only for a key the slider answers to. */\n bounds?(): readonly [number, number];\n /** Where the thumb lands `steps` presses away, for a track whose values aren't what the user counts in. */\n keyStep?(steps: number): number;\n}\n\n/** The value one key moves thumb `index` to: arrows by a step (ten with Shift), the Page keys by ten,\n * Home and End to the thumb's ends. `null` for a key the slider does not answer to. */\nexport function sliderKey(key: string, shift: boolean, shape: SliderKeyShape): number | null {\n const move = rangeKey(key, shift, shape.dir);\n if (move === null) return null;\n const { thumbs, index, min, max, step } = shape;\n const from = thumbs[index]!.value;\n const [bLo, bHi] = shape.bounds?.() ?? [min, max];\n const lo = Math.max(min, bLo);\n const hi = Math.min(max, bHi);\n const stops = shape.stops ?? [];\n let v: number;\n if (move === 'home') v = lo;\n else if (move === 'end') v = hi;\n else if (shape.keyStep) v = shape.keyStep(move);\n else if (stops.length > 0) v = stepStops(stops, from, move > 0 ? 1 : -1, Math.abs(move));\n else {\n const range = shape.range ?? [min, max];\n const stepSize = defaultStep(step, range[0], range[1]);\n const delta = move * stepSize;\n // The step grid starts at the range's start: an endless low end's stop sits off it, at whatever distance it is drawn.\n const crossed = crossEnd(from, delta, stepSize, range, [min, max]);\n if (crossed === null) v = snapToStep(from + delta, step, range[0]);\n // Back into the range from an end stop, a press at a time from the range's end, which may sit off the grid.\n else v = crossed > range[0] && crossed < range[1] ? snapToStep(crossed, step, range[0]) : crossed;\n }\n v = clamp(v, lo, hi);\n return shape.ordered ? clampOrdered(v, thumbs, index, lo, hi, step) : v;\n}\n","import type { TrackMap } from './slider';\n\n/** A stretch of values: a track's whole range, or the part of it a track shows. */\nexport interface Span {\n from: number;\n to: number;\n}\n\n/** Where `v` sits along `span`, as a fraction: 0 at `from`, 1 at `to`, and outside that past either end.\n * 0 for an empty span. */\nexport function spanPlace(span: Span, v: number): number {\n const length = span.to - span.from;\n return length === 0 ? 0 : (v - span.from) / length;\n}\n\n/** The value at fraction `f` of `span`. */\nexport function spanValue(span: Span, f: number): number {\n return span.from + f * (span.to - span.from);\n}\n\n/** A length as a fraction of `span`'s. Unlike {@link spanPlace} it measures no position, so `span.from` has no say. */\nexport function spanShare(span: Span, length: number): number {\n const whole = span.to - span.from;\n return whole === 0 ? 0 : length / whole;\n}\n\n/** `span` laid linearly along a track: the map {@link sliderAt} and {@link attract} read. Unclamped, so a\n * place off either end of the track maps to a value outside the span. */\nexport function spanMap(span: Span): TrackMap {\n return { toFraction: (v) => spanPlace(span, v), toValue: (f) => spanValue(span, f) };\n}\n\n/** `span` moved inside `bounds`, keeping its length, or shortened to `bounds` where it is the longer. */\nexport function spanHold(span: Span, bounds: Span): Span {\n if (span.from >= bounds.from && span.to <= bounds.to) return { from: span.from, to: span.to };\n const length = Math.min(span.to - span.from, bounds.to - bounds.from);\n let from = span.from;\n if (from < bounds.from) from = bounds.from;\n if (from + length > bounds.to) from = Math.max(bounds.from, bounds.to - length);\n return { from, to: Math.min(bounds.to, from + length) };\n}\n\n/** `span` shifted by `by` inside `bounds`, keeping its length. */\nexport function spanPan(span: Span, by: number, bounds: Span): Span {\n return spanHold({ from: span.from + by, to: span.to + by }, bounds);\n}\n\n/** `span` scaled by `factor` about `at`, which keeps its place along the track unless `bounds` push it.\n * A `factor` below 1 narrows. The result is no shorter than `minLength` and no longer than `bounds`. */\nexport function spanZoom(span: Span, at: number, factor: number, bounds: Span, minLength = 0): Span {\n const length = span.to - span.from;\n const next = Math.min(bounds.to - bounds.from, Math.max(minLength, length * factor));\n const f = length === 0 ? 0.5 : (at - span.from) / length;\n return spanHold({ from: at - f * next, to: at + (1 - f) * next }, bounds);\n}\n","/** How a text field's edit ends: `'commit'` writes what was typed, `'cancel'` drops it and puts back what was there. */\nexport type EditEnd = 'commit' | 'cancel';\n\n/** What a field varies in how its edit ends: what Escape does (`'cancel'` by default), and whether the field holds\n * more than one line, which leaves Shift+Enter to type a line break rather than commit. */\nexport interface EditEndShape {\n escape?: EditEnd;\n multiline?: boolean;\n}\n\n/** What may end an edit: a key, with whether Shift is held, or the field losing focus. A key {@link imeKey} claims is\n * the caller's to hold back. */\nexport type EditCause = 'blur' | { key: string; shift?: boolean };\n\n/** How `cause` ends a text field's edit, or null when it leaves the edit open. Enter and blur commit, Escape cancels\n * unless `shape` says otherwise. */\nexport function editEnd(cause: EditCause, shape: EditEndShape = {}): EditEnd | null {\n if (cause === 'blur') return 'commit';\n if (cause.key === 'Enter') return shape.multiline && cause.shift ? null : 'commit';\n if (cause.key === 'Escape') return shape.escape ?? 'cancel';\n return null;\n}\n\n/** A keydown as the platform reports it, enough to tell whether an input method owns it. */\nexport interface KeySource {\n key: string;\n isComposing?: boolean;\n keyCode?: number;\n}\n\n/** Whether a keydown belongs to an input method, which a field must leave alone: Enter there confirms a candidate and\n * Escape dismisses them. Safari sends the Enter that ends a composition with `isComposing` already false, but with\n * `keyCode` 229. */\nexport function imeKey(e: KeySource): boolean {\n return e.isComposing === true || e.keyCode === 229 || e.key === 'Process' || e.key === 'Dead';\n}\n","/**\n * Moving items within an ordered list. A destination is a gap, counted before anything is taken out: 0 before the\n * first item, `length` after the last, and `i` between `items[i - 1]` and `items[i]` — the gap a UI marks while it\n * carries something. The items moved are named by their indices, so a selection of several moves in one go.\n */\n\n/** The whole numbers in `at`, once each, ascending: an index that is not one names no item. */\nconst sortedSet = (at: readonly number[]): number[] => [...new Set(at.filter(Number.isInteger))].sort((a, b) => a - b);\n\n/** `items` with the items at indices `at` taken out and put back, in their order, in gap `to`. An index outside\n * `items`, or not a whole number, names nothing and is ignored; a gap past either end is that end. */\nexport function moveItems<T>(items: readonly T[], at: readonly number[], to: number): T[] {\n const inside = sortedSet(at).filter((i) => i >= 0 && i < items.length);\n const gap = Math.min(items.length, Math.max(0, to));\n const taken = new Set(inside);\n const out = items.filter((_, i) => !taken.has(i));\n out.splice(movedIndex(inside, gap), 0, ...inside.map((i) => items[i]!));\n return out;\n}\n\n/** The index the first of the items at `at` holds once {@link moveItems} has put them in gap `to`. */\nexport function movedIndex(at: readonly number[], to: number): number {\n return to - sortedSet(at).filter((i) => i < to).length;\n}\n\n/** Whether putting the items at `at` in gap `to` leaves them where they are: a contiguous run dropped in a gap at\n * either of its ends or inside it. False for no items. */\nexport function isNoopDrop(at: readonly number[], to: number): boolean {\n const s = sortedSet(at);\n if (s.length === 0) return false;\n const first = s[0]!;\n const last = s[s.length - 1]!;\n return last - first + 1 === s.length && to >= first && to <= last + 1;\n}\n\n/** The gap a one-place move sends the items at `at` to: before the item ahead of the first (`by` -1), or after the\n * item past the last (`by` 1). Null where that runs off either end of a list `length` long, or for no items. */\nexport function nudgeGap(at: readonly number[], by: -1 | 1, length: number): number | null {\n const s = sortedSet(at);\n if (s.length === 0) return null;\n const to = by < 0 ? s[0]! - 1 : s[s.length - 1]! + 2;\n return to < 0 || to > length ? null : to;\n}\n\n/**\n * The gap a point `p` along a line of items falls in, where each item splits at its middle: how many of the\n * middles `mids`, given in item order, `p` has reached. A line whose middles run backward, as a right-to-left row\n * does along x, counts the other way. For items that sit side by side — rows, tabs, chips.\n */\nexport function gapByMidpoint(mids: readonly number[], p: number): number {\n const backward = mids.length > 1 && mids[mids.length - 1]! < mids[0]!;\n return mids.filter((m) => (backward ? m >= p : m <= p)).length;\n}\n\n/** Which of the gaps at positions `gaps` along a line is nearest `p`, as an index into `gaps`; -1 for none. For\n * gaps drawn at places of their own, between items set apart however the layout put them: picking the nearest\n * keeps the gap chosen the one whose mark is drawn closest. */\nexport function nearestGap(gaps: readonly number[], p: number): number {\n let best = -1;\n for (let k = 0; k < gaps.length; k++) if (best < 0 || Math.abs(gaps[k]! - p) < Math.abs(gaps[best]! - p)) best = k;\n return best;\n}\n\n/**\n * Which part of an item a pointer at fraction `f` along it is over: the leading `band` of it drops before, the\n * trailing `band` after, and what lies between drops into it. The default `band` of a half leaves no middle, which\n * is an item that cannot take a drop into it, split at its midpoint.\n */\nexport function dropBand(f: number, band = 0.5): 'before' | 'into' | 'after' {\n if (f < band) return 'before';\n return f >= 1 - band ? 'after' : 'into';\n}\n\n/** The keys and modifiers a nudge chord reads off a keystroke. */\nexport interface NudgeKey {\n key: string;\n altKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n}\n\n/** Alt with neither Ctrl nor Cmd held: the chord that moves an item instead of moving focus. */\nexport function isNudgeChord(e: NudgeKey): boolean {\n return e.altKey && !e.ctrlKey && !e.metaKey;\n}\n\n/** Which way the nudge chord moves an item: `-1` for Alt+`back`, `1` for Alt+`on`, `null` for any other key.\n * The keys are Up and Down unless named. */\nexport function nudgeOf(e: NudgeKey, back = 'ArrowUp', on = 'ArrowDown'): -1 | 1 | null {\n if (!isNudgeChord(e)) return null;\n if (e.key === back) return -1;\n return e.key === on ? 1 : null;\n}\n","import type { Box } from './scalar';\nimport type { Span } from './span';\n\n/** How near an edge a dragged pointer starts a scroll, in px, unless a caller says otherwise. */\nexport const EDGE_SCROLL_MARGIN = 48;\n\n/**\n * How hard a pointer at `p` pushes `span` to scroll, from -1 toward `from` to 1 toward `to`: 0 while `p` is\n * `margin` or more inside both ends, rising linearly to full strength at an end and holding it past there, so\n * overshooting does not reverse the scroll. A span narrower than two margins scrolls toward the nearer end.\n */\nexport function edgePush(span: Span, p: number, margin: number = EDGE_SCROLL_MARGIN): number {\n if (!(margin > 0)) return 0;\n const fromStart = p - span.from;\n const fromEnd = span.to - p;\n const towardStart = fromStart <= fromEnd;\n const distance = towardStart ? fromStart : fromEnd;\n if (distance >= margin) return 0;\n const strength = Math.min(1, 1 - distance / margin);\n return towardStart ? -strength : strength;\n}\n\n/** {@link edgePush} on both axes of a scrolling box: multiply by a top speed for how far to scroll. */\nexport function edgeScroll(\n bounds: Box, point: { x: number; y: number }, margin: number = EDGE_SCROLL_MARGIN,\n): { x: number; y: number } {\n return {\n x: edgePush({ from: bounds.x, to: bounds.x + bounds.width }, point.x, margin),\n y: edgePush({ from: bounds.y, to: bounds.y + bounds.height }, point.y, margin),\n };\n}\n","import type { Box } from './scalar';\n\n/** A way to move across a surface, in its own x and y: y grows downward. */\nexport type Heading = 'left' | 'right' | 'up' | 'down';\n\n/** How much a unit of drift across a heading costs against a unit of travel along it. */\nexport const HEADING_DRIFT = 2;\n\n/** The heading an arrow key asks for, or null for any other key. */\nexport function headingOf(key: string): Heading | null {\n if (key === 'ArrowLeft') return 'left';\n if (key === 'ArrowRight') return 'right';\n if (key === 'ArrowUp') return 'up';\n return key === 'ArrowDown' ? 'down' : null;\n}\n\n/**\n * What it costs to go from `from` to `to` on `heading`, center to center: the travel along the heading plus\n * `drift` times the distance across it, so a target straight ahead beats a nearer one off to the side. Null for\n * a target that is not ahead at all.\n */\nexport function headingCost(from: Box, to: Box, heading: Heading, drift: number = HEADING_DRIFT): number | null {\n const dx = to.x + to.width / 2 - (from.x + from.width / 2);\n const dy = to.y + to.height / 2 - (from.y + from.height / 2);\n const across = heading === 'left' || heading === 'right';\n const along = across ? dx : dy;\n const ahead = heading === 'left' || heading === 'up' ? -along : along;\n if (!(ahead > 0)) return null;\n return ahead + drift * Math.abs(across ? dy : dx);\n}\n\n/** Which of `targets` focus moves to from `from` on `heading`: the index of the cheapest by {@link headingCost},\n * the earlier of two that tie, or -1 when none is ahead. A target with no box is passed over. */\nexport function nearestToward(\n from: Box, targets: readonly (Box | null | undefined)[], heading: Heading, drift: number = HEADING_DRIFT,\n): number {\n let best = -1;\n let bestCost = Infinity;\n targets.forEach((to, i) => {\n const cost = to ? headingCost(from, to, heading, drift) : null;\n if (cost !== null && cost < bestCost) {\n best = i;\n bestCost = cost;\n }\n });\n return best;\n}\n","/** Clock and timer, injected so tests and hosts control time. */\nexport interface Scheduler {\n now(): number;\n /** Run `fn` after `ms`; returns a cancel. */\n set(fn: () => void, ms: number): () => void;\n}\n\n/** The real-time scheduler: `Date.now` and `setTimeout`. */\nexport const timerScheduler: Scheduler = {\n now: () => Date.now(),\n set: (fn, ms) => {\n const t = setTimeout(fn, ms);\n return () => clearTimeout(t);\n },\n};\n","import { timerScheduler, type Scheduler } from './scheduler';\n\n/** How long a held stepper waits before it repeats, in milliseconds. */\nexport const REPEAT_DELAY_MS = 400;\n/** How often a held stepper steps once it repeats, in milliseconds. */\nexport const REPEAT_EVERY_MS = 60;\n\n/** The timing of a {@link createStepRepeat}. Each is read when it is next used, so a getter can change it mid-hold. */\nexport interface StepRepeatOptions {\n /** Default {@link REPEAT_DELAY_MS}. */\n delayMs?: number;\n /** Default {@link REPEAT_EVERY_MS}. */\n everyMs?: number;\n /** Default {@link timerScheduler}. */\n scheduler?: Pick<Scheduler, 'set'>;\n}\n\n/** A held stepper: {@link createStepRepeat}. */\nexport interface StepRepeat<K> {\n /** Step `key` once now, then after the delay once every interval until {@link stop}. Replaces any hold. */\n start(key: K): void;\n stop(): void;\n /** The key being held, or null. */\n held(): K | null;\n}\n\n/**\n * Hold-to-repeat stepping, whatever draws the stepper: `step` moves the value by `key`, and `spent` says `key`\n * has nowhere left to go, which ends the hold. Both are called at the moment of each step.\n */\nexport function createStepRepeat<K>(\n step: (key: K) => void, spent: (key: K) => boolean, opts: StepRepeatOptions = {},\n): StepRepeat<K> {\n let cancel: (() => void) | null = null;\n let key: K | null = null;\n let hold = 0;\n const stop = () => {\n cancel?.();\n cancel = null;\n key = null;\n hold++;\n };\n /** Step `k`, then wait `ms` for the next one, unless `step` ended or replaced this hold. */\n const stepThenWait = (k: K, ms: number) => {\n const mine = hold;\n step(k);\n if (hold !== mine) return;\n cancel = (opts.scheduler ?? timerScheduler).set(() => {\n // A stepper at its bound may be disabled while still held, and never hear the release that ends the hold.\n if (spent(k)) return stop();\n stepThenWait(k, opts.everyMs ?? REPEAT_EVERY_MS);\n }, ms);\n };\n return {\n start(k) {\n stop();\n key = k;\n stepThenWait(k, opts.delayMs ?? REPEAT_DELAY_MS);\n },\n stop,\n held: () => key,\n };\n}\n","/**\n * A parameter's domain, apart from how it is walked. A scrubber reads it\n * continuously, one value at a time (`at`); a stepped sequence reads every\n * step at once (`walk`). Time is one domain among others (`frames`).\n */\nexport interface Sweep<V> {\n /** The value `u` of the way along, 0 to 1, clamped: a scrubber's reading. A\n * domain of discrete steps answers its nearest step. */\n at(u: number): V;\n /** Every step in order: a sequence's reading. May never end; `stepsOf` caps it. */\n walk(): Iterable<V>;\n /** How a value reads in a caption or a readout. */\n label(value: V): string;\n}\n\n/** How many steps `stepsOf` takes from a sweep that has not ended by then. */\nexport const SWEEP_CAP = 256;\n\n/** The first `cap` steps of `sweep`, and whether it had more. `cap` is a whole number, 0 or more. */\nexport function stepsOf<V>(sweep: Sweep<V>, cap = SWEEP_CAP): { steps: V[]; capped: boolean } {\n if (!(Number.isInteger(cap) && cap >= 0)) throw new RangeError(`a cap is a whole number of steps, not ${cap}`);\n const steps: V[] = [];\n for (const value of sweep.walk()) {\n if (steps.length === cap) return { steps, capped: true };\n steps.push(value);\n }\n return { steps, capped: false };\n}\n\nconst clamp01 = (u: number): number => (u <= 0 ? 0 : u >= 1 ? 1 : u);\n\n/** `n` to twelve digits, as a label shows it. */\nconst shown = (n: number): number => +n.toPrecision(12);\n\n/** Sums of a float step drift (0.1 * 3 is 0.30000000000000004): `n` to twelve digits where that is within such\n * drift of it, measured against `scale`, the largest operand `n` was summed from; otherwise `n`, whose digits\n * past the twelfth are its own. */\nconst tidy = (n: number, scale = 0): number => {\n const t = shown(n);\n return Math.abs(t - n) <= 2 * Number.EPSILON * Math.max(Math.abs(n), Math.abs(scale)) ? t : n;\n};\n\nconst plain = (n: number): string => String(shown(n));\n\n/** What {@link range} walks: its ends, and either a `step` or a `count`. */\nexport type RangeSpec = {\n from: number;\n /** May be `Infinity`, for a walk that only `until` or a cap ends. */\n to: number;\n label?: (value: number) => string;\n} & ({ step: number; count?: never } | { count: number; step?: never });\n\n/**\n * Numbers from `from` to `to`, either `step` apart (the last step at or before\n * `to`) or `count` of them evenly spaced, both ends included. With `step`, `at`\n * snaps to a step; with `count` it is continuous, as the steps are only samples.\n */\nexport function range(spec: RangeSpec): Sweep<number> {\n const { from, to } = spec;\n if (!Number.isFinite(from) || Number.isNaN(to)) throw new RangeError(`a range runs from a finite number to a number, not ${from} to ${to}`);\n const span = to - from;\n if (spec.step !== undefined) {\n const step = spec.step;\n if (!(step > 0)) throw new RangeError(`a range's step is above 0, not ${step}`);\n const last = Number.isFinite(span) ? Math.floor(tidy(Math.abs(span) / step)) : Infinity;\n const dir = span < 0 ? -1 : 1;\n const nth = (i: number): number => (i === 0 ? from : tidy(from + dir * step * i, Math.max(Math.abs(from), step * i)));\n return {\n at: (u) => {\n if (!Number.isFinite(last)) throw new RangeError('an endless range has no point a fraction of the way along');\n return nth(Math.round(clamp01(u) * last));\n },\n *walk() {\n for (let i = 0; i <= last; i++) yield nth(i);\n },\n label: spec.label ?? plain,\n };\n }\n const count = spec.count;\n if (!(Number.isInteger(count) && count > 0)) throw new RangeError(`a range's count is a whole number above 0, not ${count}`);\n if (!Number.isFinite(span)) throw new RangeError('a range given a count needs a finite end');\n const scale = Math.max(Math.abs(from), Math.abs(to));\n const [lo, hi] = from <= to ? [from, to] : [to, from];\n const along = (u: number): number => (u <= 0 ? from : u >= 1 ? to : Math.min(hi, Math.max(lo, tidy(from + span * u, scale))));\n return {\n at: (u) => along(clamp01(u)),\n *walk() {\n if (count === 1) yield from;\n else for (let i = 0; i < count; i++) yield i === 0 ? from : i === count - 1 ? to : tidy(from + (span * i) / (count - 1), scale);\n },\n label: spec.label ?? plain,\n };\n}\n\n/** The values of a list, in its order; `at` snaps to the nearest. */\nexport function values<V>(list: readonly V[], label: (value: V) => string = String): Sweep<V> {\n if (list.length === 0) throw new RangeError('a sweep over values needs at least one');\n return {\n at: (u) => list[Math.round(clamp01(u) * (list.length - 1))]!,\n walk: () => list,\n label,\n };\n}\n\n/** What `frames` reads of a clock's declaration; a `ClockSpec` is one. */\nexport interface FrameSpan {\n /** ms per pass; omitted, the run never ends. */\n duration?: number;\n /** Passes: `true` endless, `false` one, `n` that many. */\n loop?: boolean | number;\n /** The time elapsed 0 is shown as, for the labels. */\n origin?: number;\n}\n\n/** How {@link frames} walks a clock's run. */\nexport interface FrameOptions {\n /** ms between frames. */\n every: number;\n /** `'first'`, the default, walks one pass; `'all'` walks the whole run, which\n * for an endless loop never ends. */\n passes?: 'first' | 'all';\n label?: (elapsed: number) => string;\n}\n\nconst ms = (t: number): string => `${shown(t)} ms`;\n\n/**\n * The frames of a clock's run, as elapsed ms, `every` apart from 0. A run that\n * ends shows its last frame; a pass that loops back stops short of its end,\n * which is the next pass's start. `at` is continuous over the span walked.\n */\nexport function frames(span: FrameSpan, options: FrameOptions): Sweep<number> {\n const { every } = options;\n if (!(every > 0)) throw new RangeError(`frames are a time above 0 apart, not ${every}`);\n const duration = span.duration ?? Infinity;\n if (!(duration >= 0)) throw new RangeError(`a run lasts 0 ms or more, not ${duration}`);\n const loop = span.loop ?? false;\n if (typeof loop === 'number' && !(loop >= 0)) throw new RangeError(`a run loops 0 times or more, not ${loop}`);\n const passes = loop === true ? Infinity : loop === false ? 1 : loop;\n const walked = options.passes === 'all' ? passes : 1;\n // No length times no end is no length, where the product is NaN.\n const end = duration === 0 || walked === 0 ? 0 : duration * walked;\n // The end is a frame only where nothing follows it: the run's end, not a pass's.\n const ends = walked === passes && Number.isFinite(passes) && Number.isFinite(end);\n const origin = span.origin ?? 0;\n const label = options.label ?? ((t: number) => ms(origin + t));\n return {\n at: (u) => {\n if (!Number.isFinite(end)) throw new RangeError('an endless run has no point a fraction of the way along');\n return end * clamp01(u);\n },\n *walk() {\n for (let i = 0; ; i++) {\n const t = tidy(every * i);\n if (t > end || (t === end && !ends)) break;\n yield t;\n if (t === end) return;\n }\n // The loop yields the end only when a frame lands on it, so a run that ends shows it here.\n if (ends) yield end;\n },\n label,\n };\n}\n\n/** `sweep` walked only as far as the step before the first one `done` accepts:\n * \"every frame until it repeats\". `at` is the inner sweep's. */\nexport function until<V>(sweep: Sweep<V>, done: (value: V, index: number) => boolean): Sweep<V> {\n return {\n at: sweep.at,\n *walk() {\n let i = 0;\n for (const value of sweep.walk()) {\n if (done(value, i++)) return;\n yield value;\n }\n },\n label: sweep.label,\n };\n}\n","/**\n * Grids: a run of same-size items laid out `columns` across, in reading order,\n * with a short last row at its start, centered, at its end, or stretched across\n * the row. {@link tileGrid} says where each item sits and which of the grid's\n * outer corners it is on; {@link rovingGridTarget} walks it with the arrows,\n * so the two read one layout.\n */\nimport { rovingKey } from './list';\n\n/** Where a last row shorter than the rest sits: at the start, centered, at the end, or with its items stretched\n * across the whole row. */\nexport type LastRow = 'start' | 'center' | 'end' | 'fill';\n\n/** How a run of items tiles. */\nexport interface Tiling {\n /** Items per row: a whole number, one for anything below one, and at most 2^24. */\n columns: number;\n /** Where a last row shorter than `columns` sits. Default `'start'`. */\n lastRow?: LastRow;\n}\n\n/** How far in, in columns, a row of `length` items sits in a grid `columns` across, aligned `align`. A\n * stretched (`'fill'`) row starts at the start. */\nexport function rowOffset(length: number, columns: number, align: LastRow = 'start'): number {\n const gap = Math.max(0, columns - length);\n return align === 'center' ? gap / 2 : align === 'end' ? gap : 0;\n}\n\n/** Where a tiling's items sit on its tracks. */\nexport interface TileGrid {\n /** Tracks across: twice `columns`, so a short row can sit a half column in, or enough for both a full row and a\n * stretched one to divide evenly. */\n tracks: number;\n /** Tracks a full row's item spans. */\n span: number;\n /** Tracks a stretched last row's item spans. */\n fillSpan: number;\n /** How far an offset last row sits from the start, in tracks; 0 for one at the start, stretched, or none. */\n lead: number;\n /** Index of the last row's first item. */\n lastStart: number;\n /** Whether item `i` is in a stretched last row. */\n stretched(i: number): boolean;\n /** The grid's outer corners item `i` sits on: `ss` top-left, `se` top-right, `es` bottom-left, `ee` bottom-right,\n * in the inline direction. */\n corners(i: number): ('ss' | 'se' | 'es' | 'ee')[];\n}\n\nconst gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));\n\n/** The most columns a grid lays out: past it the tracks a stretched row needs stop being whole numbers. */\nconst MAX_COLUMNS = 2 ** 24;\n\n/** A column count as a grid can lay out: its whole part, one for anything below one or not a number, and\n * {@link MAX_COLUMNS} for anything past it, `Infinity` included. */\nconst wholeColumns = (columns: number): number => (columns >= 1 ? Math.min(Math.floor(columns), MAX_COLUMNS) : 1);\n\n/** How `count` items tile under `spec`. */\nexport function tileGrid(count: number, spec: Tiling): TileGrid {\n const columns = wholeColumns(spec.columns);\n const lastRow = spec.lastRow ?? 'start';\n const short = count % columns;\n const lastStart = count - (short || columns);\n const filling = lastRow === 'fill' && short > 0;\n const tracks = filling ? (columns * short) / gcd(columns, short) : 2 * columns;\n const span = tracks / columns;\n const lead = short === 0 || lastRow === 'fill' ? 0 : span * rowOffset(short, columns, lastRow);\n // The last item reaches the end of its row when the row is full, stretched or end-aligned.\n const lastAtEnd = short === 0 || lastRow === 'fill' || lastRow === 'end';\n return {\n tracks,\n span,\n fillSpan: filling ? tracks / short : span,\n lead,\n lastStart,\n stretched: (i) => filling && i >= lastStart,\n corners: (i) => {\n const at: ('ss' | 'se' | 'es' | 'ee')[] = [];\n // A grid of one short row has that row's offset and end at its top as well.\n const single = count < columns;\n if (i === 0 && (lead === 0 || !single)) at.push('ss');\n if (i === Math.min(columns, count) - 1 && (lastAtEnd || !single)) at.push('se');\n if (i === lastStart && lead === 0) at.push('es');\n if (i === count - 1 && lastAtEnd) at.push('ee');\n return at;\n },\n };\n}\n\n/** How a grid's rows sit for {@link rovingGridTarget}. */\nexport interface GridLayout {\n dir?: 'ltr' | 'rtl';\n /** How many columns in each row's first item sits, by row: a short row centered in an even gap sits a half\n * column in. Omitted rows start at column 0. */\n offsets?: readonly number[];\n /** How many columns wide each row's items are, by row: a stretched last row's are wider than one. Omitted\n * rows' items are one column wide. */\n widths?: readonly number[];\n}\n\n/** The rows of `count` items `columns` across, as item indices in reading order. */\nexport function tileRows(count: number, across: number): number[][] {\n const columns = wholeColumns(across);\n return Array.from({ length: Math.ceil(count / columns) }, (_, r) =>\n Array.from({ length: Math.min(columns, count - r * columns) }, (_, j) => r * columns + j));\n}\n\n/** Where `key` takes focus from `current` among `count` items tiled by `spec`, by {@link rovingGridTarget}: null\n * if it does not move it. Every item is enabled unless `enabled` says otherwise. */\nexport function tileKey(\n current: number,\n key: string,\n count: number,\n spec: Tiling,\n opts: { dir?: 'ltr' | 'rtl'; enabled?: readonly boolean[] } = {},\n): number | null {\n const rows = tileRows(count, spec.columns);\n const enabled = opts.enabled ?? Array<boolean>(count).fill(true);\n return rovingGridTarget(current, key, enabled, rows, { dir: opts.dir, ...gridLayout(rows, spec.columns, spec.lastRow) });\n}\n\n/** The layout of `rows` in a grid `columns` across whose short rows sit as `lastRow` says. */\nexport function gridLayout(rows: readonly (readonly number[])[], across: number, lastRow: LastRow = 'start'): GridLayout {\n const columns = wholeColumns(across);\n const short = (row: readonly number[]): boolean => row.length < columns;\n return {\n offsets: rows.map((row) => (short(row) ? rowOffset(row.length, columns, lastRow) : 0)),\n widths: rows.map((row) => (short(row) && lastRow === 'fill' ? columns / row.length : 1)),\n };\n}\n\n/** Where one row sits: how far in its first item starts and how wide each item is, in columns. */\ninterface RowSpan { offset: number; width: number }\n\n/** Which item of `row`, laid out as `at`, sits under the column span `lo`–`hi`: the one covering most of it,\n * and of two covering it equally the later going down and the earlier going up, so Down then Up comes back.\n * Under none, the nearest end. */\nfunction itemUnder(row: readonly number[], at: RowSpan, lo: number, hi: number, down: boolean): number | undefined {\n let best = -1;\n let most = 0;\n for (let j = 0; j < row.length; j++) {\n const start = at.offset + j * at.width;\n const cover = Math.min(hi, start + at.width) - Math.max(lo, start);\n if (cover > most + 1e-9 || (down && cover > 0 && Math.abs(cover - most) <= 1e-9)) {\n best = j;\n most = cover;\n }\n }\n if (best >= 0) return row[best];\n const nearest = Math.round(((lo + hi) / 2 - at.offset) / at.width - 0.5);\n return row[Math.min(row.length - 1, Math.max(0, nearest))];\n}\n\nconst isStop = (enabled: boolean): boolean => enabled;\n\n/** Where `key` takes focus from `current` in a grid whose `rows` list item indices in reading order, or null if\n * it does not move it. Left and Right step through the enabled items in reading order (swapped under `'rtl'`),\n * wrapping, and Home and End go to the first and last. Up and Down move to the item under this one in the next\n * row, by where each row sits, or to that row's nearest end when none is under it; they pass over rows where that\n * item is disabled, and stop at the first and last rows. */\nexport function rovingGridTarget(\n current: number,\n key: string,\n enabled: readonly boolean[],\n rows: readonly (readonly number[])[],\n layout: GridLayout = {},\n): number | null {\n const step = key === 'ArrowDown' ? 1 : key === 'ArrowUp' ? -1 : 0;\n if (step === 0) {\n const moved = rovingKey(enabled, current, key, { canStop: isStop, orientation: 'horizontal', dir: layout.dir });\n return moved.handled ? moved.at : null;\n }\n const r = rows.findIndex((row) => row.includes(current));\n if (r < 0) return null;\n const at = (row: number): RowSpan => ({ offset: layout.offsets?.[row] ?? 0, width: layout.widths?.[row] ?? 1 });\n const here = at(r);\n const lo = here.offset + rows[r]!.indexOf(current) * here.width;\n for (let rr = r + step; rr >= 0 && rr < rows.length; rr += step) {\n const i = itemUnder(rows[rr]!, at(rr), lo, lo + here.width, step > 0);\n if (i !== undefined && enabled[i]) return i;\n }\n return null;\n}\n","/**\n * Selection: which of a run of items are on. One spec answers what each item\n * shows, what a click on it does, what the arrow keys do, and how a sweep\n * sets several at once, so a component taking it cannot get one of them\n * wrong. Build a model with {@link selection} (one value, or a list of them)\n * or {@link selectionOfEach} (items that each own a boolean); {@link selectionKeys}\n * says what the keyboard does with it.\n */\n\n/** An item's state: on, off, or mixed, where the sources it aggregates disagree. */\nexport type SelectState = 'off' | 'on' | 'mixed';\n\n/** At most one item on, held as its value or `null`. */\nexport interface SingleSelection<V> {\n mode?: 'single';\n value: V | null;\n onChange: (next: V | null) => void;\n /** A click on the item that is on turns it off. Default false. */\n allowDeselect?: boolean;\n /** Values drawn mixed, where `value` holds none of them. A click on one chooses it. */\n mixedValues?: readonly V[];\n /** The arrow keys choose the item they land on, as a radio group's do. Default true; false moves focus only,\n * and Space or Enter chooses. */\n followsFocus?: boolean;\n}\n\n/** Any number of items on, held as a list of their values. */\nexport interface MultipleSelection<V> {\n mode: 'multiple';\n value: readonly V[];\n onChange: (next: V[]) => void;\n /**\n * Values that are neither on nor off: the sources this aggregates disagree (a text range bold in part of it, a\n * multi-selection whose nodes differ). `value` wins where the two lists overlap. A click on one turns it on.\n */\n mixedValues?: readonly V[];\n}\n\n/** One spec for a run of items whose selection is one value or a list of them. */\nexport type SelectionSpec<V> = SingleSelection<V> | MultipleSelection<V>;\n\n/** One item that owns its own on/off state. */\nexport interface OwnSelection {\n selected: boolean;\n onChange: (next: boolean) => void;\n}\n\n/** A run of changes to a selection, each from where the last left it: a sweep's. */\nexport interface SelectionEdit {\n /** Set item `index` on or off. */\n set(index: number, on: boolean): void;\n /** Put back what the edit started from. */\n revert(): void;\n}\n\n/** A selection over items by index. */\nexport interface SelectionModel {\n /** At most one item on, or any number. */\n readonly mode: 'single' | 'multiple';\n stateOf(index: number): SelectState;\n /** What a click on item `index` does: choose it, or flip it. */\n press(index: number): void;\n /** Start a run of changes. Each `set` reports as it happens, from the edit's own copy, so a run faster than\n * the component re-renders loses none of them. */\n edit(): SelectionEdit;\n /** The arrow keys choose as they move. */\n readonly followsFocus: boolean;\n}\n\n/** Whether `a` and `b` are one value as `Array.prototype.includes` reads them: `NaN` is itself, `-0` is `0`. */\nconst same = (a: unknown, b: unknown): boolean => a === b || (Number.isNaN(a) && Number.isNaN(b));\n\n/** `spec`'s selection over `values`, one per item in order. */\nexport function selection<V>(spec: SelectionSpec<V>, values: readonly V[]): SelectionModel {\n const mixed = spec.mixedValues ?? [];\n if (spec.mode === 'multiple') {\n const on = spec.value;\n const flip = (list: readonly V[], v: V, to: boolean): V[] => (to ? [...list, v] : list.filter((w) => !same(w, v)));\n return {\n mode: 'multiple',\n followsFocus: false,\n stateOf: (i) => (on.includes(values[i]!) ? 'on' : mixed.includes(values[i]!) ? 'mixed' : 'off'),\n press: (i) => spec.onChange(flip(on, values[i]!, !on.includes(values[i]!))),\n edit: () => {\n const initial = on;\n let working: readonly V[] = initial;\n return {\n set: (i, to) => {\n const v = values[i]!;\n if (working.includes(v) === to) return;\n const next = flip(working, v, to);\n working = next;\n spec.onChange(next);\n },\n revert: () => { if (working !== initial) spec.onChange([...initial]); },\n };\n },\n };\n }\n const choose = (next: V | null): void => spec.onChange(next);\n return {\n mode: 'single',\n followsFocus: spec.followsFocus ?? true,\n stateOf: (i) => (same(spec.value, values[i]) ? 'on' : mixed.includes(values[i]!) ? 'mixed' : 'off'),\n press: (i) => {\n if (!same(spec.value, values[i])) choose(values[i]!);\n else if (spec.allowDeselect) choose(null);\n },\n edit: () => {\n const initial = spec.value;\n let working = initial;\n return {\n set: (i, to) => {\n const next = to ? values[i]! : same(working, values[i]) && spec.allowDeselect ? null : working;\n if (same(next, working)) return;\n working = next;\n choose(next);\n },\n revert: () => { if (!same(working, initial)) choose(initial); },\n };\n },\n };\n}\n\n/** The selection of items that each own their state: any number on, and nothing mixed. */\nexport function selectionOfEach(items: readonly OwnSelection[]): SelectionModel {\n return {\n mode: 'multiple',\n followsFocus: false,\n stateOf: (i) => (items[i]!.selected ? 'on' : 'off'),\n press: (i) => items[i]!.onChange(!items[i]!.selected),\n edit: () => {\n const initial = items.map((it) => it.selected);\n const working = [...initial];\n return {\n set: (i, to) => {\n if (working[i] === to) return;\n working[i] = to;\n items[i]!.onChange(to);\n },\n revert: () => {\n working.forEach((to, i) => {\n if (to === initial[i]) return;\n working[i] = initial[i]!;\n items[i]!.onChange(initial[i]!);\n });\n },\n };\n },\n };\n}\n\n/** A sweep over `model` from a press on item `from`: each item it `reach`es is set to the opposite of whether the\n * pressed one was on, so a drag from an off or mixed item turns on everything it crosses and one from an on item\n * turns it off. `revert` puts back what the sweep started from. */\nexport function sweepFrom(model: SelectionModel, from: number): { reach(index: number): void; revert(): void } {\n const to = model.stateOf(from) !== 'on';\n const edit = model.edit();\n return { reach: (i) => edit.set(i, to), revert: () => edit.revert() };\n}\n\n/** What the keyboard does with `model`'s items. Where a single selection follows focus, the tab stop sits on the\n * chosen item and an arrow landing on one chooses it; otherwise the arrows only move focus, and Space or Enter\n * presses. `enabled(i)` is false for an item nothing may choose. */\nexport function selectionKeys(\n model: SelectionModel,\n count: number,\n enabled: (index: number) => boolean = () => true,\n): { tabStop?: number; landed?: (index: number) => void; activate?: (index: number) => void } {\n if (model.mode === 'single' && model.followsFocus) {\n let chosen = -1;\n for (let i = 0; i < count && chosen < 0; i++) if (model.stateOf(i) === 'on') chosen = i;\n return { tabStop: chosen >= 0 ? chosen : undefined, landed: (i) => { if (enabled(i)) model.edit().set(i, true); } };\n }\n return { activate: (i) => { if (enabled(i)) model.press(i); } };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@weasel-js/ui-input",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.18.2",
4
+ "description": "What a key or a pointer does to a control, as pure functions: arrow steps, sliders and windowed tracks, list and grid roving, typeahead, selection, reorder and drop gaps, edge scroll, directional focus. No React, no DOM.",
5
+ "weasel": {
6
+ "tier": "base"
7
+ },
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "main": "./dist/index.js",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "author": "orochi235",
22
+ "homepage": "https://orochi235.github.io/weasel/",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/orochi235/weasel.git",
26
+ "directory": "packages/ui-input"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/orochi235/weasel/issues"
30
+ },
31
+ "engines": {
32
+ "node": ">=24"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "scripts": {
40
+ "build": "tsup"
41
+ },
42
+ "dependencies": {
43
+ "@weasel-js/quantity": "1.18.2"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ }
49
+ }