@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
package/dist/tone.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { LiteralUnion } from "type-fest";
2
+ /**
3
+ * The colour role a control lights in, rendered as its `data-tone` attribute.
4
+ * The default stylesheet colours the four named roles; any other name is the
5
+ * caller's to colour, through the same custom properties.
6
+ */
7
+ export type ControlTone = LiteralUnion<"accent" | "positive" | "warning" | "negative", string>;
8
+ //# sourceMappingURL=tone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tone.d.ts","sourceRoot":"","sources":["../src/tone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,CACrC,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,EAC9C,MAAM,CACN,CAAC"}
package/dist/tone.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tone.js","sourceRoot":"","sources":["../src/tone.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Which way a toolbar lays out its controls, and so which arrows move through
3
+ * them.
4
+ */
5
+ export type ToolbarOrientation = "horizontal" | "vertical";
6
+ /**
7
+ * The attributes of a toolbar, keyed by their HTML attribute names.
8
+ * `aria-orientation` is present for `vertical` only, the role's default being
9
+ * horizontal.
10
+ */
11
+ export type ToolbarAttributes = {
12
+ role: "toolbar";
13
+ "aria-label": string;
14
+ "aria-orientation"?: "vertical";
15
+ };
16
+ /** Input of {@link toolbarAttributes}. */
17
+ export type ToolbarAttributesInput = {
18
+ /** Its accessible name. */
19
+ label: string;
20
+ /** Defaults to `horizontal`. */
21
+ orientation?: ToolbarOrientation;
22
+ };
23
+ /**
24
+ * The attributes of a toolbar (WAI-ARIA toolbar pattern): a named container of
25
+ * controls with a single tab stop, the arrow keys moving between them. Pair it
26
+ * with `rovingFocusIndex` for the key handling.
27
+ *
28
+ * Time complexity: O(1). Memory: O(1).
29
+ *
30
+ * @example
31
+ * toolbarAttributes({ label: "Playback" });
32
+ * // { role: "toolbar", "aria-label": "Playback" }
33
+ */
34
+ export declare function toolbarAttributes(input: ToolbarAttributesInput): ToolbarAttributes;
35
+ //# sourceMappingURL=toolbar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolbar.d.ts","sourceRoot":"","sources":["../../src/toolbar/toolbar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,sBAAsB,GAC3B,iBAAiB,CAWnB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The attributes of a toolbar (WAI-ARIA toolbar pattern): a named container of
3
+ * controls with a single tab stop, the arrow keys moving between them. Pair it
4
+ * with `rovingFocusIndex` for the key handling.
5
+ *
6
+ * Time complexity: O(1). Memory: O(1).
7
+ *
8
+ * @example
9
+ * toolbarAttributes({ label: "Playback" });
10
+ * // { role: "toolbar", "aria-label": "Playback" }
11
+ */
12
+ export function toolbarAttributes(input) {
13
+ const { label, orientation = "horizontal" } = input;
14
+ const attributes = {
15
+ role: "toolbar",
16
+ "aria-label": label,
17
+ };
18
+ if (orientation === "vertical") {
19
+ attributes["aria-orientation"] = "vertical";
20
+ }
21
+ return attributes;
22
+ }
23
+ //# sourceMappingURL=toolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../src/toolbar/toolbar.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC;IACpD,MAAM,UAAU,GAAsB;QACrC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;KACnB,CAAC;IACF,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;QAChC,UAAU,CAAC,kBAAkB,CAAC,GAAG,UAAU,CAAC;IAC7C,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,183 @@
1
+ import { type CallableNoArgs } from "@ac-kit/core";
2
+ import type { AnchoredAlign, AnchoredAttributes, AnchoredSide } from "../anchored/anchored.js";
3
+ /** The attributes of a tooltip, keyed by their HTML attribute names. */
4
+ export type TooltipAttributes = AnchoredAttributes & {
5
+ role: "tooltip";
6
+ };
7
+ /** Input of {@link tooltipAttributes}. */
8
+ export type TooltipAttributesInput = {
9
+ /** Defaults to `block-start`: above the trigger. */
10
+ side?: AnchoredSide;
11
+ /** Defaults to `center`. */
12
+ align?: AnchoredAlign;
13
+ };
14
+ /**
15
+ * The attributes of a tooltip (WAI-ARIA tooltip pattern): the `tooltip` role,
16
+ * and where the stylesheet places it against its trigger.
17
+ *
18
+ * Time complexity: O(1). Memory: O(1).
19
+ *
20
+ * @example
21
+ * tooltipAttributes(); // { role: "tooltip", "data-side": "block-start", "data-align": "center" }
22
+ */
23
+ export declare function tooltipAttributes(input?: TooltipAttributesInput): TooltipAttributes;
24
+ /**
25
+ * What a tooltip is to its trigger: a `description` read after the trigger's
26
+ * name (the default), or its `label`, the name itself, for a control drawn as
27
+ * an icon alone.
28
+ */
29
+ export type TooltipRelation = "description" | "label";
30
+ /**
31
+ * The attributes a tooltip's trigger takes, keyed by their HTML attribute
32
+ * names.
33
+ */
34
+ export type TooltipTriggerAttributes = {
35
+ "aria-describedby": string;
36
+ } | {
37
+ "aria-labelledby": string;
38
+ };
39
+ /** Input of {@link tooltipTriggerAttributes}. */
40
+ export type TooltipTriggerAttributesInput = {
41
+ /** The tooltip's id. */
42
+ tooltipId: string;
43
+ /** Defaults to `description`. */
44
+ relation?: TooltipRelation;
45
+ };
46
+ /**
47
+ * The attribute linking a trigger to its tooltip, so assistive technology reads
48
+ * the tooltip whether it is shown or not: `aria-describedby`, or
49
+ * `aria-labelledby` when the tooltip names the trigger (it then wins over an
50
+ * `aria-label`).
51
+ *
52
+ * Time complexity: O(1). Memory: O(1).
53
+ *
54
+ * @example
55
+ * tooltipTriggerAttributes({ tooltipId: "t", relation: "label" });
56
+ * // { "aria-labelledby": "t" }
57
+ */
58
+ export declare function tooltipTriggerAttributes(input: TooltipTriggerAttributesInput): TooltipTriggerAttributes;
59
+ /**
60
+ * Where a tooltip stands: whether it is open and, when a change is pending,
61
+ * when it is due. The other members record what is hovered and focused; treat
62
+ * the state as opaque and pass it back to {@link tooltipStep}.
63
+ */
64
+ export type TooltipState = {
65
+ readonly isOpen: boolean;
66
+ /**
67
+ * When the pending change is due, in the caller's clock: an opening while
68
+ * closed, a closing while open. `undefined` when none is pending; call
69
+ * {@link tooltipStep} with a `time` input then.
70
+ */
71
+ readonly deadline: number | undefined;
72
+ readonly isTriggerHovered: boolean;
73
+ readonly isTooltipHovered: boolean;
74
+ readonly isFocused: boolean;
75
+ /** Dismissed or pressed: closed until hover and focus have both ended. */
76
+ readonly isSuppressed: boolean;
77
+ };
78
+ /** A tooltip closed, nothing hovered nor focused: where every one starts. */
79
+ export declare const TOOLTIP_CLOSED: TooltipState;
80
+ /**
81
+ * What happens to a tooltip:
82
+ *
83
+ * - `hover` — a mouse or pen starts or stops hovering the trigger or the open
84
+ * tooltip (touch does not hover);
85
+ * - `focus` — the trigger gains or loses a focus the browser shows
86
+ * (`:focus-visible`, from the keyboard), not the focus a click gives;
87
+ * - `press` — the trigger is pressed;
88
+ * - `dismiss` — Escape;
89
+ * - `time` — the clock reached the state's `deadline`.
90
+ */
91
+ export type TooltipInput = {
92
+ readonly kind: "hover";
93
+ readonly part: "trigger" | "tooltip";
94
+ readonly isHovered: boolean;
95
+ } | {
96
+ readonly kind: "focus";
97
+ readonly isFocused: boolean;
98
+ } | {
99
+ readonly kind: "press";
100
+ } | {
101
+ readonly kind: "dismiss";
102
+ } | {
103
+ readonly kind: "time";
104
+ };
105
+ /** Timing of {@link tooltipStep}. */
106
+ export type TooltipTiming = {
107
+ /** From the start of a hover to the opening, in ms. Defaults to 500. */
108
+ readonly showDelayMs?: number;
109
+ /**
110
+ * From the end of a hover to the closing, in ms, the time a pointer has to
111
+ * cross from the trigger to the tooltip. Defaults to 200.
112
+ */
113
+ readonly hideDelayMs?: number;
114
+ /**
115
+ * Whether another tooltip of the group is open or just closed, so a hover
116
+ * opens this one at once ({@link TooltipGroup.isWarm}). Defaults to false.
117
+ */
118
+ readonly isWarm?: boolean;
119
+ };
120
+ /**
121
+ * The next state of a tooltip after `input` at `time` (ms), following the
122
+ * WAI-ARIA tooltip pattern and WCAG 2.2 success criterion 1.4.13 (content on
123
+ * hover or focus):
124
+ *
125
+ * - A hover opens it after `showDelayMs`, at once when the group is warm; a
126
+ * visible focus opens it at once;
127
+ * - It stays open while the trigger or the tooltip itself is hovered or the
128
+ * trigger focused (hoverable, persistent), the end of a hover closing it
129
+ * after `hideDelayMs`, the loss of focus at once;
130
+ * - Escape (dismissible) and a press of the trigger close it at once, and it
131
+ * stays closed until hover and focus have both ended.
132
+ *
133
+ * Returns `state` itself when nothing changes. The caller runs a timer to the
134
+ * returned `deadline` and passes a `time` input then.
135
+ *
136
+ * Time complexity: O(1). Memory: O(1).
137
+ *
138
+ * @example
139
+ * let state = tooltipStep(
140
+ * TOOLTIP_CLOSED,
141
+ * { kind: "hover", part: "trigger", isHovered: true },
142
+ * 0,
143
+ * ); // { isOpen: false, deadline: 500, … }
144
+ * state = tooltipStep(state, { kind: "time" }, 500); // { isOpen: true, … }
145
+ *
146
+ * @throws {RangeError} When `time` is not finite, or a delay is negative or not
147
+ * finite.
148
+ */
149
+ export declare function tooltipStep(state: TooltipState, input: TooltipInput, time: number, timing?: TooltipTiming): TooltipState;
150
+ /** Options of {@link TooltipGroup}. */
151
+ export type TooltipGroupOptions = {
152
+ /**
153
+ * How long after a tooltip of the group closes the next one still opens at
154
+ * once on hover, in ms, so a pointer running along a toolbar reads each one
155
+ * without waiting again. Defaults to 300.
156
+ */
157
+ readonly skipDelayMs?: number;
158
+ };
159
+ /**
160
+ * The tooltips that show one at a time: opening one closes the one open before,
161
+ * and while one is open or just closed, the next opens without its show delay.
162
+ * Each tooltip is known by its close callback.
163
+ *
164
+ * @example
165
+ * const group = new TooltipGroup();
166
+ * group.opened(closeFirst);
167
+ * group.opened(closeSecond); // calls closeFirst
168
+ * group.isWarm(now); // true
169
+ */
170
+ export declare class TooltipGroup {
171
+ private readonly skipDelayMs_;
172
+ private open_;
173
+ private closedAt_;
174
+ /** @throws {RangeError} When `skipDelayMs` is negative or not finite. */
175
+ constructor(options?: TooltipGroupOptions);
176
+ /** Whether a tooltip is open, or one closed less than the skip delay ago. */
177
+ isWarm(time: number): boolean;
178
+ /** A tooltip opened: the one open before is closed through its callback. */
179
+ opened(close: CallableNoArgs): void;
180
+ /** A tooltip closed at `time`; ignored unless it is the open one. */
181
+ closed(close: CallableNoArgs, time: number): void;
182
+ }
183
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;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B;IAC1C,OAAO,CAAC,SAAS,CAA4B;IAE7C,yEAAyE;IACzE,YAAY,OAAO,GAAE,mBAAwB,EAI5C;IAED,6EAA6E;IAC7E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI5B;IAED,4EAA4E;IAC5E,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAMlC;IAED,qEAAqE;IACrE,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMhD;CACD"}
@@ -0,0 +1,185 @@
1
+ import { assertFinite, assertNonNegative, } from "@ac-kit/core";
2
+ /**
3
+ * The attributes of a tooltip (WAI-ARIA tooltip pattern): the `tooltip` role,
4
+ * and where the stylesheet places it against its trigger.
5
+ *
6
+ * Time complexity: O(1). Memory: O(1).
7
+ *
8
+ * @example
9
+ * tooltipAttributes(); // { role: "tooltip", "data-side": "block-start", "data-align": "center" }
10
+ */
11
+ export function tooltipAttributes(input = {}) {
12
+ const { side = "block-start", align = "center" } = input;
13
+ return { role: "tooltip", "data-side": side, "data-align": align };
14
+ }
15
+ /**
16
+ * The attribute linking a trigger to its tooltip, so assistive technology reads
17
+ * the tooltip whether it is shown or not: `aria-describedby`, or
18
+ * `aria-labelledby` when the tooltip names the trigger (it then wins over an
19
+ * `aria-label`).
20
+ *
21
+ * Time complexity: O(1). Memory: O(1).
22
+ *
23
+ * @example
24
+ * tooltipTriggerAttributes({ tooltipId: "t", relation: "label" });
25
+ * // { "aria-labelledby": "t" }
26
+ */
27
+ export function tooltipTriggerAttributes(input) {
28
+ return input.relation === "label"
29
+ ? { "aria-labelledby": input.tooltipId }
30
+ : { "aria-describedby": input.tooltipId };
31
+ }
32
+ /** A tooltip closed, nothing hovered nor focused: where every one starts. */
33
+ export const TOOLTIP_CLOSED = Object.freeze({
34
+ isOpen: false,
35
+ deadline: undefined,
36
+ isTriggerHovered: false,
37
+ isTooltipHovered: false,
38
+ isFocused: false,
39
+ isSuppressed: false,
40
+ });
41
+ /**
42
+ * The next state of a tooltip after `input` at `time` (ms), following the
43
+ * WAI-ARIA tooltip pattern and WCAG 2.2 success criterion 1.4.13 (content on
44
+ * hover or focus):
45
+ *
46
+ * - A hover opens it after `showDelayMs`, at once when the group is warm; a
47
+ * visible focus opens it at once;
48
+ * - It stays open while the trigger or the tooltip itself is hovered or the
49
+ * trigger focused (hoverable, persistent), the end of a hover closing it
50
+ * after `hideDelayMs`, the loss of focus at once;
51
+ * - Escape (dismissible) and a press of the trigger close it at once, and it
52
+ * stays closed until hover and focus have both ended.
53
+ *
54
+ * Returns `state` itself when nothing changes. The caller runs a timer to the
55
+ * returned `deadline` and passes a `time` input then.
56
+ *
57
+ * Time complexity: O(1). Memory: O(1).
58
+ *
59
+ * @example
60
+ * let state = tooltipStep(
61
+ * TOOLTIP_CLOSED,
62
+ * { kind: "hover", part: "trigger", isHovered: true },
63
+ * 0,
64
+ * ); // { isOpen: false, deadline: 500, … }
65
+ * state = tooltipStep(state, { kind: "time" }, 500); // { isOpen: true, … }
66
+ *
67
+ * @throws {RangeError} When `time` is not finite, or a delay is negative or not
68
+ * finite.
69
+ */
70
+ export function tooltipStep(state, input, time, timing = {}) {
71
+ const { showDelayMs = 500, hideDelayMs = 200, isWarm = false } = timing;
72
+ assertFinite(time, "time");
73
+ assertNonNegative(showDelayMs, "showDelayMs");
74
+ assertNonNegative(hideDelayMs, "hideDelayMs");
75
+ if (input.kind === "time") {
76
+ if (state.deadline === undefined || time < state.deadline) {
77
+ return state;
78
+ }
79
+ // A closed tooltip is hovered no more, whatever events its hiding lost.
80
+ return {
81
+ ...state,
82
+ isOpen: !state.isOpen,
83
+ deadline: undefined,
84
+ isTooltipHovered: false,
85
+ };
86
+ }
87
+ let { isOpen, deadline, isTriggerHovered, isTooltipHovered, isFocused, isSuppressed, } = state;
88
+ switch (input.kind) {
89
+ case "hover":
90
+ if (input.part === "trigger") {
91
+ isTriggerHovered = input.isHovered;
92
+ }
93
+ else {
94
+ isTooltipHovered = input.isHovered && isOpen;
95
+ }
96
+ break;
97
+ case "focus":
98
+ isFocused = input.isFocused;
99
+ break;
100
+ case "press":
101
+ case "dismiss":
102
+ isSuppressed = true;
103
+ break;
104
+ }
105
+ const isHovered = isTriggerHovered || isTooltipHovered;
106
+ if (!isHovered && !isFocused) {
107
+ isSuppressed = false;
108
+ }
109
+ const isWanted = (isHovered || isFocused) && !isSuppressed;
110
+ if (isWanted) {
111
+ if (isOpen) {
112
+ deadline = undefined;
113
+ }
114
+ else if ((input.kind === "focus" && isFocused) ||
115
+ isWarm ||
116
+ showDelayMs === 0) {
117
+ isOpen = true;
118
+ deadline = undefined;
119
+ }
120
+ else {
121
+ deadline ??= time + showDelayMs;
122
+ }
123
+ }
124
+ else if (!isOpen) {
125
+ deadline = undefined;
126
+ }
127
+ else if (input.kind === "hover" && hideDelayMs > 0) {
128
+ deadline ??= time + hideDelayMs;
129
+ }
130
+ else {
131
+ isOpen = false;
132
+ deadline = undefined;
133
+ }
134
+ return {
135
+ isOpen,
136
+ deadline,
137
+ isTriggerHovered,
138
+ isTooltipHovered: isOpen && isTooltipHovered,
139
+ isFocused,
140
+ isSuppressed,
141
+ };
142
+ }
143
+ /**
144
+ * The tooltips that show one at a time: opening one closes the one open before,
145
+ * and while one is open or just closed, the next opens without its show delay.
146
+ * Each tooltip is known by its close callback.
147
+ *
148
+ * @example
149
+ * const group = new TooltipGroup();
150
+ * group.opened(closeFirst);
151
+ * group.opened(closeSecond); // calls closeFirst
152
+ * group.isWarm(now); // true
153
+ */
154
+ export class TooltipGroup {
155
+ skipDelayMs_;
156
+ open_;
157
+ closedAt_ = Number.NEGATIVE_INFINITY;
158
+ /** @throws {RangeError} When `skipDelayMs` is negative or not finite. */
159
+ constructor(options = {}) {
160
+ const { skipDelayMs = 300 } = options;
161
+ assertNonNegative(skipDelayMs, "skipDelayMs");
162
+ this.skipDelayMs_ = skipDelayMs;
163
+ }
164
+ /** Whether a tooltip is open, or one closed less than the skip delay ago. */
165
+ isWarm(time) {
166
+ return (this.open_ !== undefined || time - this.closedAt_ < this.skipDelayMs_);
167
+ }
168
+ /** A tooltip opened: the one open before is closed through its callback. */
169
+ opened(close) {
170
+ const previous = this.open_;
171
+ this.open_ = close;
172
+ if (previous !== undefined && previous !== close) {
173
+ previous();
174
+ }
175
+ }
176
+ /** A tooltip closed at `time`; ignored unless it is the open one. */
177
+ closed(close, time) {
178
+ if (this.open_ !== close) {
179
+ return;
180
+ }
181
+ this.open_ = undefined;
182
+ this.closedAt_ = time;
183
+ }
184
+ }
185
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,iBAAiB,GAEjB,MAAM,cAAc,CAAC;AAmBtB;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAAK,GAA2B,EAAE;IAElC,MAAM,EAAE,IAAI,GAAG,aAAa,EAAE,KAAK,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEzD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC;AAyBD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAoC;IAEpC,OAAO,KAAK,CAAC,QAAQ,KAAK,OAAO;QAChC,CAAC,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,SAAS,EAAE;QACxC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;AAC5C,CAAC;AAsBD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,cAAc,GAAiB,MAAM,CAAC,MAAM,CAAC;IACzD,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,SAAS;IACnB,gBAAgB,EAAE,KAAK;IACvB,gBAAgB,EAAE,KAAK;IACvB,S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