@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,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,IAAI,CAAC,eAAe,CAAC;IACxC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,qBAA0B,GACjC,MAAM,GAAG,SAAS,CA4CpB;AAsBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAiBvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,QAAQ,EACf,aAAa,EAAE,OAAO,GACpB,MAAM,GAAG,SAAS,CAMpB"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { assertNonNegative, describeValue, isIntegerInRange, } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The query a person types into a list to reach an item by its name (the
|
|
4
|
+
* WAI-ARIA typeahead of menus, listboxes and trees): the characters typed
|
|
5
|
+
* within `timeoutMs` of each other. Every time is passed in, in ms.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const typeahead = new Typeahead();
|
|
9
|
+
* typeahead.type("c", 0); // "c"
|
|
10
|
+
* typeahead.type("h", 200); // "ch"
|
|
11
|
+
* typeahead.type("a", 900); // "a": the query timed out
|
|
12
|
+
*/
|
|
13
|
+
export class Typeahead {
|
|
14
|
+
timeoutMs_;
|
|
15
|
+
query_ = "";
|
|
16
|
+
lastTime_ = Number.NEGATIVE_INFINITY;
|
|
17
|
+
/** @throws {RangeError} When `timeoutMs` is negative or not finite. */
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
const { timeoutMs = 500 } = options;
|
|
20
|
+
assertNonNegative(timeoutMs, "timeoutMs");
|
|
21
|
+
this.timeoutMs_ = timeoutMs;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether a query is in progress at `time`: a character was typed less than
|
|
25
|
+
* `timeoutMs` before. A list lets Space extend the query then, rather than
|
|
26
|
+
* activate an item.
|
|
27
|
+
*/
|
|
28
|
+
isActive(time) {
|
|
29
|
+
return this.query_ !== "" && time - this.lastTime_ < this.timeoutMs_;
|
|
30
|
+
}
|
|
31
|
+
/** Adds `character`, typed at `time`, and returns the query to look up. */
|
|
32
|
+
type(character, time) {
|
|
33
|
+
this.query_ = this.isActive(time) ? this.query_ + character : character;
|
|
34
|
+
this.lastTime_ = time;
|
|
35
|
+
return this.query_;
|
|
36
|
+
}
|
|
37
|
+
/** Forgets the query: the list closed, or an item was chosen. */
|
|
38
|
+
reset() {
|
|
39
|
+
this.query_ = "";
|
|
40
|
+
this.lastTime_ = Number.NEGATIVE_INFINITY;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adds `character`, typed at `time`, and returns the item the query reaches
|
|
44
|
+
* among `labels` from `current` ({@link typeaheadIndex}): what a list does
|
|
45
|
+
* with each character typed.
|
|
46
|
+
*
|
|
47
|
+
* Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
|
|
48
|
+
* O(q).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const typeahead = new Typeahead();
|
|
52
|
+
* typeahead.find("b", 0, ["Apple", "Banana", "Blueberry"], 0); // 1
|
|
53
|
+
* typeahead.find("l", 100, ["Apple", "Banana", "Blueberry"], 1); // 2
|
|
54
|
+
*
|
|
55
|
+
* @throws {RangeError} When `current` is not an index of `labels`.
|
|
56
|
+
*/
|
|
57
|
+
find(character, time, labels, current, options) {
|
|
58
|
+
return typeaheadIndex(labels, current, this.type(character, time), options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The item a typeahead query moves to among `labels`, per the WAI-ARIA
|
|
63
|
+
* practices: the next item after `current` whose name starts with a single
|
|
64
|
+
* character, going round, so typing it again cycles through those items (a
|
|
65
|
+
* repeated character, `"aaa"`, cycles likewise); for a longer query, the first
|
|
66
|
+
* from `current` on whose name starts with it, so the item stays while it
|
|
67
|
+
* matches. Without `current`, the search starts at the first item.
|
|
68
|
+
*
|
|
69
|
+
* Names are compared grapheme by grapheme, ignoring case and accents as the
|
|
70
|
+
* locale's collation does (`sensitivity: "base"`) and leading white space.
|
|
71
|
+
* `undefined` for an empty query or when no enabled item matches.
|
|
72
|
+
*
|
|
73
|
+
* Time complexity: O(n · q), n labels and q graphemes in the query. Memory:
|
|
74
|
+
* O(q).
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "a"); // 1
|
|
78
|
+
* typeaheadIndex(["Apple", "Apricot", "Banana"], 0, "apr"); // 1
|
|
79
|
+
* typeaheadIndex(["Éclair", "Fig"], 1, "e"); // 0
|
|
80
|
+
*
|
|
81
|
+
* @throws {RangeError} When `current` is not an index of `labels`.
|
|
82
|
+
*/
|
|
83
|
+
export function typeaheadIndex(labels, current, query, options = {}) {
|
|
84
|
+
const count = labels.length;
|
|
85
|
+
if (current !== undefined && !isIntegerInRange(current, 0, count)) {
|
|
86
|
+
throw new RangeError(`current must be an integer in [0, ${String(count)}), got ${describeValue(current)}`);
|
|
87
|
+
}
|
|
88
|
+
const { locales, isDisabled } = options;
|
|
89
|
+
const segmenter = new Intl.Segmenter(locales, { granularity: "grapheme" });
|
|
90
|
+
const graphemes = Array.from(segmenter.segment(query), (segment) => segment.segment);
|
|
91
|
+
const first = graphemes[0];
|
|
92
|
+
if (first === undefined) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const isRepeated = graphemes.every((grapheme) => grapheme === first);
|
|
96
|
+
const searched = isRepeated ? first : query;
|
|
97
|
+
const searchedLength = isRepeated ? 1 : graphemes.length;
|
|
98
|
+
const collator = new Intl.Collator(locales, {
|
|
99
|
+
usage: "search",
|
|
100
|
+
sensitivity: "base",
|
|
101
|
+
});
|
|
102
|
+
// A single character moves on from the current item; a longer query may
|
|
103
|
+
// keep it.
|
|
104
|
+
const start = current === undefined ? 0 : isRepeated ? current + 1 : current;
|
|
105
|
+
for (let visited = 0; visited < count; visited += 1) {
|
|
106
|
+
const index = (start + visited) % count;
|
|
107
|
+
if (isDisabled?.(index) === true) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const prefix = graphemePrefix_(segmenter, labels[index].trimStart(), searchedLength);
|
|
111
|
+
if (collator.compare(prefix, searched) === 0) {
|
|
112
|
+
return index;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
function graphemePrefix_(segmenter, text, length) {
|
|
118
|
+
let end = 0;
|
|
119
|
+
let taken = 0;
|
|
120
|
+
for (const { index, segment } of segmenter.segment(text)) {
|
|
121
|
+
if (taken === length) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
end = index + segment.length;
|
|
125
|
+
taken += 1;
|
|
126
|
+
}
|
|
127
|
+
return text.slice(0, end);
|
|
128
|
+
}
|
|
129
|
+
const CONTROL_ = /^\p{Cc}$/u;
|
|
130
|
+
/**
|
|
131
|
+
* Whether a key types a character a typeahead takes: one grapheme, not a
|
|
132
|
+
* control character, without Ctrl, Alt or Meta (the browser's and the system's
|
|
133
|
+
* shortcuts). Shift passes, for capitals; so does Space, which a list takes as
|
|
134
|
+
* part of a query in progress only (see {@link Typeahead.isActive}).
|
|
135
|
+
*
|
|
136
|
+
* Time complexity: O(1) for a key name of bounded length. Memory: O(1).
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* isTypeaheadKey({ key: "a" }); // true
|
|
140
|
+
* isTypeaheadKey({ key: "Enter" }); // false: a named key
|
|
141
|
+
* isTypeaheadKey({ key: "s", ctrlKey: true }); // false: a shortcut
|
|
142
|
+
*/
|
|
143
|
+
export function isTypeaheadKey(input) {
|
|
144
|
+
const { key, ctrlKey = false, altKey = false, metaKey = false } = input;
|
|
145
|
+
if (ctrlKey || altKey || metaKey || key === "" || CONTROL_.test(key)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const segments = new Intl.Segmenter(undefined, {
|
|
149
|
+
granularity: "grapheme",
|
|
150
|
+
}).segment(key);
|
|
151
|
+
let count = 0;
|
|
152
|
+
for (const _segment of segments) {
|
|
153
|
+
count += 1;
|
|
154
|
+
if (count > 1) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return count === 1;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The character a key adds to a list's typeahead query: a typed character
|
|
162
|
+
* ({@link isTypeaheadKey}), Space only while a query is in progress (otherwise
|
|
163
|
+
* Space selects or activates an item). `undefined` for any other key.
|
|
164
|
+
*
|
|
165
|
+
* Time complexity: O(1) for a key name of bounded length. Memory: O(1).
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* typeaheadCharacter({ key: "a" }, false); // "a"
|
|
169
|
+
* typeaheadCharacter({ key: " " }, false); // undefined: Space selects
|
|
170
|
+
* typeaheadCharacter({ key: " " }, true); // " ": "new y" goes on
|
|
171
|
+
*/
|
|
172
|
+
export function typeaheadCharacter(input, isTypingAhead) {
|
|
173
|
+
if (input.key === " " && !isTypingAhead) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
return isTypeaheadKey(input) ? input.key : undefined;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=typeahead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeahead.js","sourceRoot":"","sources":["../../src/focus/typeahead.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAEhB,MAAM,cAAc,CAAC;AAYtB;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACJ,UAAU,CAAS;IAC5B,MAAM,GAAG,EAAE,CAAC;IACZ,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAE7C,uEAAuE;IACvE,YAAY,OAAO,GAAqB,EAAE;QACzC,MAAM,EAAE,SAAS,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;QACpC,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,KAAK,EAAE,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;IACtE,CAAC;IAED,2EAA2E;IAC3E,IAAI,CAAC,SAAiB,EAAE,IAAY;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,iEAAiE;IACjE,KAAK;QACJ,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAI,CACH,SAAiB,EACj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AS,CAAC;AACtD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
export * from "./anchored/anchored.js";
|
|
1
2
|
export * from "./button/button.js";
|
|
2
3
|
export * from "./dialog/dialog.js";
|
|
3
4
|
export * from "./focus/owns-arrow-keys.js";
|
|
4
5
|
export * from "./focus/roving-focus.js";
|
|
6
|
+
export * from "./focus/typeahead.js";
|
|
5
7
|
export * from "./knob/knob.js";
|
|
8
|
+
export * from "./menu/menu.js";
|
|
6
9
|
export * from "./meter/meter.js";
|
|
10
|
+
export * from "./progress/progress.js";
|
|
7
11
|
export * from "./readout/readout.js";
|
|
8
12
|
export * from "./slider/slider-attributes.js";
|
|
9
13
|
export * from "./slider/slider-range.js";
|
|
10
14
|
export * from "./slider/slider-track.js";
|
|
11
15
|
export * from "./slider/stepped-value.js";
|
|
16
|
+
export * from "./spin-button/spin-button.js";
|
|
12
17
|
export * from "./switch/switch.js";
|
|
18
|
+
export * from "./tabs/tabs.js";
|
|
19
|
+
export * from "./toast/toast-queue.js";
|
|
20
|
+
export * from "./toast/toasts-obscure.js";
|
|
13
21
|
export * from "./toggle-button/toggle-button.js";
|
|
14
22
|
export * from "./tone.js";
|
|
15
23
|
export * from "./toolbar/toolbar.js";
|
|
24
|
+
export * from "./tooltip/tooltip.js";
|
|
25
|
+
export * from "./tree/tree.js";
|
|
16
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
export * from "./anchored/anchored.js";
|
|
1
2
|
export * from "./button/button.js";
|
|
2
3
|
export * from "./dialog/dialog.js";
|
|
3
4
|
export * from "./focus/owns-arrow-keys.js";
|
|
4
5
|
export * from "./focus/roving-focus.js";
|
|
6
|
+
export * from "./focus/typeahead.js";
|
|
5
7
|
export * from "./knob/knob.js";
|
|
8
|
+
export * from "./menu/menu.js";
|
|
6
9
|
export * from "./meter/meter.js";
|
|
10
|
+
export * from "./progress/progress.js";
|
|
7
11
|
export * from "./readout/readout.js";
|
|
8
12
|
export * from "./slider/slider-attributes.js";
|
|
9
13
|
export * from "./slider/slider-range.js";
|
|
10
14
|
export * from "./slider/slider-track.js";
|
|
11
15
|
export * from "./slider/stepped-value.js";
|
|
16
|
+
export * from "./spin-button/spin-button.js";
|
|
12
17
|
export * from "./switch/switch.js";
|
|
18
|
+
export * from "./tabs/tabs.js";
|
|
19
|
+
export * from "./toast/toast-queue.js";
|
|
20
|
+
export * from "./toast/toasts-obscure.js";
|
|
13
21
|
export * from "./toggle-button/toggle-button.js";
|
|
14
22
|
export * from "./tone.js";
|
|
15
23
|
export * from "./toolbar/toolbar.js";
|
|
24
|
+
export * from "./tooltip/tooltip.js";
|
|
25
|
+
export * from "./tree/tree.js";
|
|
16
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { KeyInput } from "@ac-kit/ui-gesture";
|
|
2
|
+
import type { AnchoredAlign, AnchoredAttributes, AnchoredSide } from "../anchored/anchored.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a menu item does: an action, a setting turned on or off, or one choice
|
|
5
|
+
* among the radio items of its group.
|
|
6
|
+
*/
|
|
7
|
+
export type MenuItemKind = "item" | "checkbox" | "radio";
|
|
8
|
+
/** The attributes of a menu button, keyed by their HTML attribute names. */
|
|
9
|
+
export type MenuButtonAttributes = {
|
|
10
|
+
"aria-haspopup": "menu";
|
|
11
|
+
"aria-expanded": "true" | "false";
|
|
12
|
+
"aria-controls": string;
|
|
13
|
+
};
|
|
14
|
+
/** Input of {@link menuButtonAttributes}. */
|
|
15
|
+
export type MenuButtonAttributesInput = {
|
|
16
|
+
/** The id of the menu it opens. */
|
|
17
|
+
menuId: string;
|
|
18
|
+
isOpen: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The attributes of the button that opens a menu (WAI-ARIA menu button
|
|
22
|
+
* pattern): it has a menu popup, says whether it is open, and which element the
|
|
23
|
+
* menu is.
|
|
24
|
+
*
|
|
25
|
+
* Time complexity: O(1). Memory: O(1).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* menuButtonAttributes({ menuId: "m", isOpen: false });
|
|
29
|
+
* // { "aria-haspopup": "menu", "aria-expanded": "false", "aria-controls": "m" }
|
|
30
|
+
*/
|
|
31
|
+
export declare function menuButtonAttributes(input: MenuButtonAttributesInput): MenuButtonAttributes;
|
|
32
|
+
/** The attributes of a menu, keyed by their HTML attribute names. */
|
|
33
|
+
export type MenuAttributes = AnchoredAttributes & {
|
|
34
|
+
role: "menu";
|
|
35
|
+
"aria-labelledby": string;
|
|
36
|
+
tabindex: -1;
|
|
37
|
+
};
|
|
38
|
+
/** Input of {@link menuAttributes}. */
|
|
39
|
+
export type MenuAttributesInput = {
|
|
40
|
+
/** The id of the element naming it: its menu button. */
|
|
41
|
+
labelledBy: string;
|
|
42
|
+
/** Defaults to `block-end`: below the button. */
|
|
43
|
+
side?: AnchoredSide;
|
|
44
|
+
/** Defaults to `start`: its start edge on the button's. */
|
|
45
|
+
align?: AnchoredAlign;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The attributes of a menu (WAI-ARIA menu pattern): named by its button,
|
|
49
|
+
* focusable itself only as a fallback (its items take focus), and placed
|
|
50
|
+
* against the button by the stylesheet.
|
|
51
|
+
*
|
|
52
|
+
* Time complexity: O(1). Memory: O(1).
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* menuAttributes({ labelledBy: "b" });
|
|
56
|
+
* // { role: "menu", "aria-labelledby": "b", tabindex: -1,
|
|
57
|
+
* // "data-side": "block-end", "data-align": "start" }
|
|
58
|
+
*/
|
|
59
|
+
export declare function menuAttributes(input: MenuAttributesInput): MenuAttributes;
|
|
60
|
+
/** The attributes of a menu item, keyed by their HTML attribute names. */
|
|
61
|
+
export type MenuItemAttributes = {
|
|
62
|
+
role: "menuitem" | "menuitemcheckbox" | "menuitemradio";
|
|
63
|
+
tabindex: -1;
|
|
64
|
+
"aria-checked"?: "true" | "false";
|
|
65
|
+
"aria-disabled"?: "true";
|
|
66
|
+
"data-kind": MenuItemKind;
|
|
67
|
+
};
|
|
68
|
+
/** Input of {@link menuItemAttributes}. */
|
|
69
|
+
export type MenuItemAttributesInput = {
|
|
70
|
+
kind: "item";
|
|
71
|
+
isDisabled?: boolean;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "checkbox" | "radio";
|
|
74
|
+
isChecked: boolean;
|
|
75
|
+
isDisabled?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The attributes of a menu item: its role by kind, its checked state for a
|
|
79
|
+
* checkbox or radio item, out of the tab order (the menu moves focus to it). A
|
|
80
|
+
* disabled item stays focusable, as the WAI-ARIA practices advise, so it can be
|
|
81
|
+
* found and read; it is not activated.
|
|
82
|
+
*
|
|
83
|
+
* Time complexity: O(1). Memory: O(1).
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* menuItemAttributes({ kind: "checkbox", isChecked: true });
|
|
87
|
+
* // { role: "menuitemcheckbox", tabindex: -1, "aria-checked": "true",
|
|
88
|
+
* // "data-kind": "checkbox" }
|
|
89
|
+
*/
|
|
90
|
+
export declare function menuItemAttributes(input: MenuItemAttributesInput): MenuItemAttributes;
|
|
91
|
+
/** Which item a menu focuses as it opens. */
|
|
92
|
+
export type MenuOpenFocus = "first" | "last";
|
|
93
|
+
/**
|
|
94
|
+
* The item a key on a menu button opens its menu on (WAI-ARIA menu button
|
|
95
|
+
* pattern): Enter, Space and Arrow Down the first, Arrow Up the last.
|
|
96
|
+
* `undefined` for another key, or with Ctrl, Alt or Meta held.
|
|
97
|
+
*
|
|
98
|
+
* Time complexity: O(1). Memory: O(1).
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* menuButtonKeyAction({ key: "ArrowUp" }); // "last"
|
|
102
|
+
*/
|
|
103
|
+
export declare function menuButtonKeyAction(input: KeyInput): MenuOpenFocus | undefined;
|
|
104
|
+
/** Input of {@link menuKeyAction}: the key and where focus is. */
|
|
105
|
+
export type MenuKeyInput = KeyInput & {
|
|
106
|
+
/** The focused item's index; `undefined` when the menu itself has focus. */
|
|
107
|
+
current: number | undefined;
|
|
108
|
+
/** How many items the menu has. */
|
|
109
|
+
count: number;
|
|
110
|
+
/** The focused item's kind; `undefined` when no item has focus. */
|
|
111
|
+
itemKind: MenuItemKind | undefined;
|
|
112
|
+
/** Whether a typeahead query is in progress, so Space extends it. */
|
|
113
|
+
isTypingAhead: boolean;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* What a key does in an open menu (WAI-ARIA menu pattern):
|
|
117
|
+
*
|
|
118
|
+
* - `focus` an item: Arrow Down and Up to the next and previous one, going round,
|
|
119
|
+
* Home and End to the first and last;
|
|
120
|
+
* - `activate` the focused item: Enter does and closes the menu; Space does on an
|
|
121
|
+
* action and closes, and checks a checkbox or radio item keeping the menu
|
|
122
|
+
* open;
|
|
123
|
+
* - `close` the menu and give focus back to its button: Escape;
|
|
124
|
+
* - `leave` it: Tab and Shift Tab close it and move on from its button;
|
|
125
|
+
* - `typeahead` a character, Space included while a query is in progress.
|
|
126
|
+
*/
|
|
127
|
+
export type MenuKeyAction = {
|
|
128
|
+
readonly kind: "focus";
|
|
129
|
+
readonly index: number;
|
|
130
|
+
} | {
|
|
131
|
+
readonly kind: "activate";
|
|
132
|
+
readonly keepsOpen: boolean;
|
|
133
|
+
} | {
|
|
134
|
+
readonly kind: "close";
|
|
135
|
+
} | {
|
|
136
|
+
readonly kind: "leave";
|
|
137
|
+
} | {
|
|
138
|
+
readonly kind: "typeahead";
|
|
139
|
+
readonly character: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* The action of a key in an open menu, {@link MenuKeyAction}. `undefined` for a
|
|
143
|
+
* key the menu does not use, or with Ctrl, Alt or Meta held (a shortcut).
|
|
144
|
+
* Disabled items take focus like the others, so the caller checks them before
|
|
145
|
+
* activating one.
|
|
146
|
+
*
|
|
147
|
+
* Time complexity: O(count) at worst. Memory: O(1).
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* menuKeyAction({ key: "ArrowDown", current: 2, count: 3, itemKind: "item",
|
|
151
|
+
* isTypingAhead: false }); // { kind: "focus", index: 0 }
|
|
152
|
+
*
|
|
153
|
+
* @throws {RangeError} When `count` is not a non-negative safe integer or
|
|
154
|
+
* `current` is outside [0, count).
|
|
155
|
+
*/
|
|
156
|
+
export declare function menuKeyAction(input: MenuKeyInput): MenuKeyAction | undefined;
|
|
157
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EACX,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,MAAM,yBAAyB,CAAC;AAIjC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAEzD,4EAA4E;AAC5E,MAAM,MAAM,oBAAoB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,yBAAyB,GAAG;IACvC,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,yBAAyB,GAC9B,oBAAoB,CAMtB;AAED,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG;IACjD,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