@tremolo-ui/dom 0.7.0 → 0.8.0

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ValueRange } from "@tremolo-ui/functions";
1
+ import { Scale, ValueRange } from "@tremolo-ui/functions";
2
2
  //#region src/canvas/animation.d.ts
3
3
  /** What the canvas looked like when a frame was drawn. */
4
4
  interface AnimationFrame {
@@ -143,6 +143,14 @@ interface AcceptCandidate {
143
143
  * there by the time the file is dropped, which is when the answer counts.
144
144
  */
145
145
  export declare function matchesAccept(candidate: AcceptCandidate, accept?: string): boolean;
146
+ /**
147
+ * Split files into those that satisfy `accept` and those that do not, keeping
148
+ * their order. See {@link matchesAccept}.
149
+ */
150
+ export declare function partitionByAccept(files: Iterable<File>, accept?: string): {
151
+ accepted: File[];
152
+ rejected: File[];
153
+ };
146
154
  //#endregion
147
155
  //#region src/file/drop-zone.d.ts
148
156
  /** What is in the air over the element. */
@@ -184,7 +192,8 @@ interface DropZoneOptions {
184
192
  onDrop?: (files: File[], event: DragEvent) => void;
185
193
  /**
186
194
  * Called with the dropped files that do not match `accept`, so that the
187
- * reason can be shown.
195
+ * reason can be shown. It comes after `onDrop` for the same drop, so a list
196
+ * of rejected files can be cleared in `onDrop` and filled here.
188
197
  */
189
198
  onReject?: (files: File[], event: DragEvent) => void;
190
199
  /** Called whenever {@link DropZoneInstance.state} would change. */
@@ -295,6 +304,194 @@ export declare function mapModifier<T extends ModifierSetting, U extends Modifie
295
304
  */
296
305
  export declare function applyDelta(value: number, direction: number, options: ModifierValue<InputEventOption>, { min, max, step, scale }: ValueRange, modifiers?: ModifierState): number;
297
306
  //#endregion
307
+ //#region src/input/check-steps.d.ts
308
+ interface CheckStepsOptions {
309
+ /** The component, for the message. */
310
+ component: string;
311
+ /** The axis, for a component that has more than one. */
312
+ axis?: string;
313
+ /**
314
+ * The range to probe, or `null` to check nothing. An unbounded input has no
315
+ * travel to sample, so `NumberInput` passes `null` when `min` and `max` are
316
+ * not both there.
317
+ */
318
+ range: ValueRange | null;
319
+ keyboard?: ModifierValue<InputEventOption> | null;
320
+ wheel?: ModifierValue<InputEventOption> | null;
321
+ /**
322
+ * How the value is displayed, where the component shows one. Called with
323
+ * probe values only.
324
+ */
325
+ format?: (value: number) => string;
326
+ }
327
+ /**
328
+ * The warnings to show when a key press or a wheel notch cannot produce a
329
+ * change the user can see. Empty when there is nothing to say.
330
+ *
331
+ * Two settings that are each fine on their own can cancel out, and nothing
332
+ * fails when they do — the control simply sits there:
333
+ *
334
+ * - **`step` coarser than the amount.** `keyboard={['raw', 0.1]}` with
335
+ * `step={1}` rounds every press straight back to where it started
336
+ * - **the display coarser than the amount.** A `format` showing two decimals
337
+ * of a kHz value cannot show a press worth 1 Hz
338
+ *
339
+ * The second is only reported when the press is invisible at *every* point
340
+ * along the travel. A display that rounds is a deliberate choice and is
341
+ * normally right — it is being too coarse everywhere that makes it a mistake.
342
+ *
343
+ * **Meant for development builds only.** It probes the whole travel, so call
344
+ * it behind an inline `process.env.NODE_ENV` check: the bundler then drops
345
+ * the call, and this function and its messages with it.
346
+ */
347
+ export declare function checkSteps({ component, axis, range, keyboard, wheel, format }: CheckStepsOptions): string[];
348
+ //#endregion
349
+ //#region src/input/defaults.d.ts
350
+ /**
351
+ * The keyboard amount used by Knob, NumberInput, Slider, and XYPad by default:
352
+ * 1 per press in the units of the value, and 0.1 with shift held. That is one
353
+ * `step` only while `step` is 1; a coarser `step` rounds 1 straight back, which
354
+ * `checkSteps` warns about.
355
+ *
356
+ * A modifier entry is not snapped to `step`, which is what lets the finer
357
+ * amount move at all — see `applyDelta`.
358
+ */
359
+ export declare const DEFAULT_KEYBOARD_OPTIONS: ModifierValue<InputEventOption>;
360
+ /**
361
+ * The wheel amount used by Knob, NumberInput, Slider, and XYPad by default.
362
+ *
363
+ * Browsers turn shift+wheel into horizontal scrolling, which empties `deltaY`
364
+ * and fills `deltaX`, so no modifier is bound here.
365
+ */
366
+ export declare const DEFAULT_WHEEL_OPTIONS: ModifierValue<InputEventOption>;
367
+ /**
368
+ * The drag sensitivity used by value controls by default. Shift makes the
369
+ * same movement cover a tenth of the range, matching the arrow keys.
370
+ */
371
+ export declare const DEFAULT_DRAG_SENSITIVITY: ModifierValue<number>;
372
+ //#endregion
373
+ //#region src/input/direction.d.ts
374
+ /**
375
+ * Which way an input moves a value, before any amount is applied.
376
+ *
377
+ * `applyDelta` takes the direction as given, since which key or which sign of
378
+ * `deltaY` counts as "up" differs per control. The answers are collected here
379
+ * so that every wrapper gives the same one: a knob that turns the other way
380
+ * in one framework would be a bug nobody could see from the code.
381
+ *
382
+ * Two families, by what the control looks like:
383
+ *
384
+ * - **one value** (`Knob`, `Slider`, `NumberInput`): right and up raise it
385
+ * - **a position on screen** (`XYPad`, `PointsEditor`): in screen coordinates,
386
+ * x growing rightwards and y growing downwards, plus which axis moves
387
+ *
388
+ * A control that runs the other way (`reverse`) flips the result itself.
389
+ */
390
+ /** One of the four arrow keys, as `KeyboardEvent.key` names it. */
391
+ type ArrowKey = 'ArrowRight' | 'ArrowLeft' | 'ArrowUp' | 'ArrowDown';
392
+ /** Is `key` one of the four arrow keys? */
393
+ export declare function isArrowKey(key: string): key is ArrowKey;
394
+ /** A move along one of the two axes of a position on screen. */
395
+ interface AxisMove {
396
+ /** 0 = x, 1 = y. */
397
+ axis: 0 | 1;
398
+ /** `1` towards the right or the bottom, `-1` towards the left or the top. */
399
+ direction: 1 | -1;
400
+ }
401
+ /**
402
+ * The direction an arrow key moves a single value: right and up raise it.
403
+ * `null` for any other key.
404
+ */
405
+ export declare function arrowKeyDirection(key: string): 1 | -1 | null;
406
+ /**
407
+ * The axis and direction an arrow key moves a position on screen. `null` for
408
+ * any other key.
409
+ *
410
+ * The key picks the axis, whichever element inside the control holds the
411
+ * focus: a two-dimensional control is one control to the person moving it.
412
+ */
413
+ export declare function arrowKeyMove(key: string): AxisMove | null;
414
+ interface WheelDirectionOptions {
415
+ /**
416
+ * Read horizontal scrolling as well, for a control laid out horizontally:
417
+ * scrolling right raises the value. Vertical scrolling still counts when
418
+ * there is no horizontal movement.
419
+ *
420
+ * @default false
421
+ */
422
+ horizontal?: boolean;
423
+ }
424
+ /**
425
+ * The direction one wheel event moves a single value: scrolling up raises it.
426
+ * `null` when the event carries no movement the control reads.
427
+ */
428
+ export declare function wheelDirection(event: Pick<WheelEvent, 'deltaX' | 'deltaY'>, { horizontal }?: WheelDirectionOptions): 1 | -1 | null;
429
+ /**
430
+ * The axis and direction one wheel event moves a position on screen. `null`
431
+ * when the event carries no movement.
432
+ *
433
+ * Scrolling moves y, and shift switches to x. Browsers turn shift+wheel into
434
+ * horizontal scrolling: `deltaY` comes out empty and `deltaX` carries the
435
+ * movement. Reading whichever axis moved keeps shift working as the x-axis
436
+ * modifier — and picks up a trackpad's own horizontal gesture, which never
437
+ * had a modifier.
438
+ */
439
+ export declare function wheelMove(event: Pick<WheelEvent, 'deltaX' | 'deltaY' | 'shiftKey'>): AxisMove | null;
440
+ //#endregion
441
+ //#region src/knob/geometry.d.ts
442
+ /**
443
+ * Width and height of the viewBox a knob is drawn in. The arcs and the thumb
444
+ * are laid out in these units, and the SVG scales them to the knob's size.
445
+ */
446
+ export declare const KNOB_VIEWBOX_SIZE = 100;
447
+ interface KnobAngleOptions {
448
+ value: number;
449
+ min: number;
450
+ max: number;
451
+ scale: Scale;
452
+ /** Where the active arc starts from, so that it can grow from the middle. */
453
+ startValue: number;
454
+ /** How far the knob turns from `min` to `max`, in degrees. */
455
+ angleRange: number;
456
+ }
457
+ /**
458
+ * The angles a knob is drawn with, in degrees clockwise from the top.
459
+ *
460
+ * The travel is centred on the top, so `angleRange` of 270 runs from -135 to
461
+ * 135. Derived from the value alone, so a wrapper can call it while rendering.
462
+ */
463
+ interface KnobAngles {
464
+ /** The value, normalized to 0..1 along the scale. */
465
+ p: number;
466
+ /** Where the travel starts. */
467
+ r1: number;
468
+ /** Where the active arc starts: the lower of the value and `startValue`. */
469
+ r2: number;
470
+ /** Where the active arc ends: the higher of the value and `startValue`. */
471
+ r3: number;
472
+ /** Where the travel ends. */
473
+ r4: number;
474
+ }
475
+ export declare function knobAngles({ value, min, max, scale, startValue, angleRange }: KnobAngleOptions): KnobAngles;
476
+ /**
477
+ * The point at `angle` on a circle of `radius` around the centre of the
478
+ * viewBox.
479
+ *
480
+ * The radius depends on the stroke of the line being drawn, which each arc
481
+ * has its own of, so the point is found per arc rather than once for the knob.
482
+ */
483
+ export declare function knobArcPoint(angle: number, radius: number): {
484
+ x: number;
485
+ y: number;
486
+ };
487
+ /**
488
+ * The radius that keeps a stroke of `strokeWidth` inside the viewBox: half of
489
+ * the stroke falls outside the path it is drawn along.
490
+ */
491
+ export declare function knobArcRadius(strokeWidth: number | string | undefined): number;
492
+ /** Build an SVG path for an arc, splitting full turns into drawable segments. */
493
+ export declare function knobArcPath(startAngle: number, endAngle: number, radius: number): string;
494
+ //#endregion
298
495
  //#region src/midi/access.d.ts
299
496
  /** @private */
300
497
  export declare const PERMISSION_DENIED = "PERMISSION_DENIED";
@@ -407,6 +604,185 @@ interface MIDIMessageInstance {
407
604
  */
408
605
  export declare function createMIDIMessage(midiAccess: MIDIAccess | null, onMIDIMessage: (event: MIDIMessageEvent) => void): MIDIMessageInstance;
409
606
  //#endregion
607
+ //#region src/number-input/stepper-drag.d.ts
608
+ interface StepperDragOptions {
609
+ /** The value now, read when the drag starts moving it. */
610
+ getValue: () => number;
611
+ /**
612
+ * The range the value moves across. Its `step` is what one step of the drag
613
+ * is worth; see `numberInputRanges` for the one a number input uses.
614
+ */
615
+ range: ValueRange;
616
+ /**
617
+ * How many pixels of vertical movement make one step.
618
+ *
619
+ * @default 1
620
+ */
621
+ pixels?: number;
622
+ /**
623
+ * How much a step is worth, per modifier key: `0.1` makes the same movement
624
+ * count a tenth as much. Pressing or releasing the key mid-drag does not
625
+ * move the value.
626
+ *
627
+ * @default { default: 1, shift: 0.1 }
628
+ */
629
+ sensitivity?: ModifierValue<number>;
630
+ /** Hide the pointer and keep it from hitting the edge of the screen. */
631
+ pointerLock?: boolean;
632
+ /** Called with the new value whenever the drag moves it. */
633
+ onChange: (value: number) => void;
634
+ }
635
+ interface StepperDragInstance {
636
+ /** Replace the given options. `pointerLock` reaches the next drag. */
637
+ update: (options: Partial<StepperDragOptions>) => void;
638
+ /**
639
+ * Whether the drag in progress has moved the value. A stepper button's
640
+ * press-and-hold repeat stands down once it has, so the value is not moved
641
+ * twice.
642
+ */
643
+ moved: () => boolean;
644
+ destroy: () => void;
645
+ }
646
+ /**
647
+ * Drag up and down on the steppers of a number input to move its value, one
648
+ * `step` every `pixels` — up raises it, as on a knob.
649
+ *
650
+ * Counted from where the drag started moving rather than added up per
651
+ * event, so rounding cannot accumulate. The start is taken on the first
652
+ * move, not on pointerdown: a stepper button acts on pointerdown, so by then
653
+ * the value may already have been nudged once, and the drag carries on from
654
+ * there.
655
+ */
656
+ export declare function createStepperDrag(element: Element, options: StepperDragOptions): StepperDragInstance;
657
+ //#endregion
658
+ //#region src/number-input/value.d.ts
659
+ /**
660
+ * The value a number input edits, and how far it may go.
661
+ *
662
+ * Unlike a slider, either end may be left open, and `clampValue: false` lets
663
+ * the value past the ends that are set.
664
+ */
665
+ interface NumberInputValueOptions {
666
+ min?: number;
667
+ max?: number;
668
+ step?: number;
669
+ scale?: Scale;
670
+ /**
671
+ * Keep the value between `min` and `max`.
672
+ *
673
+ * @default true
674
+ */
675
+ clampValue?: boolean;
676
+ }
677
+ /** The ranges {@link nudgeNumberInput} moves a value across. */
678
+ interface NumberInputRanges {
679
+ /** For a `normalized` amount, which needs a finite span to take a share of. */
680
+ normalized: ValueRange;
681
+ /** For a `raw` amount, which does not. */
682
+ raw: ValueRange;
683
+ }
684
+ /**
685
+ * The ranges a number input moves its value across, with the open ends
686
+ * filled in.
687
+ *
688
+ * A normalized amount needs a finite span even when an end is unbounded or
689
+ * clamping is off. Safe integers provide one without overflowing the span a
690
+ * scale calculates. A raw amount needs no span, so its open ends can cover
691
+ * every finite number instead of stopping at the safe-integer range.
692
+ */
693
+ export declare function numberInputRanges({ min, max, step, scale, clampValue }: NumberInputValueOptions): NumberInputRanges;
694
+ /**
695
+ * Move a number input's value by one press of a key, a wheel notch or a
696
+ * stepper, picking the range that suits the kind of amount. See `applyDelta`.
697
+ */
698
+ export declare function nudgeNumberInput(value: number, direction: number, options: ModifierValue<InputEventOption>, ranges: NumberInputRanges, modifiers?: ModifierState): number;
699
+ /**
700
+ * Where the value stands against the ends: whether it can go no further
701
+ * down or up, and whether it lies outside them — which only an unclamped
702
+ * input, or a value set from outside, can do.
703
+ */
704
+ export declare function numberInputBounds(value: number, { min, max, clampValue }: NumberInputValueOptions): {
705
+ atMin: boolean;
706
+ atMax: boolean;
707
+ outOfRange: boolean;
708
+ };
709
+ /**
710
+ * The value typed text commits to, or `null` when there is no number in it.
711
+ *
712
+ * Text with no number is not a value: the input should go back to what it
713
+ * was showing rather than commit a zero the user never typed. What is read
714
+ * is clamped here and not while typing, since clamping as the user types
715
+ * would make "1500" impossible to enter into an input whose max is 100.
716
+ */
717
+ export declare function commitNumberInputText(text: string, parse: (text: string) => number, { min, max, clampValue }: NumberInputValueOptions): number | null;
718
+ //#endregion
719
+ //#region src/number-input/text.d.ts
720
+ /**
721
+ * Reading a number out of the text of a number input, and keeping the caret
722
+ * in place while the number under it changes.
723
+ *
724
+ * The text is whatever `format` made of the value — `"440 Hz"`, `"-6.0 dB"` —
725
+ * or a half-typed entry, so none of this assumes the text is a number alone.
726
+ */
727
+ /** Where the number is in the text; the rest, on either side, is the unit. */
728
+ interface NumberSpan {
729
+ start: number;
730
+ end: number;
731
+ }
732
+ /**
733
+ * Where the number is in the text: from its first digit to its last, with the
734
+ * sign and the decimal point in front of it. Whatever is left on either side
735
+ * is taken for the unit, so it does not matter whether a space separates them,
736
+ * or what the number looks like — `+6.0`, `1e+21`, `1,000` and `1:30` are each
737
+ * one number. `null` when the text has no digit at all.
738
+ */
739
+ export declare function numberSpan(text: string): NumberSpan | null;
740
+ /**
741
+ * The number in the text, with the unit after it ignored: the default `parse`
742
+ * of a number input.
743
+ *
744
+ * `NaN`, which leaves the value alone, whenever the number cannot be read
745
+ * safely, rather than a part of it: text with no number, a number that is not
746
+ * a plain one (`1,000` would otherwise read as 1, and `1:30` as 1), and text
747
+ * with something in front of the number, which can change what it means (the
748
+ * `L` of a pan reading `L 30`). A `format` that writes any of those needs its
749
+ * own `parse`.
750
+ */
751
+ export declare function parseNumberText(text: string): number;
752
+ /**
753
+ * Where the caret is, relative to the decimal point, so that it can be put
754
+ * back at the same digit once the value has changed. See
755
+ * {@link caretAtDecimalOffset}.
756
+ */
757
+ export declare function caretDecimalOffset(text: string, caret: number): number;
758
+ /**
759
+ * The caret position `offset` characters from the decimal point of the new
760
+ * text, kept within the number.
761
+ *
762
+ * @example
763
+ * // The caret sits in front of the point of "9.9" when ArrowUp turns it
764
+ * // into "10.0"
765
+ * const offset = caretDecimalOffset('9.9', 1) // 0
766
+ * caretAtDecimalOffset('10.0', offset) // 2: still in front of the point
767
+ */
768
+ export declare function caretAtDecimalOffset(text: string, offset: number): number;
769
+ //#endregion
770
+ //#region src/options/replace.d.ts
771
+ /**
772
+ * The `update()` argument that leaves an instance with exactly `next` as its
773
+ * options.
774
+ *
775
+ * `update()` merges into what the instance has, which suits a wrapper that
776
+ * pushes one setting at a time. A wrapper handed the whole new set instead —
777
+ * a Svelte action, a Vue composable — has to clear what the new set no longer
778
+ * carries, or a handler taken away, or an option left to its default, keeps
779
+ * working.
780
+ *
781
+ * @example
782
+ * instance.update(replaceOptions(previous, next))
783
+ */
784
+ export declare function replaceOptions<T extends object>(previous: T | undefined, next: T | undefined): Partial<T>;
785
+ //#endregion
410
786
  //#region src/piano/layout.d.ts
411
787
  type NoteRange = {
412
788
  first: number;
@@ -470,6 +846,48 @@ export declare function notePosition(note: number, layout: PianoLayout): number;
470
846
  * @param height height of the keyboard, in pixels
471
847
  */
472
848
  export declare function noteAt(x: number, y: number, height: number, layout: PianoLayout): number | null;
849
+ /**
850
+ * The white key width that makes the keyboard exactly `width` wide, for a
851
+ * keyboard that follows the size of its container.
852
+ *
853
+ * Solved from {@link pianoWidth} rather than by dividing among the white
854
+ * keys, so that a range that starts or ends on a black key — which sticks out
855
+ * by a fraction of a white key — still fills the container. The width grows
856
+ * linearly with the white key width, so two samples pin it down.
857
+ */
858
+ export declare function fitWhiteKeyWidth(width: number, layout: Omit<PianoLayout, 'whiteKeyWidth'>): number;
859
+ //#endregion
860
+ //#region src/piano/shortcuts.d.ts
861
+ type KeyboardShortcuts = {
862
+ /**
863
+ * Keys laid out from `noteRange.first`, one entry per semitone.
864
+ *
865
+ * An empty string leaves that note without a shortcut: `KeyboardEvent.key` is
866
+ * never empty, so the entry can never match. Use it to skip the black keys
867
+ * (see {@link SHORTCUTS.HOME_ROW_NATURAL}) and keep the remaining entries
868
+ * lined up with the notes.
869
+ */
870
+ keys: string[];
871
+ };
872
+ /**
873
+ * Ready-made keyboard layouts. Both assume `noteRange.first` is a C.
874
+ */
875
+ export declare const SHORTCUTS: {
876
+ /** Every semitone from C, over the two rows of a QWERTY keyboard. */
877
+ HOME_ROW: {
878
+ keys: string[];
879
+ };
880
+ /** The white keys only, on the home row. Black keys have no shortcut. */
881
+ HOME_ROW_NATURAL: {
882
+ keys: string[];
883
+ };
884
+ };
885
+ /**
886
+ * Where keyboard shortcuts listen. `root` handles keys only while the piano
887
+ * or one of its descendants has focus; `window` handles them anywhere on the
888
+ * page except in editable elements.
889
+ */
890
+ type KeyboardShortcutsScope = 'root' | 'window';
473
891
  //#endregion
474
892
  //#region src/piano/index.d.ts
475
893
  /**
@@ -499,6 +917,24 @@ interface PianoInputOptions {
499
917
  * @default 127
500
918
  */
501
919
  midiMax?: number;
920
+ /**
921
+ * Play notes from the computer keyboard: `keys[i]` plays
922
+ * `layout.noteRange.first + i`. `SHORTCUTS` has ready-made layouts.
923
+ *
924
+ * A held key keeps its note until it is released, the focus leaves (with
925
+ * `root`), or the window loses focus. Changing the keys, the scope or the
926
+ * note range releases every note a key is holding, since the key would
927
+ * mean something else on release.
928
+ */
929
+ keyboardShortcuts?: KeyboardShortcuts;
930
+ /**
931
+ * Where keyboard shortcuts listen: on the element (`root`), which has to
932
+ * be focusable, or anywhere on the page (`window`). Keys typed into an
933
+ * editable element are ignored either way.
934
+ *
935
+ * @default 'root'
936
+ */
937
+ keyboardShortcutsScope?: KeyboardShortcutsScope;
502
938
  /** Called when a note starts sounding, not for each source that asks. */
503
939
  onPlayNote?: (note: number, velocity?: number) => void;
504
940
  /** Called once the last source holding a note has let go. */
@@ -513,8 +949,8 @@ interface PianoInputInstance {
513
949
  */
514
950
  update: (options: Partial<PianoInputOptions>) => void;
515
951
  /**
516
- * Start a note from something other than a pointer: a keyboard shortcut, a
517
- * MIDI message, an imperative call.
952
+ * Start a note from something other than a pointer or a shortcut: a MIDI
953
+ * message, an imperative call.
518
954
  */
519
955
  noteOn: (note: number, options?: {
520
956
  source?: NoteSource;
@@ -540,6 +976,219 @@ interface PianoInputInstance {
540
976
  */
541
977
  export declare function createPianoInput(element: Element, options: PianoInputOptions): PianoInputInstance;
542
978
  //#endregion
979
+ //#region src/xy.d.ts
980
+ /**
981
+ * A pair of per-axis values. The tuple elements are labelled, so editors show
982
+ * `[x: number, y: number]` rather than a bare pair.
983
+ */
984
+ type XY<T> = [x: T, y: T];
985
+ /**
986
+ * A setting that may be given once for both axes, or per axis.
987
+ *
988
+ * A single value is told from a pair with `Array.isArray`, so the single form
989
+ * is only offered while `T` cannot itself be an array. Where it can, the pair
990
+ * is the only way to write it, since a lone array would be read as a pair.
991
+ */
992
+ type XYInput<T> = [T] extends [readonly unknown[]] ? readonly [x: T, y: T] : T | readonly [x: T, y: T];
993
+ /**
994
+ * Spread a setting that may have been given as a single value.
995
+ *
996
+ * The parameter is written out rather than taken as `XYInput<T>`: a
997
+ * conditional type cannot be narrowed, so the constraint stays where it is
998
+ * declared and this takes both forms.
999
+ *
1000
+ * The pair is copied rather than passed along, so that the result is a tuple
1001
+ * the caller owns even when a readonly one was given.
1002
+ */
1003
+ export declare function toXY<T>(value: T | readonly [x: T, y: T]): XY<T>;
1004
+ //#endregion
1005
+ //#region src/selection/box.d.ts
1006
+ /**
1007
+ * A rectangle in the 0..1 space of whatever the box is drawn over, with `y`
1008
+ * growing downwards — the same space the items are given in.
1009
+ */
1010
+ interface SelectionBoxRect {
1011
+ x: number;
1012
+ y: number;
1013
+ width: number;
1014
+ height: number;
1015
+ }
1016
+ interface SelectionBoxOptions<Id> {
1017
+ /**
1018
+ * Everything the box can pick up, read on every move rather than taken as a
1019
+ * snapshot: what is under the box changes while it is dragged, and an item
1020
+ * may have moved since the last one.
1021
+ */
1022
+ items: () => Iterable<readonly [Id, XY<number>]>;
1023
+ /** The box as it is dragged, and `null` once it is gone. */
1024
+ onBoxChange?: (box: SelectionBoxRect | null) => void;
1025
+ /** What the box covers, added to whatever it started from. */
1026
+ onSelectionChange?: (ids: Id[]) => void;
1027
+ }
1028
+ interface SelectionBoxBeginOptions<Id> {
1029
+ /**
1030
+ * Add to `selection` rather than replacing it. Ctrl / meta rather than
1031
+ * shift, for the controls where shift is the fine-adjustment key.
1032
+ */
1033
+ additive?: boolean;
1034
+ /** What was selected before the box started. Only read when `additive`. */
1035
+ selection?: readonly Id[];
1036
+ }
1037
+ interface SelectionBoxInstance<Id> {
1038
+ /** Replace the given options, without interrupting a box in progress. */
1039
+ update: (options: Partial<SelectionBoxOptions<Id>>) => void;
1040
+ /** Start a box at `at`, which is one of its corners. */
1041
+ begin: (at: XY<number>, options?: SelectionBoxBeginOptions<Id>) => void;
1042
+ /** Drag the opposite corner to `to`. */
1043
+ move: (to: XY<number>) => void;
1044
+ /**
1045
+ * Finish the box. The selection stays as it is.
1046
+ *
1047
+ * @returns whether a box was running, so that a caller can tell a drag from
1048
+ * a press that selected nothing.
1049
+ */
1050
+ end: () => boolean;
1051
+ /** The box being dragged, or `null` when there is none. */
1052
+ box: () => SelectionBoxRect | null;
1053
+ destroy: () => void;
1054
+ }
1055
+ /** Whether the box covers the point, edges included. */
1056
+ export declare function selectionBoxCovers(box: SelectionBoxRect, [x, y]: XY<number>): boolean;
1057
+ /**
1058
+ * Selecting by dragging a box over a set of items.
1059
+ *
1060
+ * The drag itself is not here: the caller owns the pointer, and reports where
1061
+ * it went in the same 0..1 space the items are given in.
1062
+ */
1063
+ export declare function createSelectionBox<Id>(options: SelectionBoxOptions<Id>): SelectionBoxInstance<Id>;
1064
+ //#endregion
1065
+ //#region src/points-editor/index.d.ts
1066
+ /** Where a point is: 0..1 on each axis, with y growing downwards. */
1067
+ interface PointPosition {
1068
+ x: number;
1069
+ y: number;
1070
+ }
1071
+ /**
1072
+ * A point's value is its position in the editor, so its range is the editor:
1073
+ * no scaling, and no rounding to a step.
1074
+ */
1075
+ export declare const POINT_AXIS: {
1076
+ min: number;
1077
+ max: number;
1078
+ };
1079
+ /**
1080
+ * How much one wheel notch moves a point by default: a hundredth of the
1081
+ * editor, whatever its pixel size.
1082
+ */
1083
+ export declare const POINTS_EDITOR_DEFAULT_WHEEL: ModifierValue<InputEventOption>;
1084
+ /**
1085
+ * How much one arrow key press moves a point by default. Shift is the
1086
+ * fine-adjustment key everywhere else, so it is bound here too — but only on
1087
+ * the keyboard. On the wheel it already means the x axis, and browsers hand
1088
+ * shift+wheel over as horizontal scrolling anyway.
1089
+ */
1090
+ export declare const POINTS_EDITOR_DEFAULT_KEYBOARD: ModifierValue<InputEventOption>;
1091
+ /** Keep a point within its range. An axis left out runs from 0 to 1. */
1092
+ export declare function clampPoint(point: PointPosition, min?: Partial<PointPosition>, max?: Partial<PointPosition>): PointPosition;
1093
+ /**
1094
+ * What a point tells the editor about itself, so that a selection can be
1095
+ * moved without the editor knowing how the points are stored.
1096
+ */
1097
+ interface PointsEditorPoint {
1098
+ value: PointPosition;
1099
+ min?: Partial<PointPosition>;
1100
+ max?: Partial<PointPosition>;
1101
+ /** A point that cannot move stays put while the rest of a selection moves. */
1102
+ readonly?: boolean;
1103
+ onChange?: (value: PointPosition) => void;
1104
+ /** The point's own element, to match the focus and a press against. */
1105
+ element?: Element | null;
1106
+ /** The wheel option the point resolved, `null` for no wheel. */
1107
+ wheel?: ModifierValue<InputEventOption> | null;
1108
+ }
1109
+ interface PointsEditorOptions {
1110
+ /**
1111
+ * Let points be selected, and a selection be moved as one. While it is off
1112
+ * nothing is selected, and a drag moves only the point it started on.
1113
+ *
1114
+ * @default false
1115
+ */
1116
+ selectable?: boolean;
1117
+ /**
1118
+ * The ids of the selected points. Whoever holds the selection pushes it
1119
+ * back with `update()` after {@link PointsEditorOptions.onSelectionChange}.
1120
+ */
1121
+ selection?: readonly string[];
1122
+ /** Called whenever a press or a selection box changes the selection. */
1123
+ onSelectionChange?: (selection: string[]) => void;
1124
+ /** Called whenever the selection box changes, with `null` once it is gone. */
1125
+ onSelectionBoxChange?: (rect: SelectionBoxRect | null) => void;
1126
+ }
1127
+ interface PointsEditorInstance {
1128
+ /** Replace the given options. */
1129
+ update: (options: Partial<PointsEditorOptions>) => void;
1130
+ /**
1131
+ * Register a point under `id`. `read` is called whenever the editor needs
1132
+ * the point, so it can return what the point is now rather than what it
1133
+ * was when it registered. Returns the function that unregisters it.
1134
+ */
1135
+ registerPoint: (id: string, read: () => PointsEditorPoint) => () => void;
1136
+ /** Whether the element is a point, or inside one. */
1137
+ isPointElement: (element: Element | null | undefined) => boolean;
1138
+ /**
1139
+ * A pointer went down on a point: work out the new selection and remember
1140
+ * where everything the drag picked up started.
1141
+ *
1142
+ * Ctrl / meta add the point to the selection or take it out: shift is the
1143
+ * fine-adjustment key on every control here, and it cannot be both. A
1144
+ * press on a point already selected keeps the selection, so the group can
1145
+ * be dragged.
1146
+ */
1147
+ beginPointDrag: (id: string, modifiers: ModifierState) => void;
1148
+ /**
1149
+ * Move everything the drag picked up by `delta` from where it started,
1150
+ * stopping the whole group together at the edge.
1151
+ */
1152
+ movePointDrag: (delta: PointPosition) => void;
1153
+ /**
1154
+ * Move `id` — and the selection, when it is part of one — by `delta` from
1155
+ * where the points are now: an input that is not a drag has no earlier
1156
+ * position to measure against.
1157
+ */
1158
+ nudgeSelection: (id: string, delta: PointPosition) => void;
1159
+ /**
1160
+ * Move `id` by one press of `option` along one axis, taking the selection
1161
+ * along as {@link PointsEditorInstance.nudgeSelection} does.
1162
+ */
1163
+ nudgePoint: (id: string, axis: 'x' | 'y', direction: number, option: ModifierValue<InputEventOption>, modifiers?: ModifierState) => void;
1164
+ /**
1165
+ * Move the point holding the focus by one wheel notch, with its own wheel
1166
+ * option. The wheel is listened to once for the whole editor, since a wheel
1167
+ * event only reaches what the cursor is over. Returns whether a point took
1168
+ * it, so the caller knows whether to consume the event.
1169
+ */
1170
+ nudgeFocusedPoint: (axis: 'x' | 'y', direction: number, modifiers: ModifierState) => boolean;
1171
+ /** A drag on empty space started at `at`: start a selection box there. */
1172
+ beginSelectionBox: (at: PointPosition, modifiers: ModifierState) => void;
1173
+ moveSelectionBox: (to: PointPosition) => void;
1174
+ /**
1175
+ * End the selection box. The press that started it left the focus on
1176
+ * nothing, and the arrow keys and the wheel reach a point only through the
1177
+ * focus, so it is handed to one of the points the box selected.
1178
+ */
1179
+ endSelectionBox: () => void;
1180
+ destroy: () => void;
1181
+ }
1182
+ /**
1183
+ * The selection and the moves of a points editor: which points a press or a
1184
+ * box selects, and how a selection moves as one.
1185
+ *
1186
+ * The points stay with the wrapper, which registers each one; the editor only
1187
+ * reads them when it needs to, so a point's value can change on every frame
1188
+ * of a drag without anything being re-registered.
1189
+ */
1190
+ export declare function createPointsEditor(options?: PointsEditorOptions): PointsEditorInstance;
1191
+ //#endregion
543
1192
  //#region src/pointer/drag.d.ts
544
1193
  type DragState = {
545
1194
  /** Total movement from the drag start, in screen coordinates. */
@@ -656,32 +1305,6 @@ interface DragInstance {
656
1305
  */
657
1306
  export declare function createDrag(element: Element, options?: DragOptions): DragInstance;
658
1307
  //#endregion
659
- //#region src/xy.d.ts
660
- /**
661
- * A pair of per-axis values. The tuple elements are labelled, so editors show
662
- * `[x: number, y: number]` rather than a bare pair.
663
- */
664
- type XY<T> = [x: T, y: T];
665
- /**
666
- * A setting that may be given once for both axes, or per axis.
667
- *
668
- * A single value is told from a pair with `Array.isArray`, so the single form
669
- * is only offered while `T` cannot itself be an array. Where it can, the pair
670
- * is the only way to write it, since a lone array would be read as a pair.
671
- */
672
- type XYInput<T> = [T] extends [readonly unknown[]] ? readonly [x: T, y: T] : T | readonly [x: T, y: T];
673
- /**
674
- * Spread a setting that may have been given as a single value.
675
- *
676
- * The parameter is written out rather than taken as `XYInput<T>`: a
677
- * conditional type cannot be narrowed, so the constraint stays where it is
678
- * declared and this takes both forms.
679
- *
680
- * The pair is copied rather than passed along, so that the result is a tuple
681
- * the caller owns even when a readonly one was given.
682
- */
683
- export declare function toXY<T>(value: T | readonly [x: T, y: T]): XY<T>;
684
- //#endregion
685
1308
  //#region src/pointer/drag-value.d.ts
686
1309
  /**
687
1310
  * How the 0-1 travel of one axis maps onto a value.
@@ -821,6 +1444,50 @@ interface DragValueInstance {
821
1444
  */
822
1445
  export declare function createDragValue(element: Element, options: DragValueOptions): DragValueInstance;
823
1446
  //#endregion
1447
+ //#region src/pointer/long-press.d.ts
1448
+ interface LongPressOptions {
1449
+ /** Called once on the press, then again every `interval` after `delay`. */
1450
+ onPress: () => void;
1451
+ /**
1452
+ * How long the press has to be held before it starts repeating, in
1453
+ * milliseconds.
1454
+ *
1455
+ * @default 500
1456
+ */
1457
+ delay?: number;
1458
+ /**
1459
+ * How often it repeats once it has started, in milliseconds.
1460
+ *
1461
+ * @default 40
1462
+ */
1463
+ interval?: number;
1464
+ }
1465
+ interface LongPressInstance {
1466
+ /**
1467
+ * Start a press, from a `pointerdown` or with no event at all. Only the
1468
+ * primary button starts one, and a press already in progress is left alone.
1469
+ */
1470
+ start: (event?: Pick<PointerEvent, 'button' | 'pointerId'>) => void;
1471
+ /** End the press, as releasing the pointer would. */
1472
+ stop: () => void;
1473
+ /** Replace the given options. The press in progress picks them up. */
1474
+ update: (options: Partial<LongPressOptions>) => void;
1475
+ /** Whether a press is in progress. */
1476
+ pressed: () => boolean;
1477
+ destroy: () => void;
1478
+ }
1479
+ /**
1480
+ * Repeat an action while a pointer is held down: once on the press, then
1481
+ * again every `interval` after `delay` — the way a stepper button or a
1482
+ * key held on a keyboard behaves.
1483
+ *
1484
+ * The release is listened for on the window, not on the element: the
1485
+ * pointer may be let go anywhere. Only the pointer that started the press
1486
+ * ends it, so a second finger lifting elsewhere does not. The window losing
1487
+ * focus ends it too, since the release would never arrive.
1488
+ */
1489
+ export declare function createLongPress(options: LongPressOptions): LongPressInstance;
1490
+ //#endregion
824
1491
  //#region src/pointer/wheel.d.ts
825
1492
  interface WheelOptions {
826
1493
  /** Replace the callback through {@link WheelInstance.update}. */
@@ -853,65 +1520,81 @@ interface WheelInstance {
853
1520
  */
854
1521
  export declare function createWheel(element: Element, onWheel: (event: WheelEvent) => void, options?: WheelOptions): WheelInstance;
855
1522
  //#endregion
856
- //#region src/selection/box.d.ts
1523
+ //#region src/position.d.ts
857
1524
  /**
858
- * A rectangle in the 0..1 space of whatever the box is drawn over, with `y`
859
- * growing downwards — the same space the items are given in.
1525
+ * Where a value sits along a track, as a whole percentage from its start.
1526
+ *
1527
+ * Normalized along the scale, so a thumb, the fill behind it and the marks
1528
+ * all sit on the curve the drag follows. `reversed` measures from the other
1529
+ * end — for a track that grows upwards or leftwards on screen, since CSS
1530
+ * places things from the top and the left.
860
1531
  */
861
- interface SelectionBoxRect {
862
- x: number;
863
- y: number;
864
- width: number;
865
- height: number;
866
- }
867
- interface SelectionBoxOptions<Id> {
868
- /**
869
- * Everything the box can pick up, read on every move rather than taken as a
870
- * snapshot: what is under the box changes while it is dragged, and an item
871
- * may have moved since the last one.
872
- */
873
- items: () => Iterable<readonly [Id, XY<number>]>;
874
- /** The box as it is dragged, and `null` once it is gone. */
875
- onBoxChange?: (box: SelectionBoxRect | null) => void;
876
- /** What the box covers, added to whatever it started from. */
877
- onSelectionChange?: (ids: Id[]) => void;
878
- }
879
- interface SelectionBoxBeginOptions<Id> {
880
- /**
881
- * Add to `selection` rather than replacing it. Ctrl / meta rather than
882
- * shift, for the controls where shift is the fine-adjustment key.
883
- */
884
- additive?: boolean;
885
- /** What was selected before the box started. Only read when `additive`. */
886
- selection?: readonly Id[];
887
- }
888
- interface SelectionBoxInstance<Id> {
889
- /** Replace the given options, without interrupting a box in progress. */
890
- update: (options: Partial<SelectionBoxOptions<Id>>) => void;
891
- /** Start a box at `at`, which is one of its corners. */
892
- begin: (at: XY<number>, options?: SelectionBoxBeginOptions<Id>) => void;
893
- /** Drag the opposite corner to `to`. */
894
- move: (to: XY<number>) => void;
895
- /**
896
- * Finish the box. The selection stays as it is.
897
- *
898
- * @returns whether a box was running, so that a caller can tell a drag from
899
- * a press that selected nothing.
900
- */
901
- end: () => boolean;
902
- /** The box being dragged, or `null` when there is none. */
903
- box: () => SelectionBoxRect | null;
904
- destroy: () => void;
1532
+ export declare function valuePercent(value: number, { min, max, scale }: Pick<ValueRange, 'min' | 'max' | 'scale'>, reversed?: boolean): number;
1533
+ //#endregion
1534
+ //#region src/slider/marks.d.ts
1535
+ /**
1536
+ * How `Slider.Marks` fills itself in when it is given no children: one option
1537
+ * every `per`, or every `step` of the slider. The object form turns off the
1538
+ * mark or the label for the whole set; a single option is customized by
1539
+ * writing `Slider.MarksOption` out instead.
1540
+ */
1541
+ type MarksOptions = 'step' | number | {
1542
+ per: 'step' | number;
1543
+ mark?: boolean;
1544
+ label?: boolean;
1545
+ };
1546
+ /** One mark along a slider, as {@link sliderMarks} lays them out. */
1547
+ interface SliderMark {
1548
+ value: number;
1549
+ mark: boolean;
1550
+ label: boolean;
905
1551
  }
906
- /** Whether the box covers the point, edges included. */
907
- export declare function selectionBoxCovers(box: SelectionBoxRect, [x, y]: XY<number>): boolean;
908
1552
  /**
909
- * Selecting by dragging a box over a set of items.
1553
+ * The marks `options` asks for between `min` and `max`, in ascending order.
910
1554
  *
911
- * The drag itself is not here: the caller owns the pointer, and reports where
912
- * it went in the same 0..1 space the items are given in.
1555
+ * Each value is a whole multiple of the interval, rounded to the digits the
1556
+ * interval has: stepping by 0.1 would otherwise put binary debris in the
1557
+ * labels (`0.1 * 3` is `0.30000000000000004`).
913
1558
  */
914
- export declare function createSelectionBox<Id>(options: SelectionBoxOptions<Id>): SelectionBoxInstance<Id>;
1559
+ export declare function sliderMarks(options: MarksOptions, min: number, max: number, step: number): SliderMark[];
1560
+ //#endregion
1561
+ //#region src/style.d.ts
1562
+ /**
1563
+ * A number as a CSS length, for a custom property.
1564
+ *
1565
+ * A custom property takes whatever text it is given, so `--size: 50` comes out
1566
+ * as the invalid `50` rather than `50px`. React appends `px` to a bare number
1567
+ * only for the properties it knows take a length, and a custom property is
1568
+ * never one of them; Vue and Svelte append nothing at all. Anything already a
1569
+ * string is passed through, so `'3rem'` and `'100%'` still work.
1570
+ */
1571
+ export declare function cssLength(value: number | string | undefined): string | undefined;
1572
+ /**
1573
+ * Take an element out of sight while leaving it in the accessibility tree and
1574
+ * in the tab order.
1575
+ *
1576
+ * `display: none` and `visibility: hidden` would remove it from both, and the
1577
+ * native control underneath a headless component is what carries the ARIA and
1578
+ * the keyboard behaviour. `pointer-events: none` is safe because nothing is
1579
+ * ever clicked here directly: a `<label>` forwards its click, and a drag is
1580
+ * handled by the part that is visible.
1581
+ *
1582
+ * Every value is a string with its unit, so the object can be handed to any
1583
+ * framework's `style` binding as it is.
1584
+ */
1585
+ export declare const visuallyHiddenStyle: {
1586
+ readonly position: "absolute";
1587
+ readonly width: "1px";
1588
+ readonly height: "1px";
1589
+ readonly padding: "0";
1590
+ readonly margin: "-1px";
1591
+ readonly overflow: "hidden";
1592
+ readonly clip: "rect(0, 0, 0, 0)";
1593
+ readonly clipPath: "inset(50%)";
1594
+ readonly whiteSpace: "nowrap";
1595
+ readonly border: "0";
1596
+ readonly pointerEvents: "none";
1597
+ };
915
1598
  //#endregion
916
- export type { AcceptCandidate, AnimationCanvasInstance, AnimationCanvasOptions, AnimationFrame, AxisOptions, CanvasDrawFunction, CanvasInitFunction, DragInstance, DragOptions, DragState, DragValueInstance, DragValueMapping, DragValueOptions, DrawingContext, DrawingState, DrawingStateValue, DropZoneInstance, DropZoneOptions, DropZoneState, InputEventOption, MIDIAccessError, MIDIAccessInstance, MIDIAccessOptions, MIDIAccessState, MIDIInputHandlers, MIDIInputInstance, MIDIMessageInstance, MappingContext, Modifier, ModifierMap, ModifierState, ModifierValue, NoteRange, NoteSource, PianoInputInstance, PianoInputOptions, PianoLayout, SelectionBoxBeginOptions, SelectionBoxInstance, SelectionBoxOptions, SelectionBoxRect, WheelInstance, WheelOptions, XY, XYInput };
1599
+ export type { AcceptCandidate, AnimationCanvasInstance, AnimationCanvasOptions, AnimationFrame, ArrowKey, AxisMove, AxisOptions, CanvasDrawFunction, CanvasInitFunction, CheckStepsOptions, DragInstance, DragOptions, DragState, DragValueInstance, DragValueMapping, DragValueOptions, DrawingContext, DrawingState, DrawingStateValue, DropZoneInstance, DropZoneOptions, DropZoneState, InputEventOption, KeyboardShortcuts, KeyboardShortcutsScope, KnobAngleOptions, KnobAngles, LongPressInstance, LongPressOptions, MIDIAccessError, MIDIAccessInstance, MIDIAccessOptions, MIDIAccessState, MIDIInputHandlers, MIDIInputInstance, MIDIMessageInstance, MappingContext, MarksOptions, Modifier, ModifierMap, ModifierState, ModifierValue, NoteRange, NoteSource, NumberInputRanges, NumberInputValueOptions, NumberSpan, PianoInputInstance, PianoInputOptions, PianoLayout, PointPosition, PointsEditorInstance, PointsEditorOptions, PointsEditorPoint, SelectionBoxBeginOptions, SelectionBoxInstance, SelectionBoxOptions, SelectionBoxRect, SliderMark, StepperDragInstance, StepperDragOptions, WheelDirectionOptions, WheelInstance, WheelOptions, XY, XYInput };
917
1600
  //# sourceMappingURL=index.d.ts.map