@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,178 @@
1
+ import { assertNonNegative, describeValue, isIntegerInRange, } from "@ac-kit/core";
2
+ /**
3
+ * The query a person types into a list to reach an item by its name (the
4
+ * WAI-ARIA typeahead of menus, listboxes and trees): the characters typed
5
+ * within `timeoutMs` of each other. Every time is passed in, in ms.
6
+ *
7
+ * @example
8
+ * const typeahead = new Typeahead();
9
+ * typeahead.type("c", 0); // "c"
10
+ * typeahead.type("h", 200); // "ch"
11
+ * typeahead.type("a", 900); // "a": the query timed out
12
+ */
13
+ export class Typeahead {
14
+ timeoutMs_;
15
+ query_ = "";
16
+ lastTime_ = Number.NEGATIVE_INFINITY;
17
+ /** @throws {RangeError} When `timeoutMs` is negative or not finite. */
18
+ constructor(options = {}) {
19
+ const { timeoutMs = 500 } = options;
20
+ assertNonNegative(timeoutMs, "timeoutMs");
21
+ this.timeoutMs_ = timeoutMs;
22
+ }
23
+ /**
24
+ * Whether a query is in progress at `time`: a character was typed less than
25
+ * `timeoutMs` before. A list lets Space extend the query then, rather than
26
+ * activate an item.
27
+ */
28
+ isActive(time) {
29
+ return this.query_ !== "" && time - this.lastTime_ < this.timeoutMs_;
30
+ }
31
+ /** Adds `character`, typed at `time`, and returns the query to look up. */
32
+ type(character, time) {
33
+ this.query_ = this.isActive(time) ? this.query_ + character : character;
34
+ this.lastTime_ = time;
35
+ return this.query_;
36
+ }
37
+ /** Forgets the query: the list closed, or an item was chosen. */
38
+ reset() {
39
+ this.query_ = "";
40
+ this.lastTime_ = Number.NEGATIVE_INFINITY;
41
+ }
42
+ /**
43
+ * Adds `character`, typed at `time`, and returns the item the query reaches
44
+ * among `labels` from `current` ({@link typeaheadIndex}): what a list does
45
+ * with each character typed.
46
+ *
47
+ * Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
48
+ * O(q).
49
+ *
50
+ * @example
51
+ * const typeahead = new Typeahead();
52
+ * typeahead.find("b", 0, ["Apple", "Banana", "Blueberry"], 0); // 1
53
+ * typeahead.find("l", 100, ["Apple", "Banana", "Blueberry"], 1); // 2
54
+ *
55
+ * @throws {RangeError} When `current` is not an index of `labels`.
56
+ */
57
+ find(character, time, labels, current, options) {
58
+ return typeaheadIndex(labels, current, this.type(character, time), options);
59
+ }
60
+ }
61
+ /**
62
+ * The item a typeahead query moves to among `labels`, per the WAI-ARIA
63
+ * practices: the next item after `current` whose name starts with a single
64
+ * character, going round, so typing it again cycles through those items (a
65
+ * repeated character, `"aaa"`, cycles likewise); for a longer query, the first
66
+ * from `current` on whose name starts with it, so the item stays while it
67
+ * matches. Without `current`, the search starts at the first item.
68
+ *
69
+ * Names are compared grapheme by grapheme, ignoring case and accents as the
70
+ * locale's collation does (`sensitivity: "base"`) and leading white space.
71
+ * `undefined` for an empty query or when no enabled item matches.
72
+ *
73
+ * Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
74
+ * O(q).
75
+ *
76
+ * @example
77
+ * typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "a"); // 1
78
+ * typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "apr"); // 1
79
+ * typeaheadIndex(["Éclair", "Fig"], 1, "e"); // 0
80
+ *
81
+ * @throws {RangeError} When `current` is not an index of `labels`.
82
+ */
83
+ export function typeaheadIndex(labels, current, query, options = {}) {
84
+ const count = labels.length;
85
+ if (current !== undefined && !isIntegerInRange(current, 0, count)) {
86
+ throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
87
+ }
88
+ const { locales, isDisabled } = options;
89
+ const segmenter = new Intl.Segmenter(locales, { granularity: "grapheme" });
90
+ const graphemes = Array.from(segmenter.segment(query), (segment) => segment.segment);
91
+ const first = graphemes[0];
92
+ if (first === undefined) {
93
+ return undefined;
94
+ }
95
+ const isRepeated = graphemes.every((grapheme) => grapheme === first);
96
+ const searched = isRepeated ? first : query;
97
+ const searchedLength = isRepeated ? 1 : graphemes.length;
98
+ const collator = new Intl.Collator(locales, {
99
+ usage: "search",
100
+ sensitivity: "base",
101
+ });
102
+ // A single character moves on from the current item; a longer query may
103
+ // keep it.
104
+ const start = current === undefined ? 0 : isRepeated ? current + 1 : current;
105
+ for (let visited = 0; visited < count; visited += 1) {
106
+ const index = (start + visited) % count;
107
+ if (isDisabled?.(index) === true) {
108
+ continue;
109
+ }
110
+ const prefix = graphemePrefix_(segmenter, labels[index].trimStart(), searchedLength);
111
+ if (collator.compare(prefix, searched) === 0) {
112
+ return index;
113
+ }
114
+ }
115
+ return undefined;
116
+ }
117
+ function graphemePrefix_(segmenter, text, length) {
118
+ let end = 0;
119
+ let taken = 0;
120
+ for (const { index, segment } of segmenter.segment(text)) {
121
+ if (taken === length) {
122
+ break;
123
+ }
124
+ end = index + segment.length;
125
+ taken += 1;
126
+ }
127
+ return text.slice(0, end);
128
+ }
129
+ const CONTROL_ = /^\p{Cc}$/u;
130
+ /**
131
+ * Whether a key types a character a typeahead takes: one grapheme, not a
132
+ * control character, without Ctrl, Alt or Meta (the browser's and the system's
133
+ * shortcuts). Shift passes, for capitals; so does Space, which a list takes as
134
+ * part of a query in progress only (see {@link Typeahead.isActive}).
135
+ *
136
+ * Time complexity: O(1) for a key name of bounded length. Memory: O(1).
137
+ *
138
+ * @example
139
+ * isTypeaheadKey({ key: "a" }); // true
140
+ * isTypeaheadKey({ key: "Enter" }); // false: a named key
141
+ * isTypeaheadKey({ key: "s", ctrlKey: true }); // false: a shortcut
142
+ */
143
+ export function isTypeaheadKey(input) {
144
+ const { key, ctrlKey = false, altKey = false, metaKey = false } = input;
145
+ if (ctrlKey || altKey || metaKey || key === "" || CONTROL_.test(key)) {
146
+ return false;
147
+ }
148
+ const segments = new Intl.Segmenter(undefined, {
149
+ granularity: "grapheme",
150
+ }).segment(key);
151
+ let count = 0;
152
+ for (const _segment of segments) {
153
+ count += 1;
154
+ if (count > 1) {
155
+ return false;
156
+ }
157
+ }
158
+ return count === 1;
159
+ }
160
+ /**
161
+ * The character a key adds to a list's typeahead query: a typed character
162
+ * ({@link isTypeaheadKey}), Space only while a query is in progress (otherwise
163
+ * Space selects or activates an item). `undefined` for any other key.
164
+ *
165
+ * Time complexity: O(1) for a key name of bounded length. Memory: O(1).
166
+ *
167
+ * @example
168
+ * typeaheadCharacter({ key: "a" }, false); // "a"
169
+ * typeaheadCharacter({ key: " " }, false); // undefined: Space selects
170
+ * typeaheadCharacter({ key: " " }, true); // " ": "new y" goes on
171
+ */
172
+ export function typeaheadCharacter(input, isTypingAhead) {
173
+ if (input.key === " " && !isTypingAhead) {
174
+ return undefined;
175
+ }
176
+ return isTypeaheadKey(input) ? input.key : undefined;
177
+ }
178
+ //# sourceMappingURL=typeahead.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeahead.js","sourceRoot":"","sources":["../../src/focus/typeahead.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAEhB,MAAM,cAAc,CAAC;AAYtB;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACJ,UAAU,CAAS;IAC5B,MAAM,GAAG,EAAE,CAAC;IACZ,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAE7C,uEAAuE;IACvE,YAAY,OAAO,GAAqB,EAAE;QACzC,MAAM,EAAE,SAAS,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;QACpC,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,KAAK,EAAE,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;IACtE,CAAC;IAED,2EAA2E;IAC3E,IAAI,CAAC,SAAiB,EAAE,IAAY;QACnC,IAAI,CAAC,MAA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QACX,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAED,OAAO,KAAK,KAAK,CAAC,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAe,EACf,aAAsB;IAEtB,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC"}
@@ -0,0 +1,26 @@
1
+ export * from "./anchored/anchored.js";
2
+ export * from "./button/button.js";
3
+ export * from "./dialog/dialog.js";
4
+ export * from "./focus/owns-arrow-keys.js";
5
+ export * from "./focus/roving-focus.js";
6
+ export * from "./focus/typeahead.js";
7
+ export * from "./knob/knob.js";
8
+ export * from "./menu/menu.js";
9
+ export * from "./meter/meter.js";
10
+ export * from "./progress/progress.js";
11
+ export * from "./readout/readout.js";
12
+ export * from "./slider/slider-attributes.js";
13
+ export * from "./slider/slider-range.js";
14
+ export * from "./slider/slider-track.js";
15
+ export * from "./slider/stepped-value.js";
16
+ export * from "./spin-button/spin-button.js";
17
+ export * from "./switch/switch.js";
18
+ export * from "./tabs/tabs.js";
19
+ export * from "./toast/toast-queue.js";
20
+ export * from "./toast/toasts-obscure.js";
21
+ export * from "./toggle-button/toggle-button.js";
22
+ export * from "./tone.js";
23
+ export * from "./toolbar/toolbar.js";
24
+ export * from "./tooltip/tooltip.js";
25
+ export * from "./tree/tree.js";
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ export * from "./anchored/anchored.js";
2
+ export * from "./button/button.js";
3
+ export * from "./dialog/dialog.js";
4
+ export * from "./focus/owns-arrow-keys.js";
5
+ export * from "./focus/roving-focus.js";
6
+ export * from "./focus/typeahead.js";
7
+ export * from "./knob/knob.js";
8
+ export * from "./menu/menu.js";
9
+ export * from "./meter/meter.js";
10
+ export * from "./progress/progress.js";
11
+ export * from "./readout/readout.js";
12
+ export * from "./slider/slider-attributes.js";
13
+ export * from "./slider/slider-range.js";
14
+ export * from "./slider/slider-track.js";
15
+ export * from "./slider/stepped-value.js";
16
+ export * from "./spin-button/spin-button.js";
17
+ export * from "./switch/switch.js";
18
+ export * from "./tabs/tabs.js";
19
+ export * from "./toast/toast-queue.js";
20
+ export * from "./toast/toasts-obscure.js";
21
+ export * from "./toggle-button/toggle-button.js";
22
+ export * from "./tone.js";
23
+ export * from "./toolbar/toolbar.js";
24
+ export * from "./tooltip/tooltip.js";
25
+ export * from "./tree/tree.js";
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { type SliderRange } from "../slider/slider-range.js";
2
+ /**
3
+ * Where a knob's travel starts and how far it turns, in degrees clockwise from
4
+ * twelve o'clock.
5
+ */
6
+ export type KnobArc = {
7
+ startDegrees: number;
8
+ /** Above zero and below 360. */
9
+ sweepDegrees: number;
10
+ };
11
+ /** The usual knob travel: 270°, from 7:30 to 4:30 clockwise. */
12
+ export declare const KNOB_ARC: {
13
+ readonly startDegrees: -135;
14
+ readonly sweepDegrees: 270;
15
+ };
16
+ /** The angles a knob draws, in degrees clockwise from twelve o'clock. */
17
+ export type KnobAngles = {
18
+ /** Where the pointer points: the value. */
19
+ pointer: number;
20
+ /** The lower end of the lit arc. */
21
+ arcFrom: number;
22
+ /** The higher end of the lit arc; equal to `arcFrom` when nothing is lit. */
23
+ arcTo: number;
24
+ };
25
+ /** Options of {@link knobAngles}. */
26
+ export type KnobAnglesOptions = {
27
+ /**
28
+ * The value the lit arc grows from. Defaults to `range.min`; a bipolar knob
29
+ * (pan, detune) gives its centre, and lights from there to either side.
30
+ */
31
+ origin?: number;
32
+ /** Defaults to {@link KNOB_ARC}. */
33
+ arc?: KnobArc;
34
+ };
35
+ /**
36
+ * The pointer angle of `value` and the span of the lit arc, for drawing a knob.
37
+ * Values outside the range are clamped to its ends.
38
+ *
39
+ * Time complexity: O(1). Memory: O(1).
40
+ *
41
+ * @example
42
+ * knobAngles(75, { min: 50, max: 100, step: 1 });
43
+ * // { pointer: 0, arcFrom: -135, arcTo: 0 }
44
+ * knobAngles(25, { min: 0, max: 100, step: 1 }, { origin: 50 });
45
+ * // { pointer: -67.5, arcFrom: -67.5, arcTo: 0 }
46
+ *
47
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
48
+ * zero.
49
+ */
50
+ export declare function knobAngles(value: number, range: SliderRange, options?: KnobAnglesOptions): KnobAngles;
51
+ /**
52
+ * A knob's dial in SVG user units, y down: its centre and radius. Plain
53
+ * numbers, so the API does not follow the math types.
54
+ */
55
+ export type KnobDial = {
56
+ readonly centerX: number;
57
+ readonly centerY: number;
58
+ readonly radius: number;
59
+ };
60
+ /**
61
+ * The SVG path data of the clockwise arc of `dial` from `fromDegrees` to
62
+ * `toDegrees`, both on the knob's clock face (degrees clockwise from twelve
63
+ * o'clock) in SVG's y-down user space, coordinates to two decimals. Stroke it
64
+ * for a knob's track or its lit arc.
65
+ *
66
+ * Time complexity: O(1). Memory: O(1).
67
+ *
68
+ * @example
69
+ * knobArcPath({ centerX: 26, centerY: 26, radius: 22 }, -90, 0);
70
+ * // "M4 26 A22 22 0 0 1 26 4"
71
+ *
72
+ * @throws {RangeError} When the arc is not between 0° and 360°: `toDegrees`
73
+ * below `fromDegrees`, or a full turn or more, which one SVG arc cannot
74
+ * draw.
75
+ */
76
+ export declare function knobArcPath(dial: KnobDial, fromDegrees: number, toDegrees: number): string;
77
+ /** Options of {@link knobDragValue}. */
78
+ export type KnobDragOptions = {
79
+ /** How many pixels of vertical travel cross the whole range. Defaults to 160. */
80
+ travel?: number;
81
+ /**
82
+ * Fine mode, usually while Shift is held: the travel is divided by
83
+ * `fineScale`.
84
+ */
85
+ isFine?: boolean;
86
+ /** How much finer fine mode is. Defaults to 0.25: four times the travel. */
87
+ fineScale?: number;
88
+ };
89
+ /**
90
+ * The value of a knob dragged vertically: up turns it up, down turns it down,
91
+ * as on hardware controllers' touch surfaces, where turning around the knob
92
+ * would hide it under the finger. `rise` is how far the pointer has moved up
93
+ * since the press, in pixels (`pressY - currentY`). The result is snapped
94
+ * ({@link snapSliderValue}).
95
+ *
96
+ * Time complexity: O(1). Memory: O(1).
97
+ *
98
+ * @example
99
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }); // 90
100
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }, { isFine: true }); // 83
101
+ *
102
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
103
+ * zero.
104
+ */
105
+ export declare function knobDragValue(startValue: number, rise: number, range: SliderRange, options?: KnobDragOptions): number;
106
+ //# sourceMappingURL=knob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knob.d.ts","sourceRoot":"","sources":["../../src/knob/knob.ts"],"names":[],"mappings":"AAWA,OAAO,EACN,KAAK,WAAW,EAGhB,MAAM,2BAA2B,CAAC;AAEnC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,QAAQ;2BACN,CAAC,GAAG;2BACJ,GAAG;CACU,CAAC;AAE7B,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAAG;IACxB,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qCAAqC;AACrC,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,GAAG,CAAC,EAAE,OAAO,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CACzB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,iBAAiB,GACzB,UAAU,CAaZ;AAED;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GACf,MAAM,CA4BR;AAoBD,wCAAwC;AACxC,MAAM,MAAM,eAAe,GAAG;IAC7B,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC5B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,eAAe,GACvB,MAAM,CASR"}
@@ -0,0 +1,116 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { printPathData } from "@ac-kit/format-svg";
3
+ import { circle2Create, circle2PointAt, circle2Set, } from "@ac-kit/math-geometry";
4
+ import { vec2Create } from "@ac-kit/math-linear";
5
+ import { DEG_TO_RAD, lerp } from "@ac-kit/math-scalar";
6
+ import { sliderFraction, snapSliderValue, } from "../slider/slider-range.js";
7
+ /** The usual knob travel: 270°, from 7:30 to 4:30 clockwise. */
8
+ export const KNOB_ARC = {
9
+ startDegrees: -135,
10
+ sweepDegrees: 270,
11
+ };
12
+ /**
13
+ * The pointer angle of `value` and the span of the lit arc, for drawing a knob.
14
+ * Values outside the range are clamped to its ends.
15
+ *
16
+ * Time complexity: O(1). Memory: O(1).
17
+ *
18
+ * @example
19
+ * knobAngles(75, { min: 50, max: 100, step: 1 });
20
+ * // { pointer: 0, arcFrom: -135, arcTo: 0 }
21
+ * knobAngles(25, { min: 0, max: 100, step: 1 }, { origin: 50 });
22
+ * // { pointer: -67.5, arcFrom: -67.5, arcTo: 0 }
23
+ *
24
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
25
+ * zero.
26
+ */
27
+ export function knobAngles(value, range, options) {
28
+ const { startDegrees, sweepDegrees } = options?.arc ?? KNOB_ARC;
29
+ const endDegrees = startDegrees + sweepDegrees;
30
+ const pointer = lerp(startDegrees, endDegrees, sliderFraction(value, range));
31
+ const origin = lerp(startDegrees, endDegrees, sliderFraction(options?.origin ?? range.min, range));
32
+ return pointer < origin
33
+ ? { pointer, arcFrom: pointer, arcTo: origin }
34
+ : { pointer, arcFrom: origin, arcTo: pointer };
35
+ }
36
+ /**
37
+ * The SVG path data of the clockwise arc of `dial` from `fromDegrees` to
38
+ * `toDegrees`, both on the knob's clock face (degrees clockwise from twelve
39
+ * o'clock) in SVG's y-down user space, coordinates to two decimals. Stroke it
40
+ * for a knob's track or its lit arc.
41
+ *
42
+ * Time complexity: O(1). Memory: O(1).
43
+ *
44
+ * @example
45
+ * knobArcPath({ centerX: 26, centerY: 26, radius: 22 }, -90, 0);
46
+ * // "M4 26 A22 22 0 0 1 26 4"
47
+ *
48
+ * @throws {RangeError} When the arc is not between 0° and 360°: `toDegrees`
49
+ * below `fromDegrees`, or a full turn or more, which one SVG arc cannot
50
+ * draw.
51
+ */
52
+ export function knobArcPath(dial, fromDegrees, toDegrees) {
53
+ const sweep = toDegrees - fromDegrees;
54
+ if (!(sweep >= 0 && sweep < 360)) {
55
+ throw new RangeError(`A knob arc runs clockwise less than a full turn, got ${describeValue(fromDegrees)}° to ${describeValue(toDegrees)}°.`);
56
+ }
57
+ const circle = circle2Set(CIRCLE_, dial.centerX, dial.centerY, dial.radius);
58
+ const start = dialPoint_(START_, circle, fromDegrees);
59
+ const end = dialPoint_(END_, circle, toDegrees);
60
+ return printPathData([
61
+ { kind: "moveto", x: start[0], y: start[1] },
62
+ {
63
+ kind: "elliptical-arc",
64
+ rx: dial.radius,
65
+ ry: dial.radius,
66
+ xAxisRotation: 0,
67
+ largeArc: sweep > 180,
68
+ // Positive-angle direction, which is clockwise with y down.
69
+ sweep: true,
70
+ x: end[0],
71
+ y: end[1],
72
+ },
73
+ ], { fractionDigits: 2 });
74
+ }
75
+ /**
76
+ * Scratch circle and points of {@link knobArcPath}; they never leave this
77
+ * module.
78
+ */
79
+ const CIRCLE_ = circle2Create();
80
+ const START_ = vec2Create();
81
+ const END_ = vec2Create();
82
+ /**
83
+ * Writes the point of `dial` at a clock-face angle into `out`. `math-geometry`
84
+ * measures from the positive x axis towards positive y; with SVG's y pointing
85
+ * down that turns clockwise, as a clock does, so only twelve o'clock's offset
86
+ * of a quarter turn is left to convert.
87
+ */
88
+ function dialPoint_(out, dial, clockDegrees) {
89
+ return circle2PointAt(out, dial, (clockDegrees - 90) * DEG_TO_RAD);
90
+ }
91
+ // Tall enough to aim at one step of a hundred with a finger, short enough to
92
+ // cross the range without lifting it.
93
+ const DEFAULT_KNOB_TRAVEL_ = 160;
94
+ const DEFAULT_FINE_SCALE_ = 0.25;
95
+ /**
96
+ * The value of a knob dragged vertically: up turns it up, down turns it down,
97
+ * as on hardware controllers' touch surfaces, where turning around the knob
98
+ * would hide it under the finger. `rise` is how far the pointer has moved up
99
+ * since the press, in pixels (`pressY - currentY`). The result is snapped
100
+ * ({@link snapSliderValue}).
101
+ *
102
+ * Time complexity: O(1). Memory: O(1).
103
+ *
104
+ * @example
105
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }); // 90
106
+ * knobDragValue(80, 32, { min: 50, max: 100, step: 1 }, { isFine: true }); // 83
107
+ *
108
+ * @throws {RangeError} When `max` is not above `min` or `step` is not above
109
+ * zero.
110
+ */
111
+ export function knobDragValue(startValue, rise, range, options) {
112
+ const travel = options?.travel ?? DEFAULT_KNOB_TRAVEL_;
113
+ const scale = options?.isFine === true ? (options.fineScale ?? DEFAULT_FINE_SCALE_) : 1;
114
+ return snapSliderValue(startValue + (rise / travel) * (range.max - range.min) * scale, range);
115
+ }
116
+ //# sourceMappingURL=knob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knob.js","sourceRoot":"","sources":["../../src/knob/knob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAEN,aAAa,EACb,cAAc,EACd,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAa,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAEN,cAAc,EACd,eAAe,GACf,MAAM,2BAA2B,CAAC;AAYnC,gEAAgE;AAChE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,YAAY,EAAE,CAAC,GAAG;IAClB,YAAY,EAAE,GAAG;CACU,CAAC;AAuB7B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CACzB,KAAa,EACb,KAAkB,EAClB,OAA2B;IAE3B,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,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GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,EAC9D,KAAK,CACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,157 @@
1
+ import type { KeyInput } from "@ac-kit/ui-gesture";
2
+ import type { AnchoredAlign, AnchoredAttributes, AnchoredSide } from "../anchored/anchored.js";
3
+ /**
4
+ * What a menu item does: an action, a setting turned on or off, or one choice
5
+ * among the radio items of its group.
6
+ */
7
+ export type MenuItemKind = "item" | "checkbox" | "radio";
8
+ /** The attributes of a menu button, keyed by their HTML attribute names. */
9
+ export type MenuButtonAttributes = {
10
+ "aria-haspopup": "menu";
11
+ "aria-expanded": "true" | "false";
12
+ "aria-controls": string;
13
+ };
14
+ /** Input of {@link menuButtonAttributes}. */
15
+ export type MenuButtonAttributesInput = {
16
+ /** The id of the menu it opens. */
17
+ menuId: string;
18
+ isOpen: boolean;
19
+ };
20
+ /**
21
+ * The attributes of the button that opens a menu (WAI-ARIA menu button
22
+ * pattern): it has a menu popup, says whether it is open, and which element the
23
+ * menu is.
24
+ *
25
+ * Time complexity: O(1). Memory: O(1).
26
+ *
27
+ * @example
28
+ * menuButtonAttributes({ menuId: "m", isOpen: false });
29
+ * // { "aria-haspopup": "menu", "aria-expanded": "false", "aria-controls": "m" }
30
+ */
31
+ export declare function menuButtonAttributes(input: MenuButtonAttributesInput): MenuButtonAttributes;
32
+ /** The attributes of a menu, keyed by their HTML attribute names. */
33
+ export type MenuAttributes = AnchoredAttributes & {
34
+ role: "menu";
35
+ "aria-labelledby": string;
36
+ tabindex: -1;
37
+ };
38
+ /** Input of {@link menuAttributes}. */
39
+ export type MenuAttributesInput = {
40
+ /** The id of the element naming it: its menu button. */
41
+ labelledBy: string;
42
+ /** Defaults to `block-end`: below the button. */
43
+ side?: AnchoredSide;
44
+ /** Defaults to `start`: its start edge on the button's. */
45
+ align?: AnchoredAlign;
46
+ };
47
+ /**
48
+ * The attributes of a menu (WAI-ARIA menu pattern): named by its button,
49
+ * focusable itself only as a fallback (its items take focus), and placed
50
+ * against the button by the stylesheet.
51
+ *
52
+ * Time complexity: O(1). Memory: O(1).
53
+ *
54
+ * @example
55
+ * menuAttributes({ labelledBy: "b" });
56
+ * // { role: "menu", "aria-labelledby": "b", tabindex: -1,
57
+ * // "data-side": "block-end", "data-align": "start" }
58
+ */
59
+ export declare function menuAttributes(input: MenuAttributesInput): MenuAttributes;
60
+ /** The attributes of a menu item, keyed by their HTML attribute names. */
61
+ export type MenuItemAttributes = {
62
+ role: "menuitem" | "menuitemcheckbox" | "menuitemradio";
63
+ tabindex: -1;
64
+ "aria-checked"?: "true" | "false";
65
+ "aria-disabled"?: "true";
66
+ "data-kind": MenuItemKind;
67
+ };
68
+ /** Input of {@link menuItemAttributes}. */
69
+ export type MenuItemAttributesInput = {
70
+ kind: "item";
71
+ isDisabled?: boolean;
72
+ } | {
73
+ kind: "checkbox" | "radio";
74
+ isChecked: boolean;
75
+ isDisabled?: boolean;
76
+ };
77
+ /**
78
+ * The attributes of a menu item: its role by kind, its checked state for a
79
+ * checkbox or radio item, out of the tab order (the menu moves focus to it). A
80
+ * disabled item stays focusable, as the WAI-ARIA practices advise, so it can be
81
+ * found and read; it is not activated.
82
+ *
83
+ * Time complexity: O(1). Memory: O(1).
84
+ *
85
+ * @example
86
+ * menuItemAttributes({ kind: "checkbox", isChecked: true });
87
+ * // { role: "menuitemcheckbox", tabindex: -1, "aria-checked": "true",
88
+ * // "data-kind": "checkbox" }
89
+ */
90
+ export declare function menuItemAttributes(input: MenuItemAttributesInput): MenuItemAttributes;
91
+ /** Which item a menu focuses as it opens. */
92
+ export type MenuOpenFocus = "first" | "last";
93
+ /**
94
+ * The item a key on a menu button opens its menu on (WAI-ARIA menu button
95
+ * pattern): Enter, Space and Arrow Down the first, Arrow Up the last.
96
+ * `undefined` for another key, or with Ctrl, Alt or Meta held.
97
+ *
98
+ * Time complexity: O(1). Memory: O(1).
99
+ *
100
+ * @example
101
+ * menuButtonKeyAction({ key: "ArrowUp" }); // "last"
102
+ */
103
+ export declare function menuButtonKeyAction(input: KeyInput): MenuOpenFocus | undefined;
104
+ /** Input of {@link menuKeyAction}: the key and where focus is. */
105
+ export type MenuKeyInput = KeyInput & {
106
+ /** The focused item's index; `undefined` when the menu itself has focus. */
107
+ current: number | undefined;
108
+ /** How many items the menu has. */
109
+ count: number;
110
+ /** The focused item's kind; `undefined` when no item has focus. */
111
+ itemKind: MenuItemKind | undefined;
112
+ /** Whether a typeahead query is in progress, so Space extends it. */
113
+ isTypingAhead: boolean;
114
+ };
115
+ /**
116
+ * What a key does in an open menu (WAI-ARIA menu pattern):
117
+ *
118
+ * - `focus` an item: Arrow Down and Up to the next and previous one, going round,
119
+ * Home and End to the first and last;
120
+ * - `activate` the focused item: Enter does and closes the menu; Space does on an
121
+ * action and closes, and checks a checkbox or radio item keeping the menu
122
+ * open;
123
+ * - `close` the menu and give focus back to its button: Escape;
124
+ * - `leave` it: Tab and Shift Tab close it and move on from its button;
125
+ * - `typeahead` a character, Space included while a query is in progress.
126
+ */
127
+ export type MenuKeyAction = {
128
+ readonly kind: "focus";
129
+ readonly index: number;
130
+ } | {
131
+ readonly kind: "activate";
132
+ readonly keepsOpen: boolean;
133
+ } | {
134
+ readonly kind: "close";
135
+ } | {
136
+ readonly kind: "leave";
137
+ } | {
138
+ readonly kind: "typeahead";
139
+ readonly character: string;
140
+ };
141
+ /**
142
+ * The action of a key in an open menu, {@link MenuKeyAction}. `undefined` for a
143
+ * key the menu does not use, or with Ctrl, Alt or Meta held (a shortcut).
144
+ * Disabled items take focus like the others, so the caller checks them before
145
+ * activating one.
146
+ *
147
+ * Time complexity: O(count) at worst. Memory: O(1).
148
+ *
149
+ * @example
150
+ * menuKeyAction({ key: "ArrowDown", current: 2, count: 3, itemKind: "item",
151
+ * isTypingAhead: false }); // { kind: "focus", index: 0 }
152
+ *
153
+ * @throws {RangeError} When `count` is not a non-negative safe integer or
154
+ * `current` is outside [0, count).
155
+ */
156
+ export declare function menuKeyAction(input: MenuKeyInput): MenuKeyAction | undefined;
157
+ //# sourceMappingURL=menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EACX,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,MAAM,yBAAyB,CAAC;AAIjC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAEzD,4EAA4E;AAC5E,MAAM,MAAM,oBAAoB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,yBAAyB,GAAG;IACvC,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,yBAAyB,GAC9B,oBAAoB,CAMtB;AAED,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,CAAC,CAAC,CAAC;CACb,CAAC;AAEF,uCAAuC;AACvC,MAAM,MAAM,mBAAmB,GAAG;IACjC,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,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