@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,101 @@
1
+ /**
2
+ * A live region a newly made region waits this long before its first
3
+ * announcement, so assistive technology has registered it: one added and filled
4
+ * at once is not reliably read.
5
+ */
6
+ const REGISTER_DELAY_MS_ = 100;
7
+ /** How long an announcement stays in the region before it is removed. */
8
+ const CLEAR_DELAY_MS_ = 7000;
9
+ const VISUALLY_HIDDEN_ = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap";
10
+ /**
11
+ * Announces text to screen readers through visually hidden live regions, a
12
+ * polite `status` and an assertive `alert`. Each announcement is a node added
13
+ * to its region, so the same text twice is read twice, and a quick second one
14
+ * does not replace the first.
15
+ *
16
+ * While a modal dialog is open, the rest of the page is inert and hidden from
17
+ * assistive technology, live regions included: the announcement then goes to a
18
+ * region inside the open dialog that holds focus.
19
+ *
20
+ * Framework-free.
21
+ */
22
+ export class LiveAnnouncer_ {
23
+ document_;
24
+ regions_ = new Map();
25
+ timers_ = new Set();
26
+ constructor(document) {
27
+ this.document_ = document;
28
+ }
29
+ announce(lines, urgency) {
30
+ const host = this.host_();
31
+ const existing = this.regions_.get(host);
32
+ const regions = existing ?? this.createRegions_(host);
33
+ const region = regions[urgency];
34
+ const entry = this.document_.createElement("div");
35
+ for (const line of lines) {
36
+ const paragraph = this.document_.createElement("p");
37
+ paragraph.textContent = line;
38
+ entry.append(paragraph);
39
+ }
40
+ const add = () => {
41
+ region.append(entry);
42
+ this.later_(() => {
43
+ entry.remove();
44
+ }, CLEAR_DELAY_MS_);
45
+ };
46
+ if (existing === undefined) {
47
+ this.later_(add, REGISTER_DELAY_MS_);
48
+ }
49
+ else {
50
+ add();
51
+ }
52
+ }
53
+ [Symbol.dispose]() {
54
+ for (const timer of this.timers_) {
55
+ clearTimeout(timer);
56
+ }
57
+ this.timers_.clear();
58
+ for (const { polite, assertive } of this.regions_.values()) {
59
+ polite.remove();
60
+ assertive.remove();
61
+ }
62
+ this.regions_.clear();
63
+ }
64
+ /** The open dialog holding focus, or else the body. */
65
+ host_() {
66
+ for (const [host, regions] of this.regions_) {
67
+ if (!host.isConnected) {
68
+ regions.polite.remove();
69
+ regions.assertive.remove();
70
+ this.regions_.delete(host);
71
+ }
72
+ }
73
+ const dialog = this.document_.activeElement?.closest("dialog[open]");
74
+ return dialog ?? this.document_.body;
75
+ }
76
+ createRegions_(host) {
77
+ const create = (urgency) => {
78
+ const region = this.document_.createElement("div");
79
+ region.setAttribute("role", urgency === "polite" ? "status" : "alert");
80
+ region.setAttribute("aria-live", urgency);
81
+ region.setAttribute("style", VISUALLY_HIDDEN_);
82
+ region.dataset["ackLiveRegion"] = urgency;
83
+ host.append(region);
84
+ return region;
85
+ };
86
+ const regions = {
87
+ polite: create("polite"),
88
+ assertive: create("assertive"),
89
+ };
90
+ this.regions_.set(host, regions);
91
+ return regions;
92
+ }
93
+ later_(action, delayMs) {
94
+ const timer = setTimeout(() => {
95
+ this.timers_.delete(timer);
96
+ action();
97
+ }, delayMs);
98
+ this.timers_.add(timer);
99
+ }
100
+ }
101
+ //# sourceMappingURL=_live-announcer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_live-announcer.js","sourceRoot":"","sources":["../../src/adapter/_live-announcer.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,yEAAyE;AACzE,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,MAAM,gBAAgB,GACrB,+HAA+H,CAAC;AAEjI;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,cAAc;IACT,SAAS,CAAW;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;IACxC,OAAO,GAAG,IAAI,GAAG,EAAiC,CAAC;IAEpE,YAAY,QAAkB;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,QAAQ,CAAC,KAAwB,EAAE,OAAqB;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAA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Z,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-classes.d.ts","sourceRoot":"","sources":["../../src/adapter/join-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE3E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-classes.js","sourceRoot":"","sources":["../../src/adapter/join-classes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAyB;IAClE,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The side of its anchor a popover sits on, in logical terms: `block-end` is
3
+ * below in a horizontal writing mode, `inline-end` after it in the reading
4
+ * direction (right in a left-to-right page). It moves to the opposite side when
5
+ * the viewport has no room for it.
6
+ */
7
+ export type AnchoredSide = "block-start" | "block-end" | "inline-start" | "inline-end";
8
+ /**
9
+ * How a popover lines up with its anchor along that side: its start edges
10
+ * together, centred, or its end edges together. It shifts into the viewport
11
+ * when it would overflow it.
12
+ */
13
+ export type AnchoredAlign = "start" | "center" | "end";
14
+ /** The attributes the stylesheet places an anchored popover by. */
15
+ export type AnchoredAttributes = {
16
+ "data-side": AnchoredSide;
17
+ "data-align": AnchoredAlign;
18
+ };
19
+ //# sourceMappingURL=anchored.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchored.d.ts","sourceRoot":"","sources":["../../src/anchored/anchored.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACrB,aAAa,GACb,WAAW,GACX,cAAc,GACd,YAAY,CAAC;AAEhB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEvD,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG;IAChC,WAAW,EAAE,YAAY,CAAC;IAC1B,YAAY,EAAE,aAAa,CAAC;CAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=anchored.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchored.js","sourceRoot":"","sources":["../../src/anchored/anchored.ts"],"names":[],"mappings":""}
@@ -0,0 +1,151 @@
1
+ /** What one cell of a {@link bitGridCells} grid shows: a bit, or a whole byte. */
2
+ export type BitGridUnit = "bit" | "byte";
3
+ /**
4
+ * The order of a byte's bits across the grid: most significant first (`msb`,
5
+ * how a byte is written in binary), or least significant first (`lsb`, how a
6
+ * bit field is numbered in many protocols).
7
+ */
8
+ export type BitGridBitOrder = "msb" | "lsb";
9
+ /**
10
+ * A named run of bytes, `[start, end)`, coloured as one field: a header, a
11
+ * nonce, a length.
12
+ */
13
+ export type BitGridField = {
14
+ readonly label: string;
15
+ readonly start: number;
16
+ readonly end: number;
17
+ };
18
+ /**
19
+ * How many field colours the default stylesheet defines. A field's
20
+ * {@link BitGridCell.fieldTone} cycles through them, so neighbouring fields
21
+ * differ.
22
+ */
23
+ export declare const BIT_GRID_FIELD_TONES = 6;
24
+ /** One cell of a bit grid. */
25
+ export type BitGridCell = {
26
+ /** The cell's position in the grid, counted in its unit. */
27
+ readonly index: number;
28
+ /** The byte it shows, or the byte its bit belongs to. */
29
+ readonly byteIndex: number;
30
+ /**
31
+ * For a bit, its weight in its byte: 7 for the most significant bit, 0 for
32
+ * the least. `undefined` for a byte cell.
33
+ */
34
+ readonly bit: number | undefined;
35
+ /** 0 or 1 for a bit, 0 to 255 for a byte. */
36
+ readonly value: number;
37
+ /** What the cell draws: `"0"` or `"1"`, or two lower-case hex digits. */
38
+ readonly text: string;
39
+ /**
40
+ * Whether it differs from the reference at the same position; a position past
41
+ * the reference's end counts as changed. `false` without a reference.
42
+ */
43
+ readonly changed: boolean;
44
+ /** The index of the field it belongs to, `undefined` for none. */
45
+ readonly field: number | undefined;
46
+ /** The field's colour slot, `field` modulo {@link BIT_GRID_FIELD_TONES}. */
47
+ readonly fieldTone: number | undefined;
48
+ };
49
+ /** Input of {@link bitGridCells}. */
50
+ export type BitGridCellsInput = {
51
+ bytes: Uint8Array;
52
+ /** Defaults to `bit`. */
53
+ unit?: BitGridUnit;
54
+ /** Defaults to `msb`. Ignored for byte cells. */
55
+ bitOrder?: BitGridBitOrder;
56
+ /** What the bytes are compared with, to mark the cells that changed. */
57
+ reference?: Uint8Array;
58
+ /** Non-overlapping byte ranges inside `bytes`. */
59
+ fields?: readonly BitGridField[];
60
+ };
61
+ /**
62
+ * The cells of a grid showing `bytes` bit by bit or byte by byte, each marked
63
+ * with whether it differs from `reference` and which field holds it.
64
+ *
65
+ * Time complexity: O(n) in the number of cells plus the bytes the fields span.
66
+ * Memory: O(n).
67
+ *
68
+ * @example
69
+ * const cells = bitGridCells({
70
+ * bytes: Uint8Array.of(0b1010_0000),
71
+ * reference: Uint8Array.of(0b1000_0000),
72
+ * });
73
+ * cells.map((cell) => cell.text).join(""); // "10100000"
74
+ * cells[2]!.changed; // true
75
+ *
76
+ * @throws {RangeError} When a field is not a non-empty range of whole bytes
77
+ * inside `bytes`, or two fields share a byte.
78
+ */
79
+ export declare function bitGridCells(input: BitGridCellsInput): BitGridCell[];
80
+ /**
81
+ * What a screen reader says for one cell: its position, its value, and whether
82
+ * it changed and which field holds it, as `"bit 3 of byte 0: 1, changed,
83
+ * header"` or `"byte 4: hex 1f"`. The value is the cell's visible text as a
84
+ * word of its own, so the name contains the label a sighted user reads (WCAG
85
+ * 2.5.3).
86
+ *
87
+ * Time complexity: O(1). Memory: O(1).
88
+ *
89
+ * @example
90
+ * const [cell] = bitGridCells({ bytes: Uint8Array.of(0x1f), unit: "byte" });
91
+ * bitGridCellLabel(cell!); // "byte 0: hex 1f"
92
+ */
93
+ export declare function bitGridCellLabel(cell: BitGridCell, fields?: readonly BitGridField[]): string;
94
+ /** Options of {@link bitGridKeyIndex}. */
95
+ export type BitGridKeyOptions = {
96
+ /**
97
+ * Whether Control (or Command) is held: Home and End then reach the grid's
98
+ * ends.
99
+ */
100
+ ctrlKey?: boolean;
101
+ };
102
+ /**
103
+ * The cell a key moves focus to in a grid of `count` cells laid out `columns`
104
+ * to a row, per the WAI-ARIA grid pattern: Left and Right within a row, Up and
105
+ * Down to the same column of the next row, Home and End to the row's ends,
106
+ * Control with Home or End to the first and last cell. The grid reads left to
107
+ * right whatever the page's direction, as bytes are written. `undefined` for
108
+ * another key, or when no cell lies that way.
109
+ *
110
+ * Time complexity: O(1). Memory: O(1).
111
+ *
112
+ * @example
113
+ * bitGridKeyIndex(0, "ArrowDown", 64, 32); // 32
114
+ * bitGridKeyIndex(31, "ArrowRight", 64, 32); // undefined: the row ends
115
+ * bitGridKeyIndex(40, "End", 64, 32, { ctrlKey: true }); // 63
116
+ *
117
+ * @throws {RangeError} When `count` is not a non-negative safe integer,
118
+ * `columns` not a positive one, or `current` lies outside [0, count).
119
+ */
120
+ export declare function bitGridKeyIndex(current: number, key: string, count: number, columns: number, options?: BitGridKeyOptions): number | undefined;
121
+ /** The ARIA attributes of a bit grid's root (WAI-ARIA 1.2 `grid` role). */
122
+ export type BitGridAttributes = {
123
+ role: "grid";
124
+ "aria-label": string;
125
+ "aria-rowcount": number;
126
+ "aria-colcount": number;
127
+ "aria-readonly"?: true;
128
+ };
129
+ /** Input of {@link bitGridAttributes}. */
130
+ export type BitGridAttributesInput = {
131
+ label: string;
132
+ count: number;
133
+ columns: number;
134
+ /** Whether a cell can be activated; a grid that cannot is read-only. */
135
+ isActivatable: boolean;
136
+ };
137
+ /**
138
+ * The attributes of a bit grid's root: the `grid` role with its name and size,
139
+ * read-only unless a cell can be activated.
140
+ *
141
+ * Time complexity: O(1). Memory: O(1).
142
+ *
143
+ * @example
144
+ * bitGridAttributes({ label: "Digest", count: 256, columns: 32, isActivatable: false });
145
+ * // { role: "grid", "aria-label": "Digest", "aria-rowcount": 8,
146
+ * // "aria-colcount": 32, "aria-readonly": true }
147
+ *
148
+ * @throws {RangeError} When `columns` is not a positive safe integer.
149
+ */
150
+ export declare function bitGridAttributes(input: BitGridAttributesInput): BitGridAttributes;
151
+ //# sourceMappingURL=bit-grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-grid.d.ts","sourceRoot":"","sources":["../../src/bit-grid/bit-grid.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;AAEzC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,8BAA8B;AAC9B,MAAM,MAAM,WAAW,GAAG;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAA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AAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,aAAa,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,sBAAsB,GAC3B,iBAAiB,CAkBnB"}
@@ -0,0 +1,201 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ /**
3
+ * How many field colours the default stylesheet defines. A field's
4
+ * {@link BitGridCell.fieldTone} cycles through them, so neighbouring fields
5
+ * differ.
6
+ */
7
+ export const BIT_GRID_FIELD_TONES = 6;
8
+ function byteFields_(length, fields) {
9
+ const owner = Array.from({ length });
10
+ for (const [index, field] of fields.entries()) {
11
+ const { start, end } = field;
12
+ if (!(Number.isSafeInteger(start) &&
13
+ Number.isSafeInteger(end) &&
14
+ start >= 0 &&
15
+ start < end &&
16
+ end <= length)) {
17
+ throw new RangeError(`A bit grid field must be a non-empty range of whole bytes inside the ${length} given, got "${field.label}" from ${describeValue(start)} to ${describeValue(end)}.`);
18
+ }
19
+ for (let byte = start; byte < end; byte++) {
20
+ const previous = owner[byte];
21
+ if (previous !== undefined) {
22
+ throw new RangeError(`Bit grid fields must not overlap: "${field.label}" and "${fields[previous].label}" both hold byte ${byte}.`);
23
+ }
24
+ owner[byte] = index;
25
+ }
26
+ }
27
+ return owner;
28
+ }
29
+ /**
30
+ * The cells of a grid showing `bytes` bit by bit or byte by byte, each marked
31
+ * with whether it differs from `reference` and which field holds it.
32
+ *
33
+ * Time complexity: O(n) in the number of cells plus the bytes the fields span.
34
+ * Memory: O(n).
35
+ *
36
+ * @example
37
+ * const cells = bitGridCells({
38
+ * bytes: Uint8Array.of(0b1010_0000),
39
+ * reference: Uint8Array.of(0b1000_0000),
40
+ * });
41
+ * cells.map((cell) => cell.text).join(""); // "10100000"
42
+ * cells[2]!.changed; // true
43
+ *
44
+ * @throws {RangeError} When a field is not a non-empty range of whole bytes
45
+ * inside `bytes`, or two fields share a byte.
46
+ */
47
+ export function bitGridCells(input) {
48
+ const { bytes, unit = "bit", bitOrder = "msb", reference, fields = [], } = input;
49
+ const owner = byteFields_(bytes.length, fields);
50
+ const cells = [];
51
+ for (const [byteIndex, byte] of bytes.entries()) {
52
+ const field = owner[byteIndex];
53
+ const fieldTone = field === undefined ? undefined : field % BIT_GRID_FIELD_TONES;
54
+ const referenceByte = reference?.[byteIndex];
55
+ if (unit === "byte") {
56
+ cells.push({
57
+ index: byteIndex,
58
+ byteIndex,
59
+ bit: undefined,
60
+ value: byte,
61
+ text: byte.toString(16).padStart(2, "0"),
62
+ changed: reference !== undefined && referenceByte !== byte,
63
+ field,
64
+ fieldTone,
65
+ });
66
+ continue;
67
+ }
68
+ for (let position = 0; position < 8; position++) {
69
+ const bit = bitOrder === "msb" ? 7 - position : position;
70
+ const value = (byte >> bit) & 1;
71
+ cells.push({
72
+ index: byteIndex * 8 + position,
73
+ byteIndex,
74
+ bit,
75
+ value,
76
+ text: String(value),
77
+ changed: reference !== undefined &&
78
+ (referenceByte === undefined ||
79
+ ((referenceByte >> bit) & 1) !== value),
80
+ field,
81
+ fieldTone,
82
+ });
83
+ }
84
+ }
85
+ return cells;
86
+ }
87
+ /**
88
+ * What a screen reader says for one cell: its position, its value, and whether
89
+ * it changed and which field holds it, as `"bit 3 of byte 0: 1, changed,
90
+ * header"` or `"byte 4: hex 1f"`. The value is the cell's visible text as a
91
+ * word of its own, so the name contains the label a sighted user reads (WCAG
92
+ * 2.5.3).
93
+ *
94
+ * Time complexity: O(1). Memory: O(1).
95
+ *
96
+ * @example
97
+ * const [cell] = bitGridCells({ bytes: Uint8Array.of(0x1f), unit: "byte" });
98
+ * bitGridCellLabel(cell!); // "byte 0: hex 1f"
99
+ */
100
+ export function bitGridCellLabel(cell, fields = []) {
101
+ const parts = [
102
+ cell.bit === undefined
103
+ ? `byte ${cell.byteIndex}: hex ${cell.text}`
104
+ : `bit ${cell.bit} of byte ${cell.byteIndex}: ${cell.text}`,
105
+ ];
106
+ if (cell.changed) {
107
+ parts.push("changed");
108
+ }
109
+ if (cell.field !== undefined) {
110
+ parts.push(fields[cell.field]?.label ?? `field ${cell.field}`);
111
+ }
112
+ return parts.join(", ");
113
+ }
114
+ /**
115
+ * The cell a key moves focus to in a grid of `count` cells laid out `columns`
116
+ * to a row, per the WAI-ARIA grid pattern: Left and Right within a row, Up and
117
+ * Down to the same column of the next row, Home and End to the row's ends,
118
+ * Control with Home or End to the first and last cell. The grid reads left to
119
+ * right whatever the page's direction, as bytes are written. `undefined` for
120
+ * another key, or when no cell lies that way.
121
+ *
122
+ * Time complexity: O(1). Memory: O(1).
123
+ *
124
+ * @example
125
+ * bitGridKeyIndex(0, "ArrowDown", 64, 32); // 32
126
+ * bitGridKeyIndex(31, "ArrowRight", 64, 32); // undefined: the row ends
127
+ * bitGridKeyIndex(40, "End", 64, 32, { ctrlKey: true }); // 63
128
+ *
129
+ * @throws {RangeError} When `count` is not a non-negative safe integer,
130
+ * `columns` not a positive one, or `current` lies outside [0, count).
131
+ */
132
+ export function bitGridKeyIndex(current, key, count, columns, options = {}) {
133
+ if (!(Number.isSafeInteger(count) && count >= 0)) {
134
+ throw new RangeError(`A bit grid's cell count must be a non-negative safe integer, got ${describeValue(count)}.`);
135
+ }
136
+ if (!(Number.isSafeInteger(columns) && columns > 0)) {
137
+ throw new RangeError(`A bit grid's column count must be a positive safe integer, got ${describeValue(columns)}.`);
138
+ }
139
+ if (!(Number.isSafeInteger(current) && current >= 0 && current < count)) {
140
+ throw new RangeError(`The focused cell must lie in [0, ${count}), got ${describeValue(current)}.`);
141
+ }
142
+ const column = current % columns;
143
+ const rowStart = current - column;
144
+ let next;
145
+ switch (key) {
146
+ case "ArrowLeft":
147
+ next = column === 0 ? -1 : current - 1;
148
+ break;
149
+ case "ArrowRight":
150
+ next = column === columns - 1 ? -1 : current + 1;
151
+ break;
152
+ case "ArrowUp":
153
+ next = current - columns;
154
+ break;
155
+ case "ArrowDown":
156
+ next = current + columns;
157
+ break;
158
+ case "Home":
159
+ next = options.ctrlKey === true ? 0 : rowStart;
160
+ break;
161
+ case "End":
162
+ next =
163
+ options.ctrlKey === true
164
+ ? count - 1
165
+ : Math.min(rowStart + columns, count) - 1;
166
+ break;
167
+ default:
168
+ return undefined;
169
+ }
170
+ return next >= 0 && next < count && next !== current ? next : undefined;
171
+ }
172
+ /**
173
+ * The attributes of a bit grid's root: the `grid` role with its name and size,
174
+ * read-only unless a cell can be activated.
175
+ *
176
+ * Time complexity: O(1). Memory: O(1).
177
+ *
178
+ * @example
179
+ * bitGridAttributes({ label: "Digest", count: 256, columns: 32, isActivatable: false });
180
+ * // { role: "grid", "aria-label": "Digest", "aria-rowcount": 8,
181
+ * // "aria-colcount": 32, "aria-readonly": true }
182
+ *
183
+ * @throws {RangeError} When `columns` is not a positive safe integer.
184
+ */
185
+ export function bitGridAttributes(input) {
186
+ const { label, count, columns, isActivatable } = input;
187
+ if (!(Number.isSafeInteger(columns) && columns > 0)) {
188
+ throw new RangeError(`A bit grid's column count must be a positive safe integer, got ${describeValue(columns)}.`);
189
+ }
190
+ const attributes = {
191
+ role: "grid",
192
+ "aria-label": label,
193
+ "aria-rowcount": Math.ceil(count / columns),
194
+ "aria-colcount": Math.min(columns, count),
195
+ };
196
+ if (!isActivatable) {
197
+ attributes["aria-readonly"] = true;
198
+ }
199
+ return attributes;
200
+ }
201
+ //# sourceMappingURL=bit-grid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-grid.js","sourceRoot":"","sources":["../../src/bit-grid/bit-grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAsB7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAyCtC,SAAS,WAAW,CACnB,MAAc,EACd,MAA+B;IAE/B,MAAM,KAAK,GAA2B,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM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,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM;QACP;YACC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC;AAoBD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IACvD,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,UAAU,CACnB,kEAAkE,aAAa,CAAC,OAAO,CAAC,GAAG,CAC3F,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAsB;QACrC,IAAI,EAAE,MAAM;QACZ,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;QAC3C,eAAe,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;KACzC,CAAC;IACF,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,UAAU,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { type Predicate } from "@ac-kit/core";
2
+ import type { KeyInput } from "@ac-kit/ui-gesture";
3
+ /** Options of {@link Typeahead}. */
4
+ export type TypeaheadOptions = {
5
+ /**
6
+ * How long after a character the next one still extends the query, in ms.
7
+ * Defaults to 500, as the WAI-ARIA practices suggest.
8
+ */
9
+ readonly timeoutMs?: number;
10
+ };
11
+ /**
12
+ * The query a person types into a list to reach an item by its name (the
13
+ * WAI-ARIA typeahead of menus, listboxes and trees): the characters typed
14
+ * within `timeoutMs` of each other. Every time is passed in, in ms.
15
+ *
16
+ * @example
17
+ * const typeahead = new Typeahead();
18
+ * typeahead.type("c", 0); // "c"
19
+ * typeahead.type("h", 200); // "ch"
20
+ * typeahead.type("a", 900); // "a": the query timed out
21
+ */
22
+ export declare class Typeahead {
23
+ private readonly timeoutMs_;
24
+ private query_;
25
+ private lastTime_;
26
+ /** @throws {RangeError} When `timeoutMs` is negative or not finite. */
27
+ constructor(options?: TypeaheadOptions);
28
+ /**
29
+ * Whether a query is in progress at `time`: a character was typed less than
30
+ * `timeoutMs` before. A list lets Space extend the query then, rather than
31
+ * activate an item.
32
+ */
33
+ isActive(time: number): boolean;
34
+ /** Adds `character`, typed at `time`, and returns the query to look up. */
35
+ type(character: string, time: number): string;
36
+ /** Forgets the query: the list closed, or an item was chosen. */
37
+ reset(): void;
38
+ /**
39
+ * Adds `character`, typed at `time`, and returns the item the query reaches
40
+ * among `labels` from `current` ({@link typeaheadIndex}): what a list does
41
+ * with each character typed.
42
+ *
43
+ * Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
44
+ * O(q).
45
+ *
46
+ * @example
47
+ * const typeahead = new Typeahead();
48
+ * typeahead.find("b", 0, ["Apple", "Banana", "Blueberry"], 0); // 1
49
+ * typeahead.find("l", 100, ["Apple", "Banana", "Blueberry"], 1); // 2
50
+ *
51
+ * @throws {RangeError} When `current` is not an index of `labels`.
52
+ */
53
+ find(character: string, time: number, labels: readonly string[], current: number | undefined, options?: TypeaheadIndexOptions): number | undefined;
54
+ }
55
+ /** Options of {@link typeaheadIndex}. */
56
+ export type TypeaheadIndexOptions = {
57
+ /** The locales whose collation compares names. Defaults to the runtime's. */
58
+ readonly locales?: Intl.LocalesArgument;
59
+ /** Items the query skips. Defaults to none. */
60
+ readonly isDisabled?: Predicate<[index: number]>;
61
+ };
62
+ /**
63
+ * The item a typeahead query moves to among `labels`, per the WAI-ARIA
64
+ * practices: the next item after `current` whose name starts with a single
65
+ * character, going round, so typing it again cycles through those items (a
66
+ * repeated character, `"aaa"`, cycles likewise); for a longer query, the first
67
+ * from `current` on whose name starts with it, so the item stays while it
68
+ * matches. Without `current`, the search starts at the first item.
69
+ *
70
+ * Names are compared grapheme by grapheme, ignoring case and accents as the
71
+ * locale's collation does (`sensitivity: "base"`) and leading white space.
72
+ * `undefined` for an empty query or when no enabled item matches.
73
+ *
74
+ * Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
75
+ * O(q).
76
+ *
77
+ * @example
78
+ * typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "a"); // 1
79
+ * typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "apr"); // 1
80
+ * typeaheadIndex(["Éclair", "Fig"], 1, "e"); // 0
81
+ *
82
+ * @throws {RangeError} When `current` is not an index of `labels`.
83
+ */
84
+ export declare function typeaheadIndex(labels: readonly string[], current: number | undefined, query: string, options?: TypeaheadIndexOptions): number | undefined;
85
+ /**
86
+ * Whether a key types a character a typeahead takes: one grapheme, not a
87
+ * control character, without Ctrl, Alt or Meta (the browser's and the system's
88
+ * shortcuts). Shift passes, for capitals; so does Space, which a list takes as
89
+ * part of a query in progress only (see {@link Typeahead.isActive}).
90
+ *
91
+ * Time complexity: O(1) for a key name of bounded length. Memory: O(1).
92
+ *
93
+ * @example
94
+ * isTypeaheadKey({ key: "a" }); // true
95
+ * isTypeaheadKey({ key: "Enter" }); // false: a named key
96
+ * isTypeaheadKey({ key: "s", ctrlKey: true }); // false: a shortcut
97
+ */
98
+ export declare function isTypeaheadKey(input: KeyInput): boolean;
99
+ /**
100
+ * The character a key adds to a list's typeahead query: a typed character
101
+ * ({@link isTypeaheadKey}), Space only while a query is in progress (otherwise
102
+ * Space selects or activates an item). `undefined` for any other key.
103
+ *
104
+ * Time complexity: O(1) for a key name of bounded length. Memory: O(1).
105
+ *
106
+ * @example
107
+ * typeaheadCharacter({ key: "a" }, false); // "a"
108
+ * typeaheadCharacter({ key: " " }, false); // undefined: Space selects
109
+ * typeaheadCharacter({ key: " " }, true); // " ": "new y" goes on
110
+ */
111
+ export declare function typeaheadCharacter(input: KeyInput, isTypingAhead: boolean): string | undefined;
112
+ //# sourceMappingURL=typeahead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeahead.d.ts","sourceRoot":"","sources":["../../src/focus/typeahead.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,SAAS,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,SAAS,CAA4B;IAE7C,uEAAuE;IACvE,YAAY,OAAO,GAAE,gBAAqB,EAIzC;IAED;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9B;IAED,2EAA2E;IAC3E,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK5C;IAED,iEAAiE;IACjE,KAAK,IAAI,IAAI,CAGZ;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAI,CACH,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,CAAC,EAAE,qBAAqB,GAC7B,MAAM,GAAG,SAAS,CAEpB;CACD;AAED,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE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