-
Notifications
You must be signed in to change notification settings - Fork 396
/
aria.ts
93 lines (85 loc) · 2.66 KB
/
aria.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { create, forEach, StringReplace, StringToLowerCase } from './language';
/**
* According to the following list, there are 48 aria attributes of which two (ariaDropEffect and
* ariaGrabbed) are deprecated:
* https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes
*
* The above list of 46 aria attributes is consistent with the following resources:
* https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
* https://wicg.github.io/aom/spec/aria-reflection.html
*/
const AriaPropertyNames = [
'ariaActiveDescendant',
'ariaAtomic',
'ariaAutoComplete',
'ariaBusy',
'ariaChecked',
'ariaColCount',
'ariaColIndex',
'ariaColSpan',
'ariaControls',
'ariaCurrent',
'ariaDescribedBy',
'ariaDetails',
'ariaDisabled',
'ariaErrorMessage',
'ariaExpanded',
'ariaFlowTo',
'ariaHasPopup',
'ariaHidden',
'ariaInvalid',
'ariaKeyShortcuts',
'ariaLabel',
'ariaLabelledBy',
'ariaLevel',
'ariaLive',
'ariaModal',
'ariaMultiLine',
'ariaMultiSelectable',
'ariaOrientation',
'ariaOwns',
'ariaPlaceholder',
'ariaPosInSet',
'ariaPressed',
'ariaReadOnly',
'ariaRelevant',
'ariaRequired',
'ariaRoleDescription',
'ariaRowCount',
'ariaRowIndex',
'ariaRowSpan',
'ariaSelected',
'ariaSetSize',
'ariaSort',
'ariaValueMax',
'ariaValueMin',
'ariaValueNow',
'ariaValueText',
'role',
] as const;
export type AccessibleElementProperties = {
[prop in typeof AriaPropertyNames[number]]: string | null;
};
const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/ (() => {
const AriaAttrNameToPropNameMap: Record<string, string> = create(null);
const AriaPropNameToAttrNameMap: Record<string, string> = create(null);
// Synthetic creation of all AOM property descriptors for Custom Elements
forEach.call(AriaPropertyNames, (propName) => {
const attrName = StringToLowerCase.call(
StringReplace.call(propName, /^aria/, () => 'aria-')
);
AriaAttrNameToPropNameMap[attrName] = propName;
AriaPropNameToAttrNameMap[propName] = attrName;
});
return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };
})();
export function isAriaAttribute(attrName: string): boolean {
return attrName in AriaAttrNameToPropNameMap;
}
export { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };