@ac-kit/ui-common 0.0.0-stage → 0.1.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE +28 -0
  3. package/README.md +315 -2
  4. package/dist/button/button.d.ts +35 -0
  5. package/dist/button/button.d.ts.map +1 -0
  6. package/dist/button/button.js +22 -0
  7. package/dist/button/button.js.map +1 -0
  8. package/dist/dialog/dialog.d.ts +33 -0
  9. package/dist/dialog/dialog.d.ts.map +1 -0
  10. package/dist/dialog/dialog.js +23 -0
  11. package/dist/dialog/dialog.js.map +1 -0
  12. package/dist/focus/owns-arrow-keys.d.ts +31 -0
  13. package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
  14. package/dist/focus/owns-arrow-keys.js +64 -0
  15. package/dist/focus/owns-arrow-keys.js.map +1 -0
  16. package/dist/focus/roving-focus.d.ts +34 -0
  17. package/dist/focus/roving-focus.d.ts.map +1 -0
  18. package/dist/focus/roving-focus.js +72 -0
  19. package/dist/focus/roving-focus.js.map +1 -0
  20. package/dist/index.d.ts +16 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +16 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/knob/knob.d.ts +106 -0
  25. package/dist/knob/knob.d.ts.map +1 -0
  26. package/dist/knob/knob.js +116 -0
  27. package/dist/knob/knob.js.map +1 -0
  28. package/dist/meter/meter.d.ts +63 -0
  29. package/dist/meter/meter.d.ts.map +1 -0
  30. package/dist/meter/meter.js +57 -0
  31. package/dist/meter/meter.js.map +1 -0
  32. package/dist/preact/button.d.ts +40 -0
  33. package/dist/preact/button.d.ts.map +1 -0
  34. package/dist/preact/button.js +22 -0
  35. package/dist/preact/button.js.map +1 -0
  36. package/dist/preact/dialog.d.ts +43 -0
  37. package/dist/preact/dialog.d.ts.map +1 -0
  38. package/dist/preact/dialog.js +89 -0
  39. package/dist/preact/dialog.js.map +1 -0
  40. package/dist/preact/index.d.ts +13 -0
  41. package/dist/preact/index.d.ts.map +1 -0
  42. package/dist/preact/index.js +13 -0
  43. package/dist/preact/index.js.map +1 -0
  44. package/dist/preact/join-classes.d.ts +10 -0
  45. package/dist/preact/join-classes.d.ts.map +1 -0
  46. package/dist/preact/join-classes.js +12 -0
  47. package/dist/preact/join-classes.js.map +1 -0
  48. package/dist/preact/knob.d.ts +51 -0
  49. package/dist/preact/knob.d.ts.map +1 -0
  50. package/dist/preact/knob.js +152 -0
  51. package/dist/preact/knob.js.map +1 -0
  52. package/dist/preact/meter.d.ts +34 -0
  53. package/dist/preact/meter.d.ts.map +1 -0
  54. package/dist/preact/meter.js +21 -0
  55. package/dist/preact/meter.js.map +1 -0
  56. package/dist/preact/radio-group.d.ts +50 -0
  57. package/dist/preact/radio-group.d.ts.map +1 -0
  58. package/dist/preact/radio-group.js +42 -0
  59. package/dist/preact/radio-group.js.map +1 -0
  60. package/dist/preact/readout.d.ts +22 -0
  61. package/dist/preact/readout.d.ts.map +1 -0
  62. package/dist/preact/readout.js +13 -0
  63. package/dist/preact/readout.js.map +1 -0
  64. package/dist/preact/slider.d.ts +40 -0
  65. package/dist/preact/slider.d.ts.map +1 -0
  66. package/dist/preact/slider.js +162 -0
  67. package/dist/preact/slider.js.map +1 -0
  68. package/dist/preact/switch.d.ts +25 -0
  69. package/dist/preact/switch.d.ts.map +1 -0
  70. package/dist/preact/switch.js +19 -0
  71. package/dist/preact/switch.js.map +1 -0
  72. package/dist/preact/toggle-button.d.ts +26 -0
  73. package/dist/preact/toggle-button.d.ts.map +1 -0
  74. package/dist/preact/toggle-button.js +16 -0
  75. package/dist/preact/toggle-button.js.map +1 -0
  76. package/dist/preact/toolbar.d.ts +24 -0
  77. package/dist/preact/toolbar.d.ts.map +1 -0
  78. package/dist/preact/toolbar.js +148 -0
  79. package/dist/preact/toolbar.js.map +1 -0
  80. package/dist/preact/use-element-binding.d.ts +32 -0
  81. package/dist/preact/use-element-binding.d.ts.map +1 -0
  82. package/dist/preact/use-element-binding.js +51 -0
  83. package/dist/preact/use-element-binding.js.map +1 -0
  84. package/dist/readout/readout.d.ts +41 -0
  85. package/dist/readout/readout.d.ts.map +1 -0
  86. package/dist/readout/readout.js +26 -0
  87. package/dist/readout/readout.js.map +1 -0
  88. package/dist/slider/_clamped-value.d.ts +7 -0
  89. package/dist/slider/_clamped-value.d.ts.map +1 -0
  90. package/dist/slider/_clamped-value.js +9 -0
  91. package/dist/slider/_clamped-value.js.map +1 -0
  92. package/dist/slider/slider-attributes.d.ts +50 -0
  93. package/dist/slider/slider-attributes.d.ts.map +1 -0
  94. package/dist/slider/slider-attributes.js +38 -0
  95. package/dist/slider/slider-attributes.js.map +1 -0
  96. package/dist/slider/slider-range.d.ts +59 -0
  97. package/dist/slider/slider-range.d.ts.map +1 -0
  98. package/dist/slider/slider-range.js +73 -0
  99. package/dist/slider/slider-range.js.map +1 -0
  100. package/dist/slider/slider-track.d.ts +37 -0
  101. package/dist/slider/slider-track.d.ts.map +1 -0
  102. package/dist/slider/slider-track.js +35 -0
  103. package/dist/slider/slider-track.js.map +1 -0
  104. package/dist/slider/stepped-value.d.ts +31 -0
  105. package/dist/slider/stepped-value.d.ts.map +1 -0
  106. package/dist/slider/stepped-value.js +55 -0
  107. package/dist/slider/stepped-value.js.map +1 -0
  108. package/dist/switch/switch.d.ts +30 -0
  109. package/dist/switch/switch.d.ts.map +1 -0
  110. package/dist/switch/switch.js +26 -0
  111. package/dist/switch/switch.js.map +1 -0
  112. package/dist/toggle-button/toggle-button.d.ts +44 -0
  113. package/dist/toggle-button/toggle-button.d.ts.map +1 -0
  114. package/dist/toggle-button/toggle-button.js +31 -0
  115. package/dist/toggle-button/toggle-button.js.map +1 -0
  116. package/dist/tone.d.ts +8 -0
  117. package/dist/tone.d.ts.map +1 -0
  118. package/dist/tone.js +2 -0
  119. package/dist/tone.js.map +1 -0
  120. package/dist/toolbar/toolbar.d.ts +35 -0
  121. package/dist/toolbar/toolbar.d.ts.map +1 -0
  122. package/dist/toolbar/toolbar.js +23 -0
  123. package/dist/toolbar/toolbar.js.map +1 -0
  124. package/package.json +100 -3
  125. package/styles.css +992 -0
@@ -0,0 +1,51 @@
1
+ import { useCallback, useLayoutEffect, useRef, useState } from "preact/hooks";
2
+ /**
3
+ * Runs `bind` on an element once it is mounted, and again when `deps` change or
4
+ * the element is replaced; before each re-run and at unmount it aborts the
5
+ * signal it passed and disposes what `bind` returned. For `ui-gesture/dom`
6
+ * bindings in this package's components, `ui-music`'s and the caller's.
7
+ *
8
+ * Returns the callback ref to put on the element, which is how the hook sees an
9
+ * element mounted late or swapped for another with the dependencies unchanged.
10
+ * The binding is made in the render that follows the element's mount, so a
11
+ * `touch-action` it sets comes right after the first paint; the stylesheet sets
12
+ * the same ones for the first press.
13
+ *
14
+ * @example
15
+ * const root = useElementBinding<HTMLDivElement>(
16
+ * (element, signal) => bindPointers(element, handlers, { signal }),
17
+ * [],
18
+ * );
19
+ * return <div ref={root} />;
20
+ */
21
+ export function useElementBinding(bind, deps) {
22
+ const [element, setElement] = useState(null);
23
+ const attach = useCallback((node) => {
24
+ setElement(node);
25
+ }, []);
26
+ const latestBind = useRef(bind);
27
+ latestBind.current = bind;
28
+ useLayoutEffect(() => {
29
+ if (element === null) {
30
+ return undefined;
31
+ }
32
+ const controller = new AbortController();
33
+ const binding = latestBind.current(element, controller.signal);
34
+ return () => {
35
+ controller.abort();
36
+ binding?.[Symbol.dispose]();
37
+ };
38
+ }, [element, ...deps]);
39
+ return attach;
40
+ }
41
+ /**
42
+ * A ref whose `current` is always the latest `value`, for handlers a binding
43
+ * reads at each call. It is written during render, so a handler that runs
44
+ * between a render and its commit sees the newer value.
45
+ */
46
+ export function useLatest(value) {
47
+ const ref = useRef(value);
48
+ ref.current = value;
49
+ return ref;
50
+ }
51
+ //# sourceMappingURL=use-element-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-element-binding.js","sourceRoot":"","sources":["../../src/preact/use-element-binding.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAGC,EACD,IAA4B;IAE5B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAmB,EAAE,EAAE;QAClD,UAAU,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,GAAG,EAAE;QACpB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAE/D,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAEvB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAQ,KAAY;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { ControlTone } from "../tone.js";
2
+ /**
3
+ * Whether assistive technology announces a readout's changes: `off` for a value
4
+ * read on demand, `polite` for one the person waits on (a count-in, a tuner's
5
+ * note).
6
+ */
7
+ export type ReadoutLive = "off" | "polite";
8
+ /**
9
+ * The attributes of a readout's root element, keyed by their HTML attribute
10
+ * names.
11
+ */
12
+ export type ReadoutAttributes = {
13
+ role: "group";
14
+ "aria-label": string;
15
+ "aria-live"?: "polite";
16
+ "aria-atomic"?: "true";
17
+ "data-tone"?: string;
18
+ };
19
+ /** Input of {@link readoutAttributes}. */
20
+ export type ReadoutAttributesInput = {
21
+ /** What the value is: `"Tempo"`, `"Bar"`. */
22
+ label: string;
23
+ tone?: ControlTone;
24
+ /** Defaults to `off`. */
25
+ live?: ReadoutLive;
26
+ };
27
+ /**
28
+ * The attributes of a readout, a lit value under a small caption like a
29
+ * hardware display's. It is a labelled group: `label` names it once, so the
30
+ * caption drawn inside must be hidden from assistive technology, and the value
31
+ * is its text content. A live readout is announced whole on each change.
32
+ *
33
+ * Time complexity: O(1). Memory: O(1).
34
+ *
35
+ * @example
36
+ * readoutAttributes({ label: "Tempo", live: "polite" });
37
+ * // { role: "group", "aria-label": "Tempo", "aria-live": "polite",
38
+ * // "aria-atomic": "true" }
39
+ */
40
+ export declare function readoutAttributes(input: ReadoutAttributesInput): ReadoutAttributes;
41
+ //# sourceMappingURL=readout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readout.d.ts","sourceRoot":"","sources":["../../src/readout/readout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,yBAAyB;IACzB,IAAI,CAAC,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,sBAAsB,GAC3B,iBAAiB,CAYnB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The attributes of a readout, a lit value under a small caption like a
3
+ * hardware display's. It is a labelled group: `label` names it once, so the
4
+ * caption drawn inside must be hidden from assistive technology, and the value
5
+ * is its text content. A live readout is announced whole on each change.
6
+ *
7
+ * Time complexity: O(1). Memory: O(1).
8
+ *
9
+ * @example
10
+ * readoutAttributes({ label: "Tempo", live: "polite" });
11
+ * // { role: "group", "aria-label": "Tempo", "aria-live": "polite",
12
+ * // "aria-atomic": "true" }
13
+ */
14
+ export function readoutAttributes(input) {
15
+ const { label, tone, live = "off" } = input;
16
+ const attributes = { role: "group", "aria-label": label };
17
+ if (live === "polite") {
18
+ attributes["aria-live"] = "polite";
19
+ attributes["aria-atomic"] = "true";
20
+ }
21
+ if (tone !== undefined) {
22
+ attributes["data-tone"] = tone;
23
+ }
24
+ return attributes;
25
+ }
26
+ //# sourceMappingURL=readout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readout.js","sourceRoot":"","sources":["../../src/readout/readout.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,UAAU,GAAsB,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC7E,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvB,UAAU,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC;QACnC,UAAU,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;IACpC,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;IAChC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SliderRange } from "./slider-range.js";
2
+ /**
3
+ * `value` kept inside `range`, `NaN` at its minimum: what a slider draws and
4
+ * announces for a value the caller let drift outside.
5
+ */
6
+ export declare function clampedSliderValue_(value: number, range: SliderRange): number;
7
+ //# sourceMappingURL=_clamped-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_clamped-value.d.ts","sourceRoot":"","sources":["../../src/slider/_clamped-value.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE7E"}
@@ -0,0 +1,9 @@
1
+ import { clamp } from "@ac-kit/core";
2
+ /**
3
+ * `value` kept inside `range`, `NaN` at its minimum: what a slider draws and
4
+ * announces for a value the caller let drift outside.
5
+ */
6
+ export function clampedSliderValue_(value, range) {
7
+ return Number.isNaN(value) ? range.min : clamp(value, range.min, range.max);
8
+ }
9
+ //# sourceMappingURL=_clamped-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_clamped-value.js","sourceRoot":"","sources":["../../src/slider/_clamped-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAIrC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,KAAkB;IACpE,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { SliderRange } from "./slider-range.js";
2
+ /**
3
+ * The ARIA attributes of a control with the WAI-ARIA `slider` role, keyed by
4
+ * their HTML attribute names so an adapter can spread them onto the element.
5
+ */
6
+ export type SliderAttributes = {
7
+ role: "slider";
8
+ "aria-label"?: string;
9
+ "aria-valuemin": number;
10
+ "aria-valuemax": number;
11
+ "aria-valuenow": number;
12
+ "aria-valuetext": string;
13
+ "aria-orientation"?: "horizontal" | "vertical";
14
+ "aria-disabled"?: "true";
15
+ };
16
+ /** Input of {@link sliderAttributes}. */
17
+ export type SliderAttributesInput = {
18
+ /** Its accessible name; omit when the element is labelled by another. */
19
+ label?: string;
20
+ /**
21
+ * The value shown, including one a gesture has not committed yet. Announced
22
+ * as `aria-valuenow` kept inside the range (`NaN` at its minimum); give
23
+ * `valueText` for the same clamped value.
24
+ */
25
+ value: number;
26
+ range: SliderRange;
27
+ /** The value as a person reads it: `"80 %"`, `"-3 dB"`, `"C♯"`. */
28
+ valueText: string;
29
+ /** Omit for a control with no axis of its own, such as a knob. */
30
+ orientation?: "horizontal" | "vertical";
31
+ disabled?: boolean;
32
+ };
33
+ /**
34
+ * The `slider` role and its value attributes, for a knob or a slider: what
35
+ * assistive technology announces, and what every adapter renders the same way.
36
+ *
37
+ * Time complexity: O(1). Memory: O(1).
38
+ *
39
+ * @example
40
+ * sliderAttributes({
41
+ * label: "Tempo",
42
+ * value: 80,
43
+ * range: { min: 50, max: 100, step: 1 },
44
+ * valueText: "80 %",
45
+ * });
46
+ * // { role: "slider", "aria-label": "Tempo", "aria-valuemin": 50,
47
+ * // "aria-valuemax": 100, "aria-valuenow": 80, "aria-valuetext": "80 %" }
48
+ */
49
+ export declare function sliderAttributes(input: SliderAttributesInput): SliderAttributes;
50
+ //# sourceMappingURL=slider-attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-attributes.d.ts","sourceRoot":"","sources":["../../src/slider/slider-attributes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IACnC,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,CAAC;IACnB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,qBAAqB,GAC1B,gBAAgB,CAoBlB"}
@@ -0,0 +1,38 @@
1
+ import { clampedSliderValue_ } from "./_clamped-value.js";
2
+ /**
3
+ * The `slider` role and its value attributes, for a knob or a slider: what
4
+ * assistive technology announces, and what every adapter renders the same way.
5
+ *
6
+ * Time complexity: O(1). Memory: O(1).
7
+ *
8
+ * @example
9
+ * sliderAttributes({
10
+ * label: "Tempo",
11
+ * value: 80,
12
+ * range: { min: 50, max: 100, step: 1 },
13
+ * valueText: "80 %",
14
+ * });
15
+ * // { role: "slider", "aria-label": "Tempo", "aria-valuemin": 50,
16
+ * // "aria-valuemax": 100, "aria-valuenow": 80, "aria-valuetext": "80 %" }
17
+ */
18
+ export function sliderAttributes(input) {
19
+ const { label, value, range, valueText, orientation, disabled } = input;
20
+ const attributes = {
21
+ role: "slider",
22
+ "aria-valuemin": range.min,
23
+ "aria-valuemax": range.max,
24
+ "aria-valuenow": clampedSliderValue_(value, range),
25
+ "aria-valuetext": valueText,
26
+ };
27
+ if (label !== undefined) {
28
+ attributes["aria-label"] = label;
29
+ }
30
+ if (orientation !== undefined) {
31
+ attributes["aria-orientation"] = orientation;
32
+ }
33
+ if (disabled === true) {
34
+ attributes["aria-disabled"] = "true";
35
+ }
36
+ return attributes;
37
+ }
38
+ //# sourceMappingURL=slider-attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-attributes.js","sourceRoot":"","sources":["../../src/slider/slider-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAoC1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAA4B;IAE5B,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,QAAQ;QACd,eAAe,EAAE,KAAK,CAAC,GAAG;QAC1B,eAAe,EAAE,KAAK,CAAC,GAAG;QAC1B,eAAe,EAAE,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC;QAClD,gBAAgB,EAAE,SAAS;KAC3B,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,UAAU,CAAC,kBAAkB,CAAC,GAAG,WAAW,CAAC;IAC9C,CAAC;IACD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACtC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The values a slider-like control takes, as WAI-ARIA states them
3
+ * (`aria-valuemin`, `aria-valuemax`) plus its step: from `min` to `max` in
4
+ * steps of `step` counted from `min`. Both ends are always reachable, even when
5
+ * `max` is not on the grid of steps.
6
+ */
7
+ export type SliderRange = {
8
+ min: number;
9
+ /** Above `min`. */
10
+ max: number;
11
+ /** Greater than zero. */
12
+ step: number;
13
+ };
14
+ /**
15
+ * The value a slider settles on for `value`: the nearest step from `range.min`
16
+ * (`quantize`), kept within the range. A value at or past an end gives that
17
+ * end, so `max` stays reachable when the steps do not land on it, as the End
18
+ * key requires.
19
+ *
20
+ * `NaN` gives `range.min`.
21
+ *
22
+ * Time complexity: O(1). Memory: O(1).
23
+ *
24
+ * @example
25
+ * snapSliderValue(0.73, { min: 0.5, max: 1, step: 0.05 }); // 0.75
26
+ * snapSliderValue(10, { min: 0, max: 10, step: 3 }); // 10
27
+ *
28
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
29
+ * zero.
30
+ */
31
+ export declare function snapSliderValue(value: number, range: SliderRange): number;
32
+ /**
33
+ * Where `value` sits along a slider, from 0 at `min` to 1 at `max`, clamped:
34
+ * for placing a thumb, a fill or a knob's pointer.
35
+ *
36
+ * Time complexity: O(1). Memory: O(1).
37
+ *
38
+ * @example
39
+ * sliderFraction(75, { min: 50, max: 100, step: 1 }); // 0.5
40
+ *
41
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
42
+ * zero.
43
+ */
44
+ export declare function sliderFraction(value: number, range: SliderRange): number;
45
+ /**
46
+ * The value at `fraction` of a slider's travel, snapped as
47
+ * {@link snapSliderValue} does: the inverse of {@link sliderFraction} up to the
48
+ * step.
49
+ *
50
+ * Time complexity: O(1). Memory: O(1).
51
+ *
52
+ * @example
53
+ * sliderValueAt(0.333, { min: 0, max: 100, step: 5 }); // 35
54
+ *
55
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
56
+ * zero.
57
+ */
58
+ export declare function sliderValueAt(fraction: number, range: SliderRange): number;
59
+ //# sourceMappingURL=slider-range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-range.d.ts","sourceRoot":"","sources":["../../src/slider/slider-range.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAiBF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAWzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAIxE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE1E"}
@@ -0,0 +1,73 @@
1
+ import { clamp, describeValue } from "@ac-kit/core";
2
+ import { inverseLerp, lerp, quantize } from "@ac-kit/math-scalar";
3
+ /** @throws {RangeError} When the range is empty, inverted or has no step. */
4
+ function assertSliderRange_(range) {
5
+ const { min, max, step } = range;
6
+ if (!Number.isFinite(min) || !Number.isFinite(max) || !(max > min)) {
7
+ throw new RangeError(`A slider range needs finite ends with max > min, got [${describeValue(min)}, ${describeValue(max)}].`);
8
+ }
9
+ if (!Number.isFinite(step) || !(step > 0)) {
10
+ throw new RangeError(`A slider range needs a finite step above zero, got ${describeValue(step)}.`);
11
+ }
12
+ }
13
+ /**
14
+ * The value a slider settles on for `value`: the nearest step from `range.min`
15
+ * (`quantize`), kept within the range. A value at or past an end gives that
16
+ * end, so `max` stays reachable when the steps do not land on it, as the End
17
+ * key requires.
18
+ *
19
+ * `NaN` gives `range.min`.
20
+ *
21
+ * Time complexity: O(1). Memory: O(1).
22
+ *
23
+ * @example
24
+ * snapSliderValue(0.73, { min: 0.5, max: 1, step: 0.05 }); // 0.75
25
+ * snapSliderValue(10, { min: 0, max: 10, step: 3 }); // 10
26
+ *
27
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
28
+ * zero.
29
+ */
30
+ export function snapSliderValue(value, range) {
31
+ assertSliderRange_(range);
32
+ const { min, max, step } = range;
33
+ if (Number.isNaN(value) || value <= min) {
34
+ return min;
35
+ }
36
+ if (value >= max) {
37
+ return max;
38
+ }
39
+ return clamp(quantize(value, step, min), min, max);
40
+ }
41
+ /**
42
+ * Where `value` sits along a slider, from 0 at `min` to 1 at `max`, clamped:
43
+ * for placing a thumb, a fill or a knob's pointer.
44
+ *
45
+ * Time complexity: O(1). Memory: O(1).
46
+ *
47
+ * @example
48
+ * sliderFraction(75, { min: 50, max: 100, step: 1 }); // 0.5
49
+ *
50
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
51
+ * zero.
52
+ */
53
+ export function sliderFraction(value, range) {
54
+ assertSliderRange_(range);
55
+ return clamp(inverseLerp(range.min, range.max, value), 0, 1);
56
+ }
57
+ /**
58
+ * The value at `fraction` of a slider's travel, snapped as
59
+ * {@link snapSliderValue} does: the inverse of {@link sliderFraction} up to the
60
+ * step.
61
+ *
62
+ * Time complexity: O(1). Memory: O(1).
63
+ *
64
+ * @example
65
+ * sliderValueAt(0.333, { min: 0, max: 100, step: 5 }); // 35
66
+ *
67
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
68
+ * zero.
69
+ */
70
+ export function sliderValueAt(fraction, range) {
71
+ return snapSliderValue(lerp(range.min, range.max, fraction), range);
72
+ }
73
+ //# sourceMappingURL=slider-range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-range.js","sourceRoot":"","sources":["../../src/slider/slider-range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAgBlE,6EAA6E;AAC7E,SAAS,kBAAkB,CAAC,KAAkB;IAC7C,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,UAAU,CACnB,yDAAyD,aAAa,CAAC,GAAG,CAAC,KAAK,aAAa,CAAC,GAAG,CAAC,IAAI,CACtG,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,UAAU,CACnB,sDAAsD,aAAa,CAAC,IAAI,CAAC,GAAG,CAC5E,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,KAAkB;IAChE,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACjC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACzC,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAkB;IAC/D,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAE1B,OAAO,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,KAAkB;IACjE,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type SliderRange } from "./slider-range.js";
2
+ /**
3
+ * Which way a slider travels. A vertical one has its maximum at the top, as on
4
+ * a mixing desk.
5
+ */
6
+ export type SliderOrientation = "horizontal" | "vertical";
7
+ /**
8
+ * A slider's track along its axis, in the pointer's coordinates (the
9
+ * coordinates of the position passed to {@link sliderTrackValueAt}): its leading
10
+ * edge (left, or top for a vertical slider), its length, and the thumb's length
11
+ * along the same axis. The thumb stays inside the track, so its centre travels
12
+ * `length - thumbLength`.
13
+ */
14
+ export type SliderTrack = {
15
+ start: number;
16
+ length: number;
17
+ thumbLength: number;
18
+ };
19
+ /**
20
+ * The value under a pointer at `position` along a slider's track — the x
21
+ * coordinate for a horizontal slider, the y coordinate for a vertical one —
22
+ * snapped as {@link sliderValueAt} does. A position past either end gives that
23
+ * end. A track no longer than its thumb has no travel: the half the position
24
+ * falls in decides between `min` and `max`.
25
+ *
26
+ * Time complexity: O(1). Memory: O(1).
27
+ *
28
+ * @example
29
+ * const track = { start: 100, length: 220, thumbLength: 20 };
30
+ * sliderTrackValueAt(210, track, { min: 0, max: 100, step: 1 }, "horizontal"); // 50
31
+ * sliderTrackValueAt(160, track, { min: 0, max: 100, step: 1 }, "vertical"); // 75
32
+ *
33
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
34
+ * zero.
35
+ */
36
+ export declare function sliderTrackValueAt(position: number, track: SliderTrack, range: SliderRange, orientation: SliderOrientation): number;
37
+ //# sourceMappingURL=slider-track.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-track.d.ts","sourceRoot":"","sources":["../../src/slider/slider-track.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,WAAW,EAClB,WAAW,EAAE,iBAAiB,GAC5B,MAAM,CAkBR"}
@@ -0,0 +1,35 @@
1
+ import { clamp } from "@ac-kit/core";
2
+ import { inverseLerp } from "@ac-kit/math-scalar";
3
+ import { sliderValueAt } from "./slider-range.js";
4
+ /**
5
+ * The value under a pointer at `position` along a slider's track — the x
6
+ * coordinate for a horizontal slider, the y coordinate for a vertical one —
7
+ * snapped as {@link sliderValueAt} does. A position past either end gives that
8
+ * end. A track no longer than its thumb has no travel: the half the position
9
+ * falls in decides between `min` and `max`.
10
+ *
11
+ * Time complexity: O(1). Memory: O(1).
12
+ *
13
+ * @example
14
+ * const track = { start: 100, length: 220, thumbLength: 20 };
15
+ * sliderTrackValueAt(210, track, { min: 0, max: 100, step: 1 }, "horizontal"); // 50
16
+ * sliderTrackValueAt(160, track, { min: 0, max: 100, step: 1 }, "vertical"); // 75
17
+ *
18
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
19
+ * zero.
20
+ */
21
+ export function sliderTrackValueAt(position, track, range, orientation) {
22
+ const { start, length, thumbLength } = track;
23
+ // The thumb's centre travels between these, so they are the ends.
24
+ const low = start + thumbLength / 2;
25
+ const high = start + length - thumbLength / 2;
26
+ if (!(high > low)) {
27
+ const isPastMiddle = position >= start + length / 2;
28
+ return sliderValueAt(Number(orientation === "vertical" ? !isPastMiddle : isPastMiddle), range);
29
+ }
30
+ const fraction = orientation === "vertical"
31
+ ? inverseLerp(high, low, position)
32
+ : inverseLerp(low, high, position);
33
+ return sliderValueAt(clamp(fraction, 0, 1), range);
34
+ }
35
+ //# sourceMappingURL=slider-track.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider-track.js","sourceRoot":"","sources":["../../src/slider/slider-track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAoB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAqBpE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CACjC,QAAgB,EAChB,KAAkB,EAClB,KAAkB,EAClB,WAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAC7C,kEAAkE;IAClE,MAAM,GAAG,GAAG,KAAK,GAAG,WAAW,GAAG,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,YAAY,GAAG,QAAQ,IAAI,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;QACpD,OAAO,aAAa,CACnB,MAAM,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,EACjE,KAAK,CACL,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GACb,WAAW,KAAK,UAAU;QACzB,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,CAAC;QAClC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAErC,OAAO,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type SliderRange } from "./slider-range.js";
2
+ /** Options of {@link steppedValue}. */
3
+ export type SteppedValueOptions = {
4
+ /** What Page Up and Page Down move by. Defaults to ten steps. */
5
+ largeStep?: number;
6
+ };
7
+ /**
8
+ * The value a key moves a slider-like control to, per the WAI-ARIA slider
9
+ * pattern: Arrow Up and Arrow Right one step up, Arrow Down and Arrow Left one
10
+ * down, Page Up and Page Down a large step, Home and End to the ends. The
11
+ * result is snapped ({@link snapSliderValue}), so stepping past an end gives
12
+ * that end.
13
+ *
14
+ * `undefined` for any other key, which the control should leave to the browser.
15
+ * A result equal to `value` means the key was a step key but the control is
16
+ * already at that end: consume the key, report no change.
17
+ *
18
+ * `key` is a `KeyboardEvent.key` value.
19
+ *
20
+ * Time complexity: O(1). Memory: O(1).
21
+ *
22
+ * @example
23
+ * steppedValue(80, "ArrowUp", { min: 50, max: 100, step: 1 }); // 81
24
+ * steppedValue(80, "PageDown", { min: 50, max: 100, step: 1 }); // 70
25
+ * steppedValue(80, "Tab", { min: 50, max: 100, step: 1 }); // undefined
26
+ *
27
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
28
+ * zero.
29
+ */
30
+ export declare function steppedValue(value: number, key: string, range: SliderRange, options?: SteppedValueOptions): number | undefined;
31
+ //# sourceMappingURL=stepped-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stepped-value.d.ts","sourceRoot":"","sources":["../../src/slider/stepped-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,mBAAmB,CAAC;AAEtE,uCAAuC;AACvC,MAAM,MAAM,mBAAmB,GAAG;IACjC,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,MAAM,GAAG,SAAS,CA8BpB"}
@@ -0,0 +1,55 @@
1
+ import { snapSliderValue } from "./slider-range.js";
2
+ /**
3
+ * The value a key moves a slider-like control to, per the WAI-ARIA slider
4
+ * pattern: Arrow Up and Arrow Right one step up, Arrow Down and Arrow Left one
5
+ * down, Page Up and Page Down a large step, Home and End to the ends. The
6
+ * result is snapped ({@link snapSliderValue}), so stepping past an end gives
7
+ * that end.
8
+ *
9
+ * `undefined` for any other key, which the control should leave to the browser.
10
+ * A result equal to `value` means the key was a step key but the control is
11
+ * already at that end: consume the key, report no change.
12
+ *
13
+ * `key` is a `KeyboardEvent.key` value.
14
+ *
15
+ * Time complexity: O(1). Memory: O(1).
16
+ *
17
+ * @example
18
+ * steppedValue(80, "ArrowUp", { min: 50, max: 100, step: 1 }); // 81
19
+ * steppedValue(80, "PageDown", { min: 50, max: 100, step: 1 }); // 70
20
+ * steppedValue(80, "Tab", { min: 50, max: 100, step: 1 }); // undefined
21
+ *
22
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
23
+ * zero.
24
+ */
25
+ export function steppedValue(value, key, range, options) {
26
+ const { min, max, step } = range;
27
+ const largeStep = options?.largeStep ?? step * 10;
28
+ let next;
29
+ switch (key) {
30
+ case "ArrowUp":
31
+ case "ArrowRight":
32
+ next = value + step;
33
+ break;
34
+ case "ArrowDown":
35
+ case "ArrowLeft":
36
+ next = value - step;
37
+ break;
38
+ case "PageUp":
39
+ next = value + largeStep;
40
+ break;
41
+ case "PageDown":
42
+ next = value - largeStep;
43
+ break;
44
+ case "Home":
45
+ next = min;
46
+ break;
47
+ case "End":
48
+ next = max;
49
+ break;
50
+ default:
51
+ return undefined;
52
+ }
53
+ return snapSliderValue(next, range);
54
+ }
55
+ //# sourceMappingURL=stepped-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stepped-value.js","sourceRoot":"","sources":["../../src/slider/stepped-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQtE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAC3B,KAAa,EACb,GAAW,EACX,KAAkB,EAClB,OAA6B;IAE7B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,IAAI,GAAG,EAAE,CAAC;IAClD,IAAI,IAAY,CAAC;IACjB,QAAQ,GAAG,EAAE,CAAC;QACb,KAAK,SAAS,CAAC;QACf,KAAK,YAAY;YAChB,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;YACpB,MAAM;QACP,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW;YACf,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;YACpB,MAAM;QACP,KAAK,QAAQ;YACZ,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;YACzB,MAAM;QACP,KAAK,UAAU;YACd,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;YACzB,MAAM;QACP,KAAK,MAAM;YACV,IAAI,GAAG,GAAG,CAAC;YACX,MAAM;QACP,KAAK,KAAK;YACT,IAAI,GAAG,GAAG,CAAC;YACX,MAAM;QACP;YACC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The attributes of a switch, keyed by their HTML attribute names: a `button`
3
+ * announced as a switch, on or off, and the state the stylesheet draws it by.
4
+ */
5
+ export type SwitchAttributes = {
6
+ role: "switch";
7
+ "aria-checked": "true" | "false";
8
+ "aria-disabled"?: "true";
9
+ "data-state": "on" | "off";
10
+ };
11
+ /** Input of {@link switchAttributes}. */
12
+ export type SwitchAttributesInput = {
13
+ isOn: boolean;
14
+ disabled?: boolean;
15
+ };
16
+ /**
17
+ * The attributes of a switch (WAI-ARIA switch pattern): a setting that takes
18
+ * effect as soon as it is flipped, unlike a checkbox in a form that is
19
+ * submitted later. Render it on a native `<button type="button">`, whose Space
20
+ * and Enter activation it relies on; activating it reports `!isOn` and leaves
21
+ * the caller to pass the new state back.
22
+ *
23
+ * Time complexity: O(1). Memory: O(1).
24
+ *
25
+ * @example
26
+ * switchAttributes({ isOn: true });
27
+ * // { role: "switch", "aria-checked": "true", "data-state": "on" }
28
+ */
29
+ export declare function switchAttributes(input: SwitchAttributesInput): SwitchAttributes;
30
+ //# sourceMappingURL=switch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,IAAI,GAAG,KAAK,CAAC;CAC3B,CAAC;AAEF,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,qBAAqB,GAC1B,gBAAgB,CAYlB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The attributes of a switch (WAI-ARIA switch pattern): a setting that takes
3
+ * effect as soon as it is flipped, unlike a checkbox in a form that is
4
+ * submitted later. Render it on a native `<button type="button">`, whose Space
5
+ * and Enter activation it relies on; activating it reports `!isOn` and leaves
6
+ * the caller to pass the new state back.
7
+ *
8
+ * Time complexity: O(1). Memory: O(1).
9
+ *
10
+ * @example
11
+ * switchAttributes({ isOn: true });
12
+ * // { role: "switch", "aria-checked": "true", "data-state": "on" }
13
+ */
14
+ export function switchAttributes(input) {
15
+ const { isOn, disabled = false } = input;
16
+ const attributes = {
17
+ role: "switch",
18
+ "aria-checked": isOn ? "true" : "false",
19
+ "data-state": isOn ? "on" : "off",
20
+ };
21
+ if (disabled) {
22
+ attributes["aria-disabled"] = "true";
23
+ }
24
+ return attributes;
25
+ }
26
+ //# sourceMappingURL=switch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAA4B;IAE5B,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IACzC,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,QAAQ;QACd,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QACvC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;KACjC,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACd,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACtC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}