@ac-kit/ui-common 0.1.0 → 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.
- package/CHANGELOG.md +155 -0
- package/README.md +327 -9
- package/dist/anchored/anchored.d.ts +19 -0
- package/dist/anchored/anchored.d.ts.map +1 -0
- package/dist/anchored/anchored.js +2 -0
- package/dist/anchored/anchored.js.map +1 -0
- package/dist/focus/typeahead.d.ts +112 -0
- package/dist/focus/typeahead.d.ts.map +1 -0
- package/dist/focus/typeahead.js +178 -0
- package/dist/focus/typeahead.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/menu/menu.d.ts +157 -0
- package/dist/menu/menu.d.ts.map +1 -0
- package/dist/menu/menu.js +162 -0
- package/dist/menu/menu.js.map +1 -0
- package/dist/preact/_anchor.d.ts +13 -0
- package/dist/preact/_anchor.d.ts.map +1 -0
- package/dist/preact/_anchor.js +39 -0
- package/dist/preact/_anchor.js.map +1 -0
- package/dist/preact/_dom.d.ts +14 -0
- package/dist/preact/_dom.d.ts.map +1 -0
- package/dist/preact/_dom.js +31 -0
- package/dist/preact/_dom.js.map +1 -0
- package/dist/preact/_live-announcer.d.ts +26 -0
- package/dist/preact/_live-announcer.d.ts.map +1 -0
- package/dist/preact/_live-announcer.js +101 -0
- package/dist/preact/_live-announcer.js.map +1 -0
- package/dist/preact/index.d.ts +7 -0
- package/dist/preact/index.d.ts.map +1 -1
- package/dist/preact/index.js +7 -0
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/knob.d.ts.map +1 -1
- package/dist/preact/knob.js +5 -13
- package/dist/preact/knob.js.map +1 -1
- package/dist/preact/menu-button.d.ts +117 -0
- package/dist/preact/menu-button.d.ts.map +1 -0
- package/dist/preact/menu-button.js +330 -0
- package/dist/preact/menu-button.js.map +1 -0
- package/dist/preact/progress-ring.d.ts +42 -0
- package/dist/preact/progress-ring.d.ts.map +1 -0
- package/dist/preact/progress-ring.js +26 -0
- package/dist/preact/progress-ring.js.map +1 -0
- package/dist/preact/slider.d.ts.map +1 -1
- package/dist/preact/slider.js +6 -4
- package/dist/preact/slider.js.map +1 -1
- package/dist/preact/spin-button.d.ts +67 -0
- package/dist/preact/spin-button.d.ts.map +1 -0
- package/dist/preact/spin-button.js +132 -0
- package/dist/preact/spin-button.js.map +1 -0
- package/dist/preact/tabs.d.ts +97 -0
- package/dist/preact/tabs.d.ts.map +1 -0
- package/dist/preact/tabs.js +264 -0
- package/dist/preact/tabs.js.map +1 -0
- package/dist/preact/toaster.d.ts +43 -0
- package/dist/preact/toaster.d.ts.map +1 -0
- package/dist/preact/toaster.js +356 -0
- package/dist/preact/toaster.js.map +1 -0
- package/dist/preact/toolbar.d.ts.map +1 -1
- package/dist/preact/toolbar.js +2 -8
- package/dist/preact/toolbar.js.map +1 -1
- package/dist/preact/tooltip.d.ts +67 -0
- package/dist/preact/tooltip.d.ts.map +1 -0
- package/dist/preact/tooltip.js +165 -0
- package/dist/preact/tooltip.js.map +1 -0
- package/dist/preact/tree.d.ts +93 -0
- package/dist/preact/tree.d.ts.map +1 -0
- package/dist/preact/tree.js +399 -0
- package/dist/preact/tree.js.map +1 -0
- package/dist/progress/progress.d.ts +51 -0
- package/dist/progress/progress.d.ts.map +1 -0
- package/dist/progress/progress.js +43 -0
- package/dist/progress/progress.js.map +1 -0
- package/dist/spin-button/spin-button.d.ts +110 -0
- package/dist/spin-button/spin-button.d.ts.map +1 -0
- package/dist/spin-button/spin-button.js +179 -0
- package/dist/spin-button/spin-button.js.map +1 -0
- package/dist/tabs/tabs.d.ts +157 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +120 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/toast/toast-queue.d.ts +212 -0
- package/dist/toast/toast-queue.d.ts.map +1 -0
- package/dist/toast/toast-queue.js +290 -0
- package/dist/toast/toast-queue.js.map +1 -0
- package/dist/toast/toasts-obscure.d.ts +25 -0
- package/dist/toast/toasts-obscure.d.ts.map +1 -0
- package/dist/toast/toasts-obscure.js +30 -0
- package/dist/toast/toasts-obscure.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts +183 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -0
- package/dist/tooltip/tooltip.js +185 -0
- package/dist/tooltip/tooltip.js.map +1 -0
- package/dist/tree/tree.d.ts +302 -0
- package/dist/tree/tree.d.ts.map +1 -0
- package/dist/tree/tree.js +439 -0
- package/dist/tree/tree.js.map +1 -0
- package/package.json +22 -12
- package/styles.css +894 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { box2Area, box2Create, box2FromXywh, box2Intersection, } from "@ac-kit/math-geometry";
|
|
2
|
+
// Scratch boxes: the call allocates nothing.
|
|
3
|
+
const TARGET_ = box2Create();
|
|
4
|
+
const COVER_ = box2Create();
|
|
5
|
+
const COMMON_ = box2Create();
|
|
6
|
+
/**
|
|
7
|
+
* Whether any of the `toasts` covers part of `target`, the focused control: the
|
|
8
|
+
* toaster then fades its toasts, so a focused control is never hidden by them
|
|
9
|
+
* (WCAG 2.2 success criterion 2.4.11, focus not obscured). Edges that only
|
|
10
|
+
* touch do not cover; an empty box covers nothing.
|
|
11
|
+
*
|
|
12
|
+
* Time complexity: O(n) for n toasts. Memory: O(1).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* toastsObscure({ x: 0, y: 0, width: 10, height: 10 }, [
|
|
16
|
+
* { x: 5, y: 5, width: 10, height: 10 },
|
|
17
|
+
* ]); // true
|
|
18
|
+
*/
|
|
19
|
+
export function toastsObscure(target, toasts) {
|
|
20
|
+
box2FromXywh(TARGET_, target.x, target.y, target.width, target.height);
|
|
21
|
+
for (const toast of toasts) {
|
|
22
|
+
box2FromXywh(COVER_, toast.x, toast.y, toast.width, toast.height);
|
|
23
|
+
box2Intersection(COMMON_, TARGET_, COVER_);
|
|
24
|
+
if (box2Area(COMMON_) > 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=toasts-obscure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toasts-obscure.js","sourceRoot":"","sources":["../../src/toast/toasts-obscure.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAa/B,6CAA6C;AAC7C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;AAC7B,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;AAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC5B,MAAkB,EAClB,MAA4B;IAE5B,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACvE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAClE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,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;AAEtB,OAAO,KAAK,EACX,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,MAAM,yBAAyB,CAAC;AAEjC,wEAAwE;AACxE,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEzE,0CAA0C;AAC1C,MAAM,MAAM,sBAAsB,GAAG;IACpC,oDAAoD;IACpD,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,GAAE,sBAA2B,GAChC,iBAAiB,CAInB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,OAAO,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GACjC;IAAE,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,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G;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,aAAkB,GACxB,YAAY,CAgFd;AAED,uCAAuC;AACvC,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,KAAK,CAA6B;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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