@ac-kit/ui-common 0.0.0-stage → 0.2.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 (205) hide show
  1. package/CHANGELOG.md +244 -0
  2. package/LICENSE +28 -0
  3. package/README.md +633 -2
  4. package/dist/anchored/anchored.d.ts +19 -0
  5. package/dist/anchored/anchored.d.ts.map +1 -0
  6. package/dist/anchored/anchored.js +2 -0
  7. package/dist/anchored/anchored.js.map +1 -0
  8. package/dist/button/button.d.ts +35 -0
  9. package/dist/button/button.d.ts.map +1 -0
  10. package/dist/button/button.js +22 -0
  11. package/dist/button/button.js.map +1 -0
  12. package/dist/dialog/dialog.d.ts +33 -0
  13. package/dist/dialog/dialog.d.ts.map +1 -0
  14. package/dist/dialog/dialog.js +23 -0
  15. package/dist/dialog/dialog.js.map +1 -0
  16. package/dist/focus/owns-arrow-keys.d.ts +31 -0
  17. package/dist/focus/owns-arrow-keys.d.ts.map +1 -0
  18. package/dist/focus/owns-arrow-keys.js +64 -0
  19. package/dist/focus/owns-arrow-keys.js.map +1 -0
  20. package/dist/focus/roving-focus.d.ts +34 -0
  21. package/dist/focus/roving-focus.d.ts.map +1 -0
  22. package/dist/focus/roving-focus.js +72 -0
  23. package/dist/focus/roving-focus.js.map +1 -0
  24. package/dist/focus/typeahead.d.ts +112 -0
  25. package/dist/focus/typeahead.d.ts.map +1 -0
  26. package/dist/focus/typeahead.js +178 -0
  27. package/dist/focus/typeahead.js.map +1 -0
  28. package/dist/index.d.ts +26 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +26 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/knob/knob.d.ts +106 -0
  33. package/dist/knob/knob.d.ts.map +1 -0
  34. package/dist/knob/knob.js +116 -0
  35. package/dist/knob/knob.js.map +1 -0
  36. package/dist/menu/menu.d.ts +157 -0
  37. package/dist/menu/menu.d.ts.map +1 -0
  38. package/dist/menu/menu.js +162 -0
  39. package/dist/menu/menu.js.map +1 -0
  40. package/dist/meter/meter.d.ts +63 -0
  41. package/dist/meter/meter.d.ts.map +1 -0
  42. package/dist/meter/meter.js +57 -0
  43. package/dist/meter/meter.js.map +1 -0
  44. package/dist/preact/_anchor.d.ts +13 -0
  45. package/dist/preact/_anchor.d.ts.map +1 -0
  46. package/dist/preact/_anchor.js +39 -0
  47. package/dist/preact/_anchor.js.map +1 -0
  48. package/dist/preact/_dom.d.ts +14 -0
  49. package/dist/preact/_dom.d.ts.map +1 -0
  50. package/dist/preact/_dom.js +31 -0
  51. package/dist/preact/_dom.js.map +1 -0
  52. package/dist/preact/_live-announcer.d.ts +26 -0
  53. package/dist/preact/_live-announcer.d.ts.map +1 -0
  54. package/dist/preact/_live-announcer.js +101 -0
  55. package/dist/preact/_live-announcer.js.map +1 -0
  56. package/dist/preact/button.d.ts +40 -0
  57. package/dist/preact/button.d.ts.map +1 -0
  58. package/dist/preact/button.js +22 -0
  59. package/dist/preact/button.js.map +1 -0
  60. package/dist/preact/dialog.d.ts +43 -0
  61. package/dist/preact/dialog.d.ts.map +1 -0
  62. package/dist/preact/dialog.js +89 -0
  63. package/dist/preact/dialog.js.map +1 -0
  64. package/dist/preact/index.d.ts +20 -0
  65. package/dist/preact/index.d.ts.map +1 -0
  66. package/dist/preact/index.js +20 -0
  67. package/dist/preact/index.js.map +1 -0
  68. package/dist/preact/join-classes.d.ts +10 -0
  69. package/dist/preact/join-classes.d.ts.map +1 -0
  70. package/dist/preact/join-classes.js +12 -0
  71. package/dist/preact/join-classes.js.map +1 -0
  72. package/dist/preact/knob.d.ts +51 -0
  73. package/dist/preact/knob.d.ts.map +1 -0
  74. package/dist/preact/knob.js +144 -0
  75. package/dist/preact/knob.js.map +1 -0
  76. package/dist/preact/menu-button.d.ts +117 -0
  77. package/dist/preact/menu-button.d.ts.map +1 -0
  78. package/dist/preact/menu-button.js +330 -0
  79. package/dist/preact/menu-button.js.map +1 -0
  80. package/dist/preact/meter.d.ts +34 -0
  81. package/dist/preact/meter.d.ts.map +1 -0
  82. package/dist/preact/meter.js +21 -0
  83. package/dist/preact/meter.js.map +1 -0
  84. package/dist/preact/progress-ring.d.ts +42 -0
  85. package/dist/preact/progress-ring.d.ts.map +1 -0
  86. package/dist/preact/progress-ring.js +26 -0
  87. package/dist/preact/progress-ring.js.map +1 -0
  88. package/dist/preact/radio-group.d.ts +50 -0
  89. package/dist/preact/radio-group.d.ts.map +1 -0
  90. package/dist/preact/radio-group.js +42 -0
  91. package/dist/preact/radio-group.js.map +1 -0
  92. package/dist/preact/readout.d.ts +22 -0
  93. package/dist/preact/readout.d.ts.map +1 -0
  94. package/dist/preact/readout.js +13 -0
  95. package/dist/preact/readout.js.map +1 -0
  96. package/dist/preact/slider.d.ts +40 -0
  97. package/dist/preact/slider.d.ts.map +1 -0
  98. package/dist/preact/slider.js +164 -0
  99. package/dist/preact/slider.js.map +1 -0
  100. package/dist/preact/spin-button.d.ts +67 -0
  101. package/dist/preact/spin-button.d.ts.map +1 -0
  102. package/dist/preact/spin-button.js +132 -0
  103. package/dist/preact/spin-button.js.map +1 -0
  104. package/dist/preact/switch.d.ts +25 -0
  105. package/dist/preact/switch.d.ts.map +1 -0
  106. package/dist/preact/switch.js +19 -0
  107. package/dist/preact/switch.js.map +1 -0
  108. package/dist/preact/tabs.d.ts +97 -0
  109. package/dist/preact/tabs.d.ts.map +1 -0
  110. package/dist/preact/tabs.js +264 -0
  111. package/dist/preact/tabs.js.map +1 -0
  112. package/dist/preact/toaster.d.ts +43 -0
  113. package/dist/preact/toaster.d.ts.map +1 -0
  114. package/dist/preact/toaster.js +356 -0
  115. package/dist/preact/toaster.js.map +1 -0
  116. package/dist/preact/toggle-button.d.ts +26 -0
  117. package/dist/preact/toggle-button.d.ts.map +1 -0
  118. package/dist/preact/toggle-button.js +16 -0
  119. package/dist/preact/toggle-button.js.map +1 -0
  120. package/dist/preact/toolbar.d.ts +24 -0
  121. package/dist/preact/toolbar.d.ts.map +1 -0
  122. package/dist/preact/toolbar.js +142 -0
  123. package/dist/preact/toolbar.js.map +1 -0
  124. package/dist/preact/tooltip.d.ts +67 -0
  125. package/dist/preact/tooltip.d.ts.map +1 -0
  126. package/dist/preact/tooltip.js +165 -0
  127. package/dist/preact/tooltip.js.map +1 -0
  128. package/dist/preact/tree.d.ts +93 -0
  129. package/dist/preact/tree.d.ts.map +1 -0
  130. package/dist/preact/tree.js +399 -0
  131. package/dist/preact/tree.js.map +1 -0
  132. package/dist/preact/use-element-binding.d.ts +32 -0
  133. package/dist/preact/use-element-binding.d.ts.map +1 -0
  134. package/dist/preact/use-element-binding.js +51 -0
  135. package/dist/preact/use-element-binding.js.map +1 -0
  136. package/dist/progress/progress.d.ts +51 -0
  137. package/dist/progress/progress.d.ts.map +1 -0
  138. package/dist/progress/progress.js +43 -0
  139. package/dist/progress/progress.js.map +1 -0
  140. package/dist/readout/readout.d.ts +41 -0
  141. package/dist/readout/readout.d.ts.map +1 -0
  142. package/dist/readout/readout.js +26 -0
  143. package/dist/readout/readout.js.map +1 -0
  144. package/dist/slider/_clamped-value.d.ts +7 -0
  145. package/dist/slider/_clamped-value.d.ts.map +1 -0
  146. package/dist/slider/_clamped-value.js +9 -0
  147. package/dist/slider/_clamped-value.js.map +1 -0
  148. package/dist/slider/slider-attributes.d.ts +50 -0
  149. package/dist/slider/slider-attributes.d.ts.map +1 -0
  150. package/dist/slider/slider-attributes.js +38 -0
  151. package/dist/slider/slider-attributes.js.map +1 -0
  152. package/dist/slider/slider-range.d.ts +59 -0
  153. package/dist/slider/slider-range.d.ts.map +1 -0
  154. package/dist/slider/slider-range.js +73 -0
  155. package/dist/slider/slider-range.js.map +1 -0
  156. package/dist/slider/slider-track.d.ts +37 -0
  157. package/dist/slider/slider-track.d.ts.map +1 -0
  158. package/dist/slider/slider-track.js +35 -0
  159. package/dist/slider/slider-track.js.map +1 -0
  160. package/dist/slider/stepped-value.d.ts +31 -0
  161. package/dist/slider/stepped-value.d.ts.map +1 -0
  162. package/dist/slider/stepped-value.js +55 -0
  163. package/dist/slider/stepped-value.js.map +1 -0
  164. package/dist/spin-button/spin-button.d.ts +110 -0
  165. package/dist/spin-button/spin-button.d.ts.map +1 -0
  166. package/dist/spin-button/spin-button.js +179 -0
  167. package/dist/spin-button/spin-button.js.map +1 -0
  168. package/dist/switch/switch.d.ts +30 -0
  169. package/dist/switch/switch.d.ts.map +1 -0
  170. package/dist/switch/switch.js +26 -0
  171. package/dist/switch/switch.js.map +1 -0
  172. package/dist/tabs/tabs.d.ts +157 -0
  173. package/dist/tabs/tabs.d.ts.map +1 -0
  174. package/dist/tabs/tabs.js +120 -0
  175. package/dist/tabs/tabs.js.map +1 -0
  176. package/dist/toast/toast-queue.d.ts +212 -0
  177. package/dist/toast/toast-queue.d.ts.map +1 -0
  178. package/dist/toast/toast-queue.js +290 -0
  179. package/dist/toast/toast-queue.js.map +1 -0
  180. package/dist/toast/toasts-obscure.d.ts +25 -0
  181. package/dist/toast/toasts-obscure.d.ts.map +1 -0
  182. package/dist/toast/toasts-obscure.js +30 -0
  183. package/dist/toast/toasts-obscure.js.map +1 -0
  184. package/dist/toggle-button/toggle-button.d.ts +44 -0
  185. package/dist/toggle-button/toggle-button.d.ts.map +1 -0
  186. package/dist/toggle-button/toggle-button.js +31 -0
  187. package/dist/toggle-button/toggle-button.js.map +1 -0
  188. package/dist/tone.d.ts +8 -0
  189. package/dist/tone.d.ts.map +1 -0
  190. package/dist/tone.js +2 -0
  191. package/dist/tone.js.map +1 -0
  192. package/dist/toolbar/toolbar.d.ts +35 -0
  193. package/dist/toolbar/toolbar.d.ts.map +1 -0
  194. package/dist/toolbar/toolbar.js +23 -0
  195. package/dist/toolbar/toolbar.js.map +1 -0
  196. package/dist/tooltip/tooltip.d.ts +183 -0
  197. package/dist/tooltip/tooltip.d.ts.map +1 -0
  198. package/dist/tooltip/tooltip.js +185 -0
  199. package/dist/tooltip/tooltip.js.map +1 -0
  200. package/dist/tree/tree.d.ts +302 -0
  201. package/dist/tree/tree.d.ts.map +1 -0
  202. package/dist/tree/tree.js +439 -0
  203. package/dist/tree/tree.js.map +1 -0
  204. package/package.json +110 -3
  205. package/styles.css +1883 -0
@@ -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,110 @@
1
+ /**
2
+ * The values a spin button takes: steps of `step` counted from `min` (else from
3
+ * `max`, else from 0), within `min` and `max` when it has them. Either bound
4
+ * may be absent, as WAI-ARIA allows for the `spinbutton` role (a quantity has a
5
+ * minimum and no maximum).
6
+ */
7
+ export type SpinButtonRange = {
8
+ readonly min?: number;
9
+ /** Above `min` when both are given. */
10
+ readonly max?: number;
11
+ /** Greater than zero. */
12
+ readonly step: number;
13
+ };
14
+ /** Options of {@link spinButtonValue}. */
15
+ export type SpinButtonValueOptions = {
16
+ /** What Page Up and Page Down move by. Defaults to ten steps. */
17
+ readonly largeStep?: number;
18
+ };
19
+ /**
20
+ * The value a spin button settles on for `value`, typed or stepped to: the
21
+ * nearest step, kept within the bounds it has. A value at or past a bound gives
22
+ * that bound, so a bound off the grid of steps stays reachable. With both
23
+ * bounds, this is {@link snapSliderValue}.
24
+ *
25
+ * `NaN` gives the origin of the steps (`min`, else `max`, else 0).
26
+ *
27
+ * Time complexity: O(1). Memory: O(1).
28
+ *
29
+ * @example
30
+ * snapSpinButtonValue(7.4, { min: 0, step: 0.5 }); // 7.5
31
+ * snapSpinButtonValue(-3, { min: 0, step: 1 }); // 0
32
+ * snapSpinButtonValue(1e6, { min: 0, step: 1 }); // 1000000: no maximum
33
+ *
34
+ * @throws {RangeError} When `step` is not above zero, a bound is not finite,
35
+ * `max` is not above `min`, or `value` is infinite towards a side with no
36
+ * bound.
37
+ */
38
+ export declare function snapSpinButtonValue(value: number, range: SpinButtonRange): number;
39
+ /**
40
+ * The value a key moves a spin button to (WAI-ARIA spinbutton pattern): Arrow
41
+ * Up one step up, Arrow Down one down, Page Up and Page Down a large step, Home
42
+ * to `min` and End to `max` when the range has them. The result is snapped
43
+ * ({@link snapSpinButtonValue}), so stepping past a bound gives that bound;
44
+ * with both bounds, this is {@link steppedValue}'s, without Arrow Left and Arrow
45
+ * Right, which move the caret in an editable field.
46
+ *
47
+ * `undefined` for any other key, Home without `min` and End without `max`:
48
+ * leave those to the browser. A result equal to `value` means the key was a
49
+ * step key but the value cannot move that way (at a bound, or a step that would
50
+ * overflow): consume the key, report no change.
51
+ *
52
+ * Time complexity: O(1). Memory: O(1).
53
+ *
54
+ * @example
55
+ * spinButtonValue(4, "ArrowUp", { min: 1, step: 1 }); // 5
56
+ * spinButtonValue(4, "PageDown", { min: 1, step: 1 }); // 1
57
+ * spinButtonValue(4, "End", { min: 1, step: 1 }); // undefined: no maximum
58
+ *
59
+ * @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue})
60
+ * or `largeStep` is not above zero.
61
+ */
62
+ export declare function spinButtonValue(value: number, key: string, range: SpinButtonRange, options?: SpinButtonValueOptions): number | undefined;
63
+ /**
64
+ * The ARIA attributes of a control with the WAI-ARIA `spinbutton` role, keyed
65
+ * by their HTML attribute names. `aria-valuemin` and `aria-valuemax` are
66
+ * present for the bounds the range has.
67
+ */
68
+ export type SpinButtonAttributes = {
69
+ role: "spinbutton";
70
+ "aria-label"?: string;
71
+ "aria-valuemin"?: number;
72
+ "aria-valuemax"?: number;
73
+ "aria-valuenow": number;
74
+ "aria-valuetext": string;
75
+ "aria-disabled"?: "true";
76
+ };
77
+ /** Input of {@link spinButtonAttributes}. */
78
+ export type SpinButtonAttributesInput = {
79
+ /** Its accessible name; omit when another element names it. */
80
+ label?: string;
81
+ /**
82
+ * Announced as `aria-valuenow` kept within the bounds (`NaN` at the origin of
83
+ * the steps); give `valueText` for the same value.
84
+ */
85
+ value: number;
86
+ range: SpinButtonRange;
87
+ /** The value as a person reads it: `"4 copies"`, `"80 %"`. */
88
+ valueText: string;
89
+ disabled?: boolean;
90
+ };
91
+ /**
92
+ * The `spinbutton` role and its value attributes: what assistive technology
93
+ * announces, and what every adapter renders the same way.
94
+ *
95
+ * Time complexity: O(1). Memory: O(1).
96
+ *
97
+ * @example
98
+ * spinButtonAttributes({
99
+ * label: "Copies",
100
+ * value: 4,
101
+ * range: { min: 1, step: 1 },
102
+ * valueText: "4",
103
+ * });
104
+ * // { role: "spinbutton", "aria-label": "Copies", "aria-valuemin": 1,
105
+ * // "aria-valuenow": 4, "aria-valuetext": "4" }
106
+ *
107
+ * @throws {RangeError} When the range is invalid ({@link snapSpinButtonValue}).
108
+ */
109
+ export declare function spinButtonAttributes(input: SpinButtonAttributesInput): SpinButtonAttributes;
110
+ //# sourceMappingURL=spin-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spin-button.d.ts","sourceRoot":"","sources":["../../src/spin-button/spin-button.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AA2BF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,GACpB,MAAM,CA8BR;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,sBAA2B,GAClC,MAAM,GAAG,SAAS,CA2CpB;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,yBAAyB,GAAG;IACvC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,yBAAyB,GAC9B,oBAAoB,CA6BtB"}