@markuplint/ml-spec 3.0.0-alpha.4 → 3.0.0-alpha.6
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/lib/dom-traverse/get-attr-specs.d.ts +1 -1
- package/lib/dom-traverse/get-computed-aria-props.d.ts +12 -0
- package/lib/dom-traverse/get-computed-aria-props.js +106 -0
- package/lib/dom-traverse/get-content-model.d.ts +4 -1
- package/lib/dom-traverse/get-implicit-role.d.ts +5 -1
- package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +10 -4
- package/lib/dom-traverse/get-permitted-roles.d.ts +7 -3
- package/lib/dom-traverse/get-spec.d.ts +4 -1
- package/lib/dom-traverse/has-required-owned-elements.d.ts +6 -1
- package/lib/dom-traverse/is-exposed.d.ts +11 -0
- package/lib/dom-traverse/is-exposed.js +181 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/specs/aria-specs.d.ts +7 -4
- package/lib/specs/content-model-category-to-tag-names.d.ts +4 -1
- package/lib/specs/get-aria.d.ts +7 -1
- package/lib/specs/get-attr-specs.d.ts +7 -3
- package/lib/specs/get-implicit-role.d.ts +7 -1
- package/lib/specs/get-permitted-roles.d.ts +9 -3
- package/lib/specs/get-role-spec.d.ts +10 -3
- package/lib/specs/get-selectors-by-content-model-category.d.ts +4 -1
- package/lib/specs/get-spec-by-tag-name.d.ts +5 -1
- package/lib/specs/is-palpable-elements.d.ts +9 -0
- package/lib/specs/is-palpable-elements.js +47 -0
- package/lib/specs/is-void-element.d.ts +1 -0
- package/lib/specs/is-void-element.js +25 -0
- package/lib/specs/schema-to-spec.d.ts +3 -3
- package/lib/types/aria.d.ts +129 -115
- package/lib/types/attributes.d.ts +1437 -112
- package/lib/types/index.d.ts +192 -164
- package/lib/types/permitted-structres.d.ts +76 -37
- package/lib/types/permitted-structures.d.ts +72 -33
- package/lib/utils/merge-array.d.ts +5 -3
- package/lib/utils/resolve-namespace.d.ts +5 -5
- package/package.json +5 -5
- package/schemas/content-models.schema.json +1 -2
- package/src/dom-traverse/accname-computation.spec.ts +1 -1
- package/src/dom-traverse/get-computed-aria-props.spec.ts +368 -0
- package/src/dom-traverse/get-computed-aria-props.ts +130 -0
- package/src/dom-traverse/is-exposed.spec.ts +50 -0
- package/src/dom-traverse/is-exposed.ts +196 -0
- package/src/index.ts +4 -0
- package/src/specs/is-palpable-elements.ts +55 -0
- package/src/specs/is-void-element.ts +22 -0
- package/src/types/permitted-structres.ts +1 -2
- package/src/types/permitted-structures.ts +1 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MLMLSpec } from '../types';
|
|
2
|
-
export declare function getAttrSpecs(el: Element, schema: MLMLSpec): import(
|
|
2
|
+
export declare function getAttrSpecs(el: Element, schema: MLMLSpec): import('../types').Attribute[] | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ARIAVersion, MLMLSpec } from '../types';
|
|
2
|
+
type ARIAProps = Record<string, ARIAProp>;
|
|
3
|
+
type ARIAProp = {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string | undefined;
|
|
6
|
+
required: boolean;
|
|
7
|
+
deprecated: boolean;
|
|
8
|
+
from: ARIAPropReferenceType;
|
|
9
|
+
};
|
|
10
|
+
type ARIAPropReferenceType = 'default' | 'html-attr' | 'aria-attr';
|
|
11
|
+
export declare function getComputedAriaProps(specs: Readonly<MLMLSpec>, el: Element, version: ARIAVersion): ARIAProps;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComputedAriaProps = void 0;
|
|
4
|
+
const aria_specs_1 = require("../specs/aria-specs");
|
|
5
|
+
const get_computed_role_1 = require("./get-computed-role");
|
|
6
|
+
function getComputedAriaProps(specs, el, version) {
|
|
7
|
+
const ariaSpecs = (0, aria_specs_1.ariaSpecs)(specs, version);
|
|
8
|
+
const { role } = (0, get_computed_role_1.getComputedRole)(specs, el, version);
|
|
9
|
+
if (!role) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
const props = {};
|
|
13
|
+
role.ownedProperties.forEach(ownedProp => {
|
|
14
|
+
var _a;
|
|
15
|
+
const spec = ariaSpecs.props.find(propSpec => propSpec.name === ownedProp.name);
|
|
16
|
+
if (!spec) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (el.hasAttribute(spec.name)) {
|
|
20
|
+
const attrValue = el.getAttribute(spec.name);
|
|
21
|
+
if (attrValue && isValidAriaValue(spec, role.name, attrValue, spec.enum)) {
|
|
22
|
+
props[ownedProp.name] = {
|
|
23
|
+
name: ownedProp.name,
|
|
24
|
+
value: attrValue,
|
|
25
|
+
deprecated: !!spec.deprecated,
|
|
26
|
+
required: !!ownedProp.required,
|
|
27
|
+
from: 'aria-attr',
|
|
28
|
+
};
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const equivalentHtmlAttr = (_a = spec.equivalentHtmlAttrs) === null || _a === void 0 ? void 0 : _a[0];
|
|
33
|
+
if (equivalentHtmlAttr && el.hasAttribute(equivalentHtmlAttr.htmlAttrName)) {
|
|
34
|
+
const value = equivalentHtmlAttr.value === null
|
|
35
|
+
? el.getAttribute(equivalentHtmlAttr.htmlAttrName)
|
|
36
|
+
: equivalentHtmlAttr.value;
|
|
37
|
+
if (value != null) {
|
|
38
|
+
props[ownedProp.name] = {
|
|
39
|
+
name: ownedProp.name,
|
|
40
|
+
value,
|
|
41
|
+
deprecated: !!spec.deprecated,
|
|
42
|
+
required: !!ownedProp.required,
|
|
43
|
+
from: 'html-attr',
|
|
44
|
+
};
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let defaultValue = spec.defaultValue;
|
|
49
|
+
/**
|
|
50
|
+
* @see https://www.w3.org/TR/html-aria/#el-h1-h6
|
|
51
|
+
*/
|
|
52
|
+
if (ownedProp.name === 'aria-level' && /^H[1-6]$/.test(el.nodeName)) {
|
|
53
|
+
defaultValue = el.nodeName.replace('H', '');
|
|
54
|
+
}
|
|
55
|
+
props[ownedProp.name] = {
|
|
56
|
+
name: ownedProp.name,
|
|
57
|
+
value: defaultValue,
|
|
58
|
+
deprecated: !!spec.deprecated,
|
|
59
|
+
required: !!ownedProp.required,
|
|
60
|
+
from: 'default',
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return props;
|
|
64
|
+
}
|
|
65
|
+
exports.getComputedAriaProps = getComputedAriaProps;
|
|
66
|
+
function isValidAriaValue(spec, role, value, enumList) {
|
|
67
|
+
let type = spec.value;
|
|
68
|
+
if (spec.conditionalValue) {
|
|
69
|
+
for (const cond of spec.conditionalValue) {
|
|
70
|
+
if (cond.role.includes(role)) {
|
|
71
|
+
type = cond.value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
value = (value !== null && value !== void 0 ? value : '').trim();
|
|
76
|
+
switch (type) {
|
|
77
|
+
case 'string': {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
case 'ID reference':
|
|
81
|
+
case 'ID reference list':
|
|
82
|
+
case 'URI': {
|
|
83
|
+
return !!value;
|
|
84
|
+
}
|
|
85
|
+
case 'integer':
|
|
86
|
+
case 'number': {
|
|
87
|
+
return !isNaN(parseFloat(value));
|
|
88
|
+
}
|
|
89
|
+
case 'token':
|
|
90
|
+
case 'token list': {
|
|
91
|
+
if (!enumList.length) {
|
|
92
|
+
throw new Error('Need an enum list in token and token list types');
|
|
93
|
+
}
|
|
94
|
+
return enumList.includes(value.toLowerCase());
|
|
95
|
+
}
|
|
96
|
+
case 'tristate': {
|
|
97
|
+
return ['true', 'false', 'mixed'].includes(value.toLowerCase());
|
|
98
|
+
}
|
|
99
|
+
case 'true/false': {
|
|
100
|
+
return ['true', 'false'].includes(value.toLowerCase());
|
|
101
|
+
}
|
|
102
|
+
case 'true/false/undefined': {
|
|
103
|
+
return ['true', 'false', 'undefined'].includes(value.toLowerCase());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { ElementSpec } from '../types';
|
|
2
2
|
import type { PermittedContentPattern } from '../types/permitted-structures';
|
|
3
|
-
export declare function getContentModel(
|
|
3
|
+
export declare function getContentModel(
|
|
4
|
+
el: Element,
|
|
5
|
+
specs: Pick<ElementSpec, 'name' | 'contentModel'>[],
|
|
6
|
+
): boolean | PermittedContentPattern[] | null;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
|
|
2
2
|
export declare function getImplicitRole(specs: Readonly<MLMLSpec>, el: Element, version: ARIAVersion): ComputedRole;
|
|
3
|
-
export declare function getImplicitRoleName(
|
|
3
|
+
export declare function getImplicitRoleName(
|
|
4
|
+
el: Element,
|
|
5
|
+
version: ARIAVersion,
|
|
6
|
+
specs: Readonly<MLMLSpec>,
|
|
7
|
+
): import('..').ImplicitRole;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ARIAVersion, MLMLSpec } from '../types';
|
|
2
|
-
export declare function getNonPresentationalAncestor(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare function getNonPresentationalAncestor(
|
|
3
|
+
el: Element,
|
|
4
|
+
specs: MLMLSpec,
|
|
5
|
+
version: ARIAVersion,
|
|
6
|
+
):
|
|
7
|
+
| import('../types').ComputedRole
|
|
8
|
+
| {
|
|
9
|
+
el: null;
|
|
10
|
+
role: null;
|
|
11
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { ARIAVersion, MLMLSpec } from '../types';
|
|
2
|
-
export declare function getPermittedRoles(
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare function getPermittedRoles(
|
|
3
|
+
el: Element,
|
|
4
|
+
version: ARIAVersion,
|
|
5
|
+
specs: Readonly<MLMLSpec>,
|
|
6
|
+
): {
|
|
7
|
+
name: string;
|
|
8
|
+
deprecated?: boolean | undefined;
|
|
5
9
|
}[];
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ElementSpec } from '../types';
|
|
2
|
-
export declare function getSpec<K extends keyof ElementSpec>(
|
|
2
|
+
export declare function getSpec<K extends keyof ElementSpec>(
|
|
3
|
+
el: Element,
|
|
4
|
+
specs: Pick<ElementSpec, 'name' | K>[],
|
|
5
|
+
): Pick<ElementSpec, 'name' | K> | null;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
|
|
2
2
|
export declare function hasRequiredOwnedElement(el: Element, specs: Readonly<MLMLSpec>, version: ARIAVersion): boolean;
|
|
3
|
-
export declare function isRequiredOwnedElement(
|
|
3
|
+
export declare function isRequiredOwnedElement(
|
|
4
|
+
owned: ComputedRole,
|
|
5
|
+
query: string,
|
|
6
|
+
specs: MLMLSpec,
|
|
7
|
+
version: ARIAVersion,
|
|
8
|
+
): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ARIAVersion, MLMLSpec } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Detect including/excluding from the Accessibility Tree
|
|
4
|
+
*
|
|
5
|
+
* @see https://www.w3.org/TR/wai-aria-1.2/#accessibility_tree
|
|
6
|
+
*
|
|
7
|
+
* @param specs
|
|
8
|
+
* @param el
|
|
9
|
+
* @param version
|
|
10
|
+
*/
|
|
11
|
+
export declare function isExposed(el: Element, specs: Readonly<MLMLSpec>, version: ARIAVersion): boolean;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isExposed = void 0;
|
|
4
|
+
const aria_specs_1 = require("../specs/aria-specs");
|
|
5
|
+
const is_palpable_elements_1 = require("../specs/is-palpable-elements");
|
|
6
|
+
const is_presentational_1 = require("../specs/is-presentational");
|
|
7
|
+
const get_computed_role_1 = require("./get-computed-role");
|
|
8
|
+
/**
|
|
9
|
+
* Detect including/excluding from the Accessibility Tree
|
|
10
|
+
*
|
|
11
|
+
* @see https://www.w3.org/TR/wai-aria-1.2/#accessibility_tree
|
|
12
|
+
*
|
|
13
|
+
* @param specs
|
|
14
|
+
* @param el
|
|
15
|
+
* @param version
|
|
16
|
+
*/
|
|
17
|
+
function isExposed(el, specs, version) {
|
|
18
|
+
// According to WAI-ARIA
|
|
19
|
+
if (isExcluding(el, specs, version)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// According to HTML and SVG Specs with **the author's interpretation**
|
|
23
|
+
{
|
|
24
|
+
if (!(0, is_palpable_elements_1.isPalpableElement)(el, specs, { extendsSvg: true, extendsExposableElements: true })) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// According to WAI-ARIA
|
|
29
|
+
{
|
|
30
|
+
const exposable = isIncluding(el, specs, version);
|
|
31
|
+
if (exposable) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Default
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
exports.isExposed = isExposed;
|
|
39
|
+
/**
|
|
40
|
+
* Excluding Elements from the Accessibility Tree
|
|
41
|
+
*
|
|
42
|
+
* @see https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
|
|
43
|
+
*
|
|
44
|
+
* @param specs
|
|
45
|
+
* @param el
|
|
46
|
+
* @param version
|
|
47
|
+
*/
|
|
48
|
+
function isExcluding(el, specs, version) {
|
|
49
|
+
/**
|
|
50
|
+
* The following elements are not exposed via the accessibility API and
|
|
51
|
+
* user agents MUST NOT include them in the accessibility tree:
|
|
52
|
+
* - Elements, including their descendent elements,
|
|
53
|
+
* that have host language semantics specifying
|
|
54
|
+
* that the element is not displayed, such as CSS display:none,
|
|
55
|
+
* visibility:hidden, or the HTML hidden attribute.
|
|
56
|
+
*/
|
|
57
|
+
{
|
|
58
|
+
let currentEl = el;
|
|
59
|
+
while (currentEl) {
|
|
60
|
+
if (hasDisplayNodeOrVisibilityHidden(currentEl) || currentEl.hasAttribute('hidden')) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
currentEl = currentEl.parentElement;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* - Elements with none or presentation as the first role in the role attribute.
|
|
68
|
+
* However, their exclusion is conditional. In addition,
|
|
69
|
+
* the element's descendants and text content are generally included.
|
|
70
|
+
* These exceptions and conditions are documented in the presentation (role)
|
|
71
|
+
* section.
|
|
72
|
+
*/
|
|
73
|
+
if ((0, is_presentational_1.isPresentational)((el.getAttribute('role') || '').split(/\s+/)[0])) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* If not already excluded from the accessibility tree per the above rules,
|
|
78
|
+
* user agents SHOULD NOT include the following elements
|
|
79
|
+
* in the accessibility tree:
|
|
80
|
+
* - Elements, including their descendants, that have aria-hidden set to true.
|
|
81
|
+
* In other words, aria-hidden="true" on a parent overrides aria-hidden="false"
|
|
82
|
+
* on descendants.
|
|
83
|
+
*/
|
|
84
|
+
{
|
|
85
|
+
let currentEl = el;
|
|
86
|
+
while (currentEl) {
|
|
87
|
+
if (currentEl.getAttribute('aria-hidden') === 'true') {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
currentEl = currentEl.parentElement;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* - Any descendants of elements that have the characteristic
|
|
95
|
+
* "Children Presentational: True" unless the descendant
|
|
96
|
+
* is not allowed to be presentational because it meets one of
|
|
97
|
+
* the conditions for exception described in
|
|
98
|
+
* Presentational Roles Conflict Resolution.
|
|
99
|
+
* However, the text content of any excluded descendants is included.
|
|
100
|
+
*/
|
|
101
|
+
{
|
|
102
|
+
let currentEl = el.parentElement;
|
|
103
|
+
while (currentEl) {
|
|
104
|
+
const { role } = (0, get_computed_role_1.getComputedRole)(specs, currentEl, version);
|
|
105
|
+
if (role === null || role === void 0 ? void 0 : role.childrenPresentational) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
currentEl = currentEl.parentElement;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Including Elements in the Accessibility Tree
|
|
115
|
+
*
|
|
116
|
+
* If not excluded from or marked as hidden in the accessibility tree
|
|
117
|
+
* per the rules above in Excluding Elements in the Accessibility Tree,
|
|
118
|
+
* user agents MUST provide an accessible object in the accessibility tree
|
|
119
|
+
* for DOM elements that meet any of the following criteria:
|
|
120
|
+
*
|
|
121
|
+
* @see https://www.w3.org/TR/wai-aria-1.2/#tree_inclusion
|
|
122
|
+
*
|
|
123
|
+
* @param specs
|
|
124
|
+
* @param el
|
|
125
|
+
* @param version
|
|
126
|
+
*/
|
|
127
|
+
function isIncluding(el, specs, version) {
|
|
128
|
+
/**
|
|
129
|
+
* > **meet any** of the following criteria:
|
|
130
|
+
*/
|
|
131
|
+
const results = [];
|
|
132
|
+
/**
|
|
133
|
+
* Elements that are not hidden and may fire an accessibility API event,
|
|
134
|
+
* including:
|
|
135
|
+
* - Elements that are currently focused, even if the element or one of
|
|
136
|
+
* its ancestor elements has its aria-hidden attribute set to true.
|
|
137
|
+
*/
|
|
138
|
+
// 🚫 Can't detect the element is focused.
|
|
139
|
+
// results.push(true);
|
|
140
|
+
/**
|
|
141
|
+
* - Elements that are a valid target of an aria-activedescendant attribute.
|
|
142
|
+
*/
|
|
143
|
+
// TODO: Compute aria-activedescendant.
|
|
144
|
+
// results.push(true);
|
|
145
|
+
/**
|
|
146
|
+
* Elements that have an explicit role or a global WAI-ARIA attribute and
|
|
147
|
+
* do not have aria-hidden set to true.
|
|
148
|
+
* (See Excluding Elements in the Accessibility Tree for
|
|
149
|
+
* additional guidance on aria-hidden.)
|
|
150
|
+
*/
|
|
151
|
+
if (el.getAttribute('aria-hidden') !== 'true') {
|
|
152
|
+
const globalAria = (0, aria_specs_1.ariaSpecs)(specs, version).props.filter(prop => prop.isGlobal);
|
|
153
|
+
const { role } = (0, get_computed_role_1.getComputedRole)(specs, el, version);
|
|
154
|
+
// Has an explicit role
|
|
155
|
+
if (role && !role.isImplicit) {
|
|
156
|
+
results.push(true);
|
|
157
|
+
}
|
|
158
|
+
// Has a global WAI-ARIA attribute
|
|
159
|
+
for (const attr of Array.from(el.attributes)) {
|
|
160
|
+
if (globalAria.some(aria => aria.name === attr.localName)) {
|
|
161
|
+
results.push(true);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Elements that are not hidden and have an ID that is referenced
|
|
168
|
+
* by another element via a WAI-ARIA property.
|
|
169
|
+
*/
|
|
170
|
+
// TODO: Compute refering ID.
|
|
171
|
+
// results.push(true);
|
|
172
|
+
return results.includes(true);
|
|
173
|
+
}
|
|
174
|
+
function hasDisplayNodeOrVisibilityHidden(el) {
|
|
175
|
+
const style = el.getAttribute('style');
|
|
176
|
+
if (!style) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
// TODO: Improve accuracy
|
|
180
|
+
return /display\s*:\s*none|visibility\s*:\s*hidden/gi.test(style);
|
|
181
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
export * from './dom-traverse/accname-computation';
|
|
2
2
|
export * from './dom-traverse/get-attr-specs';
|
|
3
|
+
export * from './dom-traverse/get-computed-aria-props';
|
|
3
4
|
export * from './dom-traverse/get-computed-role';
|
|
4
5
|
export * from './dom-traverse/get-content-model';
|
|
5
6
|
export * from './dom-traverse/get-implicit-role';
|
|
6
7
|
export * from './dom-traverse/get-permitted-roles';
|
|
7
8
|
export * from './dom-traverse/get-spec';
|
|
8
9
|
export * from './dom-traverse/has-required-owned-elements';
|
|
10
|
+
export * from './dom-traverse/is-exposed';
|
|
9
11
|
export * from './dom-traverse/may-be-focusable';
|
|
10
12
|
export * from './specs/aria-specs';
|
|
11
13
|
export * from './specs/content-model-category-to-tag-names';
|
|
12
14
|
export * from './specs/get-role-spec';
|
|
13
15
|
export * from './specs/get-spec-by-tag-name';
|
|
16
|
+
export * from './specs/is-palpable-elements';
|
|
17
|
+
export * from './specs/is-void-element';
|
|
14
18
|
export * from './specs/schema-to-spec';
|
|
15
19
|
export * from './types';
|
|
16
20
|
export * from './types/aria';
|
package/lib/index.js
CHANGED
|
@@ -3,17 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./dom-traverse/accname-computation"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./dom-traverse/get-attr-specs"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./dom-traverse/get-computed-aria-props"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./dom-traverse/get-computed-role"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./dom-traverse/get-content-model"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./dom-traverse/get-implicit-role"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./dom-traverse/get-permitted-roles"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./dom-traverse/get-spec"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./dom-traverse/has-required-owned-elements"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./dom-traverse/is-exposed"), exports);
|
|
12
14
|
tslib_1.__exportStar(require("./dom-traverse/may-be-focusable"), exports);
|
|
13
15
|
tslib_1.__exportStar(require("./specs/aria-specs"), exports);
|
|
14
16
|
tslib_1.__exportStar(require("./specs/content-model-category-to-tag-names"), exports);
|
|
15
17
|
tslib_1.__exportStar(require("./specs/get-role-spec"), exports);
|
|
16
18
|
tslib_1.__exportStar(require("./specs/get-spec-by-tag-name"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./specs/is-palpable-elements"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./specs/is-void-element"), exports);
|
|
17
21
|
tslib_1.__exportStar(require("./specs/schema-to-spec"), exports);
|
|
18
22
|
tslib_1.__exportStar(require("./types"), exports);
|
|
19
23
|
tslib_1.__exportStar(require("./types/aria"), exports);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ARIAVersion, MLMLSpec } from '../types';
|
|
2
|
-
export declare function ariaSpecs(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare function ariaSpecs(
|
|
3
|
+
specs: Readonly<MLMLSpec>,
|
|
4
|
+
version: ARIAVersion,
|
|
5
|
+
): {
|
|
6
|
+
roles: import('../types').ARIARoleInSchema[];
|
|
7
|
+
graphicsRoles: import('../types').ARIARoleInSchema[];
|
|
8
|
+
props: import('../types').ARIAProperty[];
|
|
6
9
|
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { MLMLSpec } from '../types';
|
|
2
2
|
import type { Category } from '../types/permitted-structures';
|
|
3
|
-
export declare function contentModelCategoryToTagNames(
|
|
3
|
+
export declare function contentModelCategoryToTagNames(
|
|
4
|
+
contentModel: Category,
|
|
5
|
+
def: MLMLSpec['def'],
|
|
6
|
+
): ReadonlyArray<string>;
|
package/lib/specs/get-aria.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { ARIAVersion, Matches, MLMLSpec } from '../types';
|
|
2
2
|
import type { ARIA } from '../types/aria';
|
|
3
|
-
export declare function getARIA(
|
|
3
|
+
export declare function getARIA(
|
|
4
|
+
specs: Readonly<MLMLSpec>,
|
|
5
|
+
localName: string,
|
|
6
|
+
namespace: string | null,
|
|
7
|
+
version: ARIAVersion,
|
|
8
|
+
matches: Matches,
|
|
9
|
+
): Omit<ARIA, ARIAVersion | 'conditions'> | null;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { MLMLSpec, Attribute } from '../types';
|
|
2
2
|
import type { NamespaceURI } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function getAttrSpecs(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function getAttrSpecs(
|
|
4
|
+
localName: string,
|
|
5
|
+
namespace: NamespaceURI | null,
|
|
6
|
+
schema: MLMLSpec,
|
|
7
|
+
): Attribute[] | null;
|
|
8
|
+
type HasName = {
|
|
9
|
+
name: string;
|
|
6
10
|
};
|
|
7
11
|
export declare function nameCompare(a: HasName | string, b: HasName | string): 1 | -1 | 0;
|
|
8
12
|
export {};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { ARIAVersion, Matches, MLMLSpec } from '../types';
|
|
2
|
-
export declare function getImplicitRole(
|
|
2
|
+
export declare function getImplicitRole(
|
|
3
|
+
specs: Readonly<MLMLSpec>,
|
|
4
|
+
localName: string,
|
|
5
|
+
namespace: string | null,
|
|
6
|
+
version: ARIAVersion,
|
|
7
|
+
matches: Matches,
|
|
8
|
+
): import('..').ImplicitRole;
|
|
@@ -6,7 +6,13 @@ import type { ARIAVersion, Matches, MLMLSpec } from '../types';
|
|
|
6
6
|
* - If `true`, this mean is "Any".
|
|
7
7
|
* - If `false`, this mean is "No".
|
|
8
8
|
*/
|
|
9
|
-
export declare function getPermittedRoles(
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export declare function getPermittedRoles(
|
|
10
|
+
specs: Readonly<MLMLSpec>,
|
|
11
|
+
localName: string,
|
|
12
|
+
namespace: string | null,
|
|
13
|
+
version: ARIAVersion,
|
|
14
|
+
matches: Matches,
|
|
15
|
+
): {
|
|
16
|
+
name: string;
|
|
17
|
+
deprecated?: boolean;
|
|
12
18
|
}[];
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ARIAVersion, ARIARoleInSchema, MLMLSpec, ARIARole } from '../types';
|
|
2
2
|
import type { NamespaceURI } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function getRoleSpec(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function getRoleSpec(
|
|
4
|
+
specs: Readonly<MLMLSpec>,
|
|
5
|
+
roleName: string,
|
|
6
|
+
namespace: NamespaceURI,
|
|
7
|
+
version: ARIAVersion,
|
|
8
|
+
):
|
|
9
|
+
| (ARIARole & {
|
|
10
|
+
superClassRoles: ARIARoleInSchema[];
|
|
11
|
+
})
|
|
12
|
+
| null;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { MLMLSpec } from '../types';
|
|
2
2
|
import type { Category } from '../types/permitted-structures';
|
|
3
|
-
export declare function getSelectorsByContentModelCategory(
|
|
3
|
+
export declare function getSelectorsByContentModelCategory(
|
|
4
|
+
specs: Readonly<MLMLSpec>,
|
|
5
|
+
category: Category,
|
|
6
|
+
): ReadonlyArray<string>;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { ElementSpec } from '../types';
|
|
2
|
-
export declare function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(
|
|
2
|
+
export declare function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(
|
|
3
|
+
specs: Readonly<Pick<ElementSpec, 'name' | K>[]>,
|
|
4
|
+
localName: string,
|
|
5
|
+
namespace: string | null,
|
|
6
|
+
): Pick<ElementSpec, 'name' | K> | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPalpableElement = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Exposable content models and elements
|
|
6
|
+
*
|
|
7
|
+
* **WARNING**:
|
|
8
|
+
* This implementation is through the author's interpretation.
|
|
9
|
+
* Want a issue request.
|
|
10
|
+
* https://github.com/markuplint/markuplint/issues/new
|
|
11
|
+
*
|
|
12
|
+
* @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
|
|
13
|
+
*/
|
|
14
|
+
const exposableElementsThatAreNoBelongingAModel = [
|
|
15
|
+
'body',
|
|
16
|
+
'dd',
|
|
17
|
+
'dt',
|
|
18
|
+
'figcaption',
|
|
19
|
+
'html',
|
|
20
|
+
'legend',
|
|
21
|
+
'li',
|
|
22
|
+
'optgroup',
|
|
23
|
+
'option',
|
|
24
|
+
'rp',
|
|
25
|
+
'rt',
|
|
26
|
+
'summary',
|
|
27
|
+
'tbody',
|
|
28
|
+
'td',
|
|
29
|
+
'tfoot',
|
|
30
|
+
'th',
|
|
31
|
+
'thead',
|
|
32
|
+
'tr',
|
|
33
|
+
];
|
|
34
|
+
function isPalpableElement(el, specs, options) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const conditions = [((_a = specs.def['#contentModels']['#palpable']) === null || _a === void 0 ? void 0 : _a.join(',')) || ''];
|
|
37
|
+
if ((options === null || options === void 0 ? void 0 : options.extendsSvg) !== false /* default true */) {
|
|
38
|
+
conditions.push(((_b = specs.def['#contentModels']['#SVGRenderable']) === null || _b === void 0 ? void 0 : _b.join(',')) || '');
|
|
39
|
+
}
|
|
40
|
+
if (options === null || options === void 0 ? void 0 : options.extendsExposableElements /* default false */) {
|
|
41
|
+
conditions.push(exposableElementsThatAreNoBelongingAModel.join(','));
|
|
42
|
+
}
|
|
43
|
+
return conditions.some(condition => {
|
|
44
|
+
return el.matches(condition);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.isPalpableElement = isPalpableElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isVoidElement(el: Element): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVoidElement = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @see https://html.spec.whatwg.org/multipage/syntax.html#void-elements
|
|
6
|
+
*/
|
|
7
|
+
const voidElements = [
|
|
8
|
+
'area',
|
|
9
|
+
'base',
|
|
10
|
+
'br',
|
|
11
|
+
'col',
|
|
12
|
+
'embed',
|
|
13
|
+
'hr',
|
|
14
|
+
'img',
|
|
15
|
+
'input',
|
|
16
|
+
'link',
|
|
17
|
+
'meta',
|
|
18
|
+
'source',
|
|
19
|
+
'track',
|
|
20
|
+
'wbr',
|
|
21
|
+
];
|
|
22
|
+
function isVoidElement(el) {
|
|
23
|
+
return voidElements.includes(el.localName);
|
|
24
|
+
}
|
|
25
|
+
exports.isVoidElement = isVoidElement;
|
|
@@ -7,7 +7,7 @@ import type { ElementSpec, ExtendedSpec, MLMLSpec } from '../types';
|
|
|
7
7
|
* @param schemas `MLDocument.schemas`
|
|
8
8
|
*/
|
|
9
9
|
export declare function schemaToSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]): {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
cites: import('../types').Cites;
|
|
11
|
+
def: import('../types').SpecDefs;
|
|
12
|
+
specs: ElementSpec[];
|
|
13
13
|
};
|