@ac-kit/ui-common 0.1.0 → 0.3.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 (231) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +383 -9
  3. package/dist/adapter/_anchor.d.ts +13 -0
  4. package/dist/adapter/_anchor.d.ts.map +1 -0
  5. package/dist/adapter/_anchor.js +39 -0
  6. package/dist/adapter/_anchor.js.map +1 -0
  7. package/dist/adapter/_dom.d.ts +14 -0
  8. package/dist/adapter/_dom.d.ts.map +1 -0
  9. package/dist/adapter/_dom.js +31 -0
  10. package/dist/adapter/_dom.js.map +1 -0
  11. package/dist/adapter/_live-announcer.d.ts +26 -0
  12. package/dist/adapter/_live-announcer.d.ts.map +1 -0
  13. package/dist/adapter/_live-announcer.js +101 -0
  14. package/dist/adapter/_live-announcer.js.map +1 -0
  15. package/dist/adapter/join-classes.d.ts.map +1 -0
  16. package/dist/adapter/join-classes.js.map +1 -0
  17. package/dist/anchored/anchored.d.ts +19 -0
  18. package/dist/anchored/anchored.d.ts.map +1 -0
  19. package/dist/anchored/anchored.js +2 -0
  20. package/dist/anchored/anchored.js.map +1 -0
  21. package/dist/bit-grid/bit-grid.d.ts +151 -0
  22. package/dist/bit-grid/bit-grid.d.ts.map +1 -0
  23. package/dist/bit-grid/bit-grid.js +201 -0
  24. package/dist/bit-grid/bit-grid.js.map +1 -0
  25. package/dist/focus/typeahead.d.ts +112 -0
  26. package/dist/focus/typeahead.d.ts.map +1 -0
  27. package/dist/focus/typeahead.js +178 -0
  28. package/dist/focus/typeahead.js.map +1 -0
  29. package/dist/index.d.ts +12 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +12 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/menu/menu.d.ts +157 -0
  34. package/dist/menu/menu.d.ts.map +1 -0
  35. package/dist/menu/menu.js +162 -0
  36. package/dist/menu/menu.js.map +1 -0
  37. package/dist/preact/bit-grid.d.ts +39 -0
  38. package/dist/preact/bit-grid.d.ts.map +1 -0
  39. package/dist/preact/bit-grid.js +72 -0
  40. package/dist/preact/bit-grid.js.map +1 -0
  41. package/dist/preact/button.d.ts.map +1 -1
  42. package/dist/preact/button.js +1 -1
  43. package/dist/preact/button.js.map +1 -1
  44. package/dist/preact/dialog.d.ts.map +1 -1
  45. package/dist/preact/dialog.js +1 -1
  46. package/dist/preact/dialog.js.map +1 -1
  47. package/dist/preact/index.d.ts +10 -1
  48. package/dist/preact/index.d.ts.map +1 -1
  49. package/dist/preact/index.js +10 -1
  50. package/dist/preact/index.js.map +1 -1
  51. package/dist/preact/knob.d.ts.map +1 -1
  52. package/dist/preact/knob.js +6 -14
  53. package/dist/preact/knob.js.map +1 -1
  54. package/dist/preact/menu-button.d.ts +117 -0
  55. package/dist/preact/menu-button.d.ts.map +1 -0
  56. package/dist/preact/menu-button.js +330 -0
  57. package/dist/preact/menu-button.js.map +1 -0
  58. package/dist/preact/meter.d.ts.map +1 -1
  59. package/dist/preact/meter.js +1 -1
  60. package/dist/preact/meter.js.map +1 -1
  61. package/dist/preact/progress-ring.d.ts +42 -0
  62. package/dist/preact/progress-ring.d.ts.map +1 -0
  63. package/dist/preact/progress-ring.js +26 -0
  64. package/dist/preact/progress-ring.js.map +1 -0
  65. package/dist/preact/radio-group.d.ts.map +1 -1
  66. package/dist/preact/radio-group.js +1 -1
  67. package/dist/preact/radio-group.js.map +1 -1
  68. package/dist/preact/readout.d.ts.map +1 -1
  69. package/dist/preact/readout.js +1 -1
  70. package/dist/preact/readout.js.map +1 -1
  71. package/dist/preact/slider.d.ts.map +1 -1
  72. package/dist/preact/slider.js +7 -5
  73. package/dist/preact/slider.js.map +1 -1
  74. package/dist/preact/spin-button.d.ts +67 -0
  75. package/dist/preact/spin-button.d.ts.map +1 -0
  76. package/dist/preact/spin-button.js +132 -0
  77. package/dist/preact/spin-button.js.map +1 -0
  78. package/dist/preact/swatch-strip.d.ts +30 -0
  79. package/dist/preact/swatch-strip.d.ts.map +1 -0
  80. package/dist/preact/swatch-strip.js +17 -0
  81. package/dist/preact/swatch-strip.js.map +1 -0
  82. package/dist/preact/switch.js +1 -1
  83. package/dist/preact/switch.js.map +1 -1
  84. package/dist/preact/tabs.d.ts +97 -0
  85. package/dist/preact/tabs.d.ts.map +1 -0
  86. package/dist/preact/tabs.js +264 -0
  87. package/dist/preact/tabs.js.map +1 -0
  88. package/dist/preact/toaster.d.ts +43 -0
  89. package/dist/preact/toaster.d.ts.map +1 -0
  90. package/dist/preact/toaster.js +356 -0
  91. package/dist/preact/toaster.js.map +1 -0
  92. package/dist/preact/toggle-button.d.ts.map +1 -1
  93. package/dist/preact/toggle-button.js +1 -1
  94. package/dist/preact/toggle-button.js.map +1 -1
  95. package/dist/preact/toolbar.d.ts.map +1 -1
  96. package/dist/preact/toolbar.js +3 -9
  97. package/dist/preact/toolbar.js.map +1 -1
  98. package/dist/preact/tooltip.d.ts +67 -0
  99. package/dist/preact/tooltip.d.ts.map +1 -0
  100. package/dist/preact/tooltip.js +165 -0
  101. package/dist/preact/tooltip.js.map +1 -0
  102. package/dist/preact/tree.d.ts +93 -0
  103. package/dist/preact/tree.d.ts.map +1 -0
  104. package/dist/preact/tree.js +399 -0
  105. package/dist/preact/tree.js.map +1 -0
  106. package/dist/progress/progress.d.ts +51 -0
  107. package/dist/progress/progress.d.ts.map +1 -0
  108. package/dist/progress/progress.js +43 -0
  109. package/dist/progress/progress.js.map +1 -0
  110. package/dist/react/_props.d.ts +22 -0
  111. package/dist/react/_props.d.ts.map +1 -0
  112. package/dist/react/_props.js +14 -0
  113. package/dist/react/_props.js.map +1 -0
  114. package/dist/react/bit-grid.d.ts +40 -0
  115. package/dist/react/bit-grid.d.ts.map +1 -0
  116. package/dist/react/bit-grid.js +71 -0
  117. package/dist/react/bit-grid.js.map +1 -0
  118. package/dist/react/button.d.ts +60 -0
  119. package/dist/react/button.d.ts.map +1 -0
  120. package/dist/react/button.js +34 -0
  121. package/dist/react/button.js.map +1 -0
  122. package/dist/react/dialog.d.ts +44 -0
  123. package/dist/react/dialog.d.ts.map +1 -0
  124. package/dist/react/dialog.js +91 -0
  125. package/dist/react/dialog.js.map +1 -0
  126. package/dist/react/index.d.ts +22 -0
  127. package/dist/react/index.d.ts.map +1 -0
  128. package/dist/react/index.js +22 -0
  129. package/dist/react/index.js.map +1 -0
  130. package/dist/react/knob.d.ts +55 -0
  131. package/dist/react/knob.d.ts.map +1 -0
  132. package/dist/react/knob.js +144 -0
  133. package/dist/react/knob.js.map +1 -0
  134. package/dist/react/menu-button.d.ts +147 -0
  135. package/dist/react/menu-button.d.ts.map +1 -0
  136. package/dist/react/menu-button.js +342 -0
  137. package/dist/react/menu-button.js.map +1 -0
  138. package/dist/react/meter.d.ts +34 -0
  139. package/dist/react/meter.d.ts.map +1 -0
  140. package/dist/react/meter.js +23 -0
  141. package/dist/react/meter.js.map +1 -0
  142. package/dist/react/progress-ring.d.ts +42 -0
  143. package/dist/react/progress-ring.d.ts.map +1 -0
  144. package/dist/react/progress-ring.js +28 -0
  145. package/dist/react/progress-ring.js.map +1 -0
  146. package/dist/react/radio-group.d.ts +52 -0
  147. package/dist/react/radio-group.d.ts.map +1 -0
  148. package/dist/react/radio-group.js +30 -0
  149. package/dist/react/radio-group.js.map +1 -0
  150. package/dist/react/readout.d.ts +23 -0
  151. package/dist/react/readout.d.ts.map +1 -0
  152. package/dist/react/readout.js +13 -0
  153. package/dist/react/readout.js.map +1 -0
  154. package/dist/react/slider.d.ts +44 -0
  155. package/dist/react/slider.d.ts.map +1 -0
  156. package/dist/react/slider.js +167 -0
  157. package/dist/react/slider.js.map +1 -0
  158. package/dist/react/spin-button.d.ts +71 -0
  159. package/dist/react/spin-button.d.ts.map +1 -0
  160. package/dist/react/spin-button.js +132 -0
  161. package/dist/react/spin-button.js.map +1 -0
  162. package/dist/react/swatch-strip.d.ts +31 -0
  163. package/dist/react/swatch-strip.d.ts.map +1 -0
  164. package/dist/react/swatch-strip.js +17 -0
  165. package/dist/react/swatch-strip.js.map +1 -0
  166. package/dist/react/switch.d.ts +26 -0
  167. package/dist/react/switch.d.ts.map +1 -0
  168. package/dist/react/switch.js +19 -0
  169. package/dist/react/switch.js.map +1 -0
  170. package/dist/react/tabs.d.ts +95 -0
  171. package/dist/react/tabs.d.ts.map +1 -0
  172. package/dist/react/tabs.js +274 -0
  173. package/dist/react/tabs.js.map +1 -0
  174. package/dist/react/toaster.d.ts +43 -0
  175. package/dist/react/toaster.d.ts.map +1 -0
  176. package/dist/react/toaster.js +368 -0
  177. package/dist/react/toaster.js.map +1 -0
  178. package/dist/react/toggle-button.d.ts +37 -0
  179. package/dist/react/toggle-button.d.ts.map +1 -0
  180. package/dist/react/toggle-button.js +22 -0
  181. package/dist/react/toggle-button.js.map +1 -0
  182. package/dist/react/toolbar.d.ts +25 -0
  183. package/dist/react/toolbar.d.ts.map +1 -0
  184. package/dist/react/toolbar.js +143 -0
  185. package/dist/react/toolbar.js.map +1 -0
  186. package/dist/react/tooltip.d.ts +68 -0
  187. package/dist/react/tooltip.d.ts.map +1 -0
  188. package/dist/react/tooltip.js +165 -0
  189. package/dist/react/tooltip.js.map +1 -0
  190. package/dist/react/tree.d.ts +94 -0
  191. package/dist/react/tree.d.ts.map +1 -0
  192. package/dist/react/tree.js +422 -0
  193. package/dist/react/tree.js.map +1 -0
  194. package/dist/react/use-element-binding.d.ts +35 -0
  195. package/dist/react/use-element-binding.d.ts.map +1 -0
  196. package/dist/react/use-element-binding.js +51 -0
  197. package/dist/react/use-element-binding.js.map +1 -0
  198. package/dist/spin-button/spin-button.d.ts +110 -0
  199. package/dist/spin-button/spin-button.d.ts.map +1 -0
  200. package/dist/spin-button/spin-button.js +179 -0
  201. package/dist/spin-button/spin-button.js.map +1 -0
  202. package/dist/swatch-strip/swatch-strip.d.ts +60 -0
  203. package/dist/swatch-strip/swatch-strip.d.ts.map +1 -0
  204. package/dist/swatch-strip/swatch-strip.js +60 -0
  205. package/dist/swatch-strip/swatch-strip.js.map +1 -0
  206. package/dist/tabs/tabs.d.ts +157 -0
  207. package/dist/tabs/tabs.d.ts.map +1 -0
  208. package/dist/tabs/tabs.js +120 -0
  209. package/dist/tabs/tabs.js.map +1 -0
  210. package/dist/toast/toast-queue.d.ts +212 -0
  211. package/dist/toast/toast-queue.d.ts.map +1 -0
  212. package/dist/toast/toast-queue.js +290 -0
  213. package/dist/toast/toast-queue.js.map +1 -0
  214. package/dist/toast/toasts-obscure.d.ts +25 -0
  215. package/dist/toast/toasts-obscure.d.ts.map +1 -0
  216. package/dist/toast/toasts-obscure.js +30 -0
  217. package/dist/toast/toasts-obscure.js.map +1 -0
  218. package/dist/tooltip/tooltip.d.ts +183 -0
  219. package/dist/tooltip/tooltip.d.ts.map +1 -0
  220. package/dist/tooltip/tooltip.js +185 -0
  221. package/dist/tooltip/tooltip.js.map +1 -0
  222. package/dist/tree/tree.d.ts +302 -0
  223. package/dist/tree/tree.d.ts.map +1 -0
  224. package/dist/tree/tree.js +439 -0
  225. package/dist/tree/tree.js.map +1 -0
  226. package/package.json +47 -14
  227. package/styles.css +1084 -3
  228. package/dist/preact/join-classes.d.ts.map +0 -1
  229. package/dist/preact/join-classes.js.map +0 -1
  230. /package/dist/{preact → adapter}/join-classes.d.ts +0 -0
  231. /package/dist/{preact → adapter}/join-classes.js +0 -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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/bit-grid.js";
1
3
  export * from "./button/button.js";
2
4
  export * from "./dialog/dialog.js";
3
5
  export * from "./focus/owns-arrow-keys.js";
4
6
  export * from "./focus/roving-focus.js";
7
+ export * from "./focus/typeahead.js";
5
8
  export * from "./knob/knob.js";
9
+ export * from "./menu/menu.js";
6
10
  export * from "./meter/meter.js";
11
+ export * from "./progress/progress.js";
7
12
  export * from "./readout/readout.js";
8
13
  export * from "./slider/slider-attributes.js";
9
14
  export * from "./slider/slider-range.js";
10
15
  export * from "./slider/slider-track.js";
11
16
  export * from "./slider/stepped-value.js";
17
+ export * from "./spin-button/spin-button.js";
18
+ export * from "./swatch-strip/swatch-strip.js";
12
19
  export * from "./switch/switch.js";
20
+ export * from "./tabs/tabs.js";
21
+ export * from "./toast/toast-queue.js";
22
+ export * from "./toast/toasts-obscure.js";
13
23
  export * from "./toggle-button/toggle-button.js";
14
24
  export * from "./tone.js";
15
25
  export * from "./toolbar/toolbar.js";
26
+ export * from "./tooltip/tooltip.js";
27
+ export * from "./tree/tree.js";
16
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,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,gCAAgC,CAAC;AAC/C,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 CHANGED
@@ -1,16 +1,28 @@
1
+ export * from "./anchored/anchored.js";
2
+ export * from "./bit-grid/bit-grid.js";
1
3
  export * from "./button/button.js";
2
4
  export * from "./dialog/dialog.js";
3
5
  export * from "./focus/owns-arrow-keys.js";
4
6
  export * from "./focus/roving-focus.js";
7
+ export * from "./focus/typeahead.js";
5
8
  export * from "./knob/knob.js";
9
+ export * from "./menu/menu.js";
6
10
  export * from "./meter/meter.js";
11
+ export * from "./progress/progress.js";
7
12
  export * from "./readout/readout.js";
8
13
  export * from "./slider/slider-attributes.js";
9
14
  export * from "./slider/slider-range.js";
10
15
  export * from "./slider/slider-track.js";
11
16
  export * from "./slider/stepped-value.js";
17
+ export * from "./spin-button/spin-button.js";
18
+ export * from "./swatch-strip/swatch-strip.js";
12
19
  export * from "./switch/switch.js";
20
+ export * from "./tabs/tabs.js";
21
+ export * from "./toast/toast-queue.js";
22
+ export * from "./toast/toasts-obscure.js";
13
23
  export * from "./toggle-button/toggle-button.js";
14
24
  export * from "./tone.js";
15
25
  export * from "./toolbar/toolbar.js";
26
+ export * from "./tooltip/tooltip.js";
27
+ export * from "./tree/tree.js";
16
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,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,gCAAgC,CAAC;AAC/C,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,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,EAA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;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,GAAG,SAAS,CAqD5E"}
@@ -0,0 +1,162 @@
1
+ import { describeValue, isIntegerInRange } from "@ac-kit/core";
2
+ import { rovingFocusIndex } from "../focus/roving-focus.js";
3
+ import { typeaheadCharacter } from "../focus/typeahead.js";
4
+ /**
5
+ * The attributes of the button that opens a menu (WAI-ARIA menu button
6
+ * pattern): it has a menu popup, says whether it is open, and which element the
7
+ * menu is.
8
+ *
9
+ * Time complexity: O(1). Memory: O(1).
10
+ *
11
+ * @example
12
+ * menuButtonAttributes({ menuId: "m", isOpen: false });
13
+ * // { "aria-haspopup": "menu", "aria-expanded": "false", "aria-controls": "m" }
14
+ */
15
+ export function menuButtonAttributes(input) {
16
+ return {
17
+ "aria-haspopup": "menu",
18
+ "aria-expanded": input.isOpen ? "true" : "false",
19
+ "aria-controls": input.menuId,
20
+ };
21
+ }
22
+ /**
23
+ * The attributes of a menu (WAI-ARIA menu pattern): named by its button,
24
+ * focusable itself only as a fallback (its items take focus), and placed
25
+ * against the button by the stylesheet.
26
+ *
27
+ * Time complexity: O(1). Memory: O(1).
28
+ *
29
+ * @example
30
+ * menuAttributes({ labelledBy: "b" });
31
+ * // { role: "menu", "aria-labelledby": "b", tabindex: -1,
32
+ * // "data-side": "block-end", "data-align": "start" }
33
+ */
34
+ export function menuAttributes(input) {
35
+ const { labelledBy, side = "block-end", align = "start" } = input;
36
+ return {
37
+ role: "menu",
38
+ "aria-labelledby": labelledBy,
39
+ tabindex: -1,
40
+ "data-side": side,
41
+ "data-align": align,
42
+ };
43
+ }
44
+ const ITEM_ROLES_ = {
45
+ item: "menuitem",
46
+ checkbox: "menuitemcheckbox",
47
+ radio: "menuitemradio",
48
+ };
49
+ /**
50
+ * The attributes of a menu item: its role by kind, its checked state for a
51
+ * checkbox or radio item, out of the tab order (the menu moves focus to it). A
52
+ * disabled item stays focusable, as the WAI-ARIA practices advise, so it can be
53
+ * found and read; it is not activated.
54
+ *
55
+ * Time complexity: O(1). Memory: O(1).
56
+ *
57
+ * @example
58
+ * menuItemAttributes({ kind: "checkbox", isChecked: true });
59
+ * // { role: "menuitemcheckbox", tabindex: -1, "aria-checked": "true",
60
+ * // "data-kind": "checkbox" }
61
+ */
62
+ export function menuItemAttributes(input) {
63
+ const attributes = {
64
+ role: ITEM_ROLES_[input.kind],
65
+ tabindex: -1,
66
+ "data-kind": input.kind,
67
+ };
68
+ if (input.kind !== "item") {
69
+ attributes["aria-checked"] = input.isChecked ? "true" : "false";
70
+ }
71
+ if (input.isDisabled === true) {
72
+ attributes["aria-disabled"] = "true";
73
+ }
74
+ return attributes;
75
+ }
76
+ function hasShortcutModifier_(input) {
77
+ return (input.ctrlKey === true || input.altKey === true || input.metaKey === true);
78
+ }
79
+ /**
80
+ * The item a key on a menu button opens its menu on (WAI-ARIA menu button
81
+ * pattern): Enter, Space and Arrow Down the first, Arrow Up the last.
82
+ * `undefined` for another key, or with Ctrl, Alt or Meta held.
83
+ *
84
+ * Time complexity: O(1). Memory: O(1).
85
+ *
86
+ * @example
87
+ * menuButtonKeyAction({ key: "ArrowUp" }); // "last"
88
+ */
89
+ export function menuButtonKeyAction(input) {
90
+ if (hasShortcutModifier_(input)) {
91
+ return undefined;
92
+ }
93
+ switch (input.key) {
94
+ case "Enter":
95
+ case " ":
96
+ case "ArrowDown":
97
+ return "first";
98
+ case "ArrowUp":
99
+ return "last";
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+ /**
105
+ * The action of a key in an open menu, {@link MenuKeyAction}. `undefined` for a
106
+ * key the menu does not use, or with Ctrl, Alt or Meta held (a shortcut).
107
+ * Disabled items take focus like the others, so the caller checks them before
108
+ * activating one.
109
+ *
110
+ * Time complexity: O(count) at worst. Memory: O(1).
111
+ *
112
+ * @example
113
+ * menuKeyAction({ key: "ArrowDown", current: 2, count: 3, itemKind: "item",
114
+ * isTypingAhead: false }); // { kind: "focus", index: 0 }
115
+ *
116
+ * @throws {RangeError} When `count` is not a non-negative safe integer or
117
+ * `current` is outside [0, count).
118
+ */
119
+ export function menuKeyAction(input) {
120
+ const { key, current, count, itemKind, isTypingAhead } = input;
121
+ if (!isIntegerInRange(count, 0, Number.MAX_SAFE_INTEGER + 1)) {
122
+ throw new RangeError(`count must be a non-negative safe integer, got ${describeValue(count)}`);
123
+ }
124
+ if (current !== undefined && !isIntegerInRange(current, 0, count)) {
125
+ throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
126
+ }
127
+ if (hasShortcutModifier_(input)) {
128
+ return undefined;
129
+ }
130
+ switch (key) {
131
+ case "ArrowDown":
132
+ case "ArrowUp":
133
+ case "Home":
134
+ case "End": {
135
+ if (count === 0) {
136
+ return undefined;
137
+ }
138
+ const index = current === undefined
139
+ ? rovingFocusIndex(0, key === "ArrowUp" || key === "End" ? "End" : "Home", count)
140
+ : rovingFocusIndex(current, key, count, { orientation: "vertical" });
141
+ return index === undefined ? undefined : { kind: "focus", index };
142
+ }
143
+ case "Escape":
144
+ return { kind: "close" };
145
+ case "Tab":
146
+ return { kind: "leave" };
147
+ case "Enter":
148
+ return itemKind === undefined
149
+ ? undefined
150
+ : { kind: "activate", keepsOpen: false };
151
+ default: {
152
+ const character = typeaheadCharacter(input, isTypingAhead);
153
+ if (character !== undefined) {
154
+ return { kind: "typeahead", character };
155
+ }
156
+ return key === " " && itemKind !== undefined
157
+ ? { kind: "activate", keepsOpen: itemKind !== "item" }
158
+ : undefined;
159
+ }
160
+ }
161
+ }
162
+ //# sourceMappingURL=menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQ/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAsB3D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAgC;IAEhC,OAAO;QACN,eAAe,EAAE,MAAM;QACvB,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QAChD,eAAe,EAAE,KAAK,CAAC,MAAM;KAC7B,CAAC;AACH,CAAC;AAmBD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACxD,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,WAAW,EAAE,KAAK,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC;IAElE,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,iBAAiB,EAAE,UAAU;QAC7B,QAAQ,EAAE,CAAC,CAAC;QACZ,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,KAAK;KACnB,CAAC;AACH,CAAC;AAgBD,MAAM,WAAW,GAAG;IACnB,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,kBAAkB;IAC5B,KAAK,EAAE,eAAe;CAC8C,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAA8B;IAE9B,MAAM,UA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B,KAAK,OAAO;YACX,OAAO,QAAQ,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC3C,SAAS,CAAC;YACT,MAAM,SAAS,GAAG,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;YAC3D,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC7B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;YACzC,CAAC;YAED,OAAO,GAAG,KAAK,GAAG,IAAI,QAAQ,KAAK,SAAS;gBAC3C,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,KAAK,MAAM,EAAE;gBACtD,CAAC,CAAC,SAAS,CAAC;QACd,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ import type { JSX } from "preact";
3
+ import { type BitGridBitOrder, type BitGridField, type BitGridUnit } from "../bit-grid/bit-grid.js";
4
+ /** Props of {@link BitGrid}. */
5
+ export type BitGridProps = {
6
+ /** Its accessible name; it is not drawn. */
7
+ label: string;
8
+ bytes: Uint8Array;
9
+ /** One cell per bit, or per byte in hex. Defaults to `bit`. */
10
+ unit?: BitGridUnit;
11
+ /** Defaults to `msb`. */
12
+ bitOrder?: BitGridBitOrder;
13
+ /** Cells per row. Defaults to 32 bits or 16 bytes. */
14
+ columns?: number;
15
+ /** What the bytes are compared with; the cells that differ are marked. */
16
+ reference?: Uint8Array;
17
+ /** Byte ranges coloured as named fields. */
18
+ fields?: readonly BitGridField[];
19
+ /** The cell drawn as chosen, by its index. */
20
+ selectedIndex?: number;
21
+ /**
22
+ * A cell activated by a click, Enter or Space, by its index. Without, the
23
+ * grid is read-only and still navigable.
24
+ */
25
+ onActivate?: Callable<[index: number]>;
26
+ id?: string;
27
+ class?: string;
28
+ };
29
+ /**
30
+ * Bytes as a grid of bits or hex digits, with the cells that differ from a
31
+ * reference marked and named fields coloured. A WAI-ARIA `grid`: one tab stop,
32
+ * the arrows, Home and End move among the cells, and Enter or Space activates
33
+ * one when `onActivate` is given.
34
+ *
35
+ * @throws {RangeError} When a field is not a range of whole bytes inside
36
+ * `bytes`, two fields overlap, or `columns` is not a positive integer.
37
+ */
38
+ export declare function BitGrid(props: BitGridProps): JSX.Element;
39
+ //# sourceMappingURL=bit-grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-grid.d.ts","sourceRoot":"","sources":["../../src/preact/bit-grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAIlC,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAKhB,MAAM,yBAAyB,CAAC;AAGjC,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG;IAC1B,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,CAAC;IAClB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,8CAA8C;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CAgJxD"}