@markuplint/ml-spec 3.10.0 → 3.11.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getComputedRole = void 0;
4
4
  const aria_specs_1 = require("../specs/aria-specs");
5
5
  const is_presentational_1 = require("../specs/is-presentational");
6
+ const accname_computation_1 = require("./accname-computation");
6
7
  const get_attr_specs_1 = require("./get-attr-specs");
7
8
  const get_explicit_role_1 = require("./get-explicit-role");
8
9
  const get_implicit_role_1 = require("./get-implicit-role");
@@ -13,7 +14,7 @@ const may_be_focusable_1 = require("./may-be-focusable");
13
14
  function getComputedRole(specs,
14
15
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
15
16
  el, version, assumeSingleNode = false) {
16
- var _a, _b;
17
+ var _a, _b, _c, _d;
17
18
  const implicitRole = (0, get_implicit_role_1.getImplicitRole)(specs, el, version);
18
19
  const explicitRole = (0, get_explicit_role_1.getExplicitRole)(specs, el, version);
19
20
  const computedRole = explicitRole.role
@@ -83,6 +84,51 @@ el, version, assumeSingleNode = false) {
83
84
  };
84
85
  }
85
86
  }
87
+ /**
88
+ * SVG: Including Elements in the Accessibility Tree
89
+ *
90
+ * > Many SVG elements—although rendered to the screen—
91
+ * > do not have an intrinsic semantic meaning. Instead,
92
+ * > they represent components of the visual presentation of the document.
93
+ * > To simplify the accessible representation of the document,
94
+ * > these purely presentational elements should normally be omitted
95
+ * > from the accessibility tree, unless the author explicitly provides semantic content.
96
+ * >
97
+ * > However, any rendered SVG element may have semantic meaning.
98
+ * > Authors indicate the significance of the element
99
+ * > by including alternative text content or WAI-ARIA attributes.
100
+ * > This section defines the rules for including normally-omitted elements
101
+ * > in the accessibility tree.
102
+ * >
103
+ * > The following graphical and container elements
104
+ * > in the SVG namespace SHOULD NOT be included in the accessibility tree,
105
+ * > except as described in this section:
106
+ * >
107
+ * > - shape elements (circle, ellipse, line, path, polygon, polyline, rect)
108
+ * > - the use element
109
+ * > - the grouping (g) element
110
+ * > - the image element
111
+ * > - the mesh element
112
+ * > - text formatting elements (textPath, tspan)
113
+ * > - the foreignObject element
114
+ *
115
+ * @see https://www.w3.org/TR/svg-aam-1.0/#include_elements
116
+ */
117
+ if (
118
+ // It doesn't been specified a valid explicit role.
119
+ (explicitRole.role === null || explicitRole.errorType != null) &&
120
+ // It is an SVG element.
121
+ el.namespaceURI === 'http://www.w3.org/2000/svg') {
122
+ const accname = (0, accname_computation_1.getAccname)(el).trim() ||
123
+ ((_b = (_a = Array.from(el.children)
124
+ .find(child => ['title', 'desc'].includes(child.localName))) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim());
125
+ if (!accname) {
126
+ return {
127
+ el,
128
+ role: null,
129
+ };
130
+ }
131
+ }
86
132
  if (computedRole.role && !(0, is_presentational_1.isPresentational)(computedRole.role.name)) {
87
133
  return computedRole;
88
134
  }
@@ -138,7 +184,7 @@ el, version, assumeSingleNode = false) {
138
184
  */
139
185
  if (explicitRole.role) {
140
186
  const nonPresentationalAncestor = (0, get_non_presentational_ancestor_1.getNonPresentationalAncestor)(el, specs, version);
141
- if (nonPresentationalAncestor.role && ((_a = nonPresentationalAncestor.role) === null || _a === void 0 ? void 0 : _a.requiredOwnedElements.length) > 0) {
187
+ if (nonPresentationalAncestor.role && ((_c = nonPresentationalAncestor.role) === null || _c === void 0 ? void 0 : _c.requiredOwnedElements.length) > 0) {
142
188
  if (nonPresentationalAncestor.role.requiredOwnedElements.some(expected => {
143
189
  // const ancestor = nonPresentationalAncestor.el;
144
190
  // const ancestorImplicitRole = getImplicitRole(specs, ancestor, version);
@@ -164,7 +210,7 @@ el, version, assumeSingleNode = false) {
164
210
  */
165
211
  const { props } = (0, aria_specs_1.ariaSpecs)(specs, version);
166
212
  for (const attr of Array.from(el.attributes)) {
167
- if ((_b = props.find(p => p.name === attr.name)) === null || _b === void 0 ? void 0 : _b.isGlobal) {
213
+ if ((_d = props.find(p => p.name === attr.name)) === null || _d === void 0 ? void 0 : _d.isGlobal) {
168
214
  return {
169
215
  ...implicitRole,
170
216
  errorType: 'GLOBAL_PROP_MUST_NOT_BE_PRESENTATIONAL',
@@ -12,7 +12,7 @@ export interface AttributesSchema {
12
12
  }
13
13
  export interface GlobalAttributes {
14
14
  '#HTMLGlobalAttrs'?: boolean;
15
- '#GlobalEventAttrs'?: boolean | ('onabort' | 'onauxclick' | 'onbeforeinput' | 'onbeforematch' | 'onbeforetoggle' | 'onblur' | 'oncancel' | 'oncanplay' | 'oncanplaythrough' | 'onchange' | 'onclick' | 'onclose' | 'oncompositionend' | 'oncompositionstart' | 'oncompositionupdate' | 'oncontextlost' | 'oncontextmenu' | 'oncontextrestored' | 'oncopy' | 'oncuechange' | 'oncut' | 'ondblclick' | 'ondrag' | 'ondragend' | 'ondragenter' | 'ondragleave' | 'ondragover' | 'ondragstart' | 'ondrop' | 'ondurationchange' | 'onemptied' | 'onended' | 'onerror' | 'onfocus' | 'onfocusin' | 'onfocusout' | 'onformdata' | 'oninput' | 'oninvalid' | 'onkeydown' | 'onkeypress' | 'onkeyup' | 'onload' | 'onloadeddata' | 'onloadedmetadata' | 'onloadstart' | 'onmousedown' | 'onmouseenter' | 'onmouseleave' | 'onmousemove' | 'onmouseout' | 'onmouseover' | 'onmouseup' | 'onpaste' | 'onpause' | 'onplay' | 'onplaying' | 'onprogress' | 'onratechange' | 'onreset' | 'onresize' | 'onscroll' | 'onsecuritypolicyviolation' | 'onseeked' | 'onseeking' | 'onselect' | 'onslotchange' | 'onstalled' | 'onsubmit' | 'onsuspend' | 'ontimeupdate' | 'ontoggle' | 'onunload' | 'onvolumechange' | 'onwaiting' | 'onwebkitanimationend' | 'onwebkitanimationiteration' | 'onwebkitanimationstart' | 'onwebkittransitionend' | 'onwheel')[];
15
+ '#GlobalEventAttrs'?: boolean | ('onabort' | 'onauxclick' | 'onbeforeinput' | 'onbeforematch' | 'onbeforetoggle' | 'onblur' | 'oncancel' | 'oncanplay' | 'oncanplaythrough' | 'onchange' | 'onclick' | 'onclose' | 'oncompositionend' | 'oncompositionstart' | 'oncompositionupdate' | 'oncontextlost' | 'oncontextmenu' | 'oncontextrestored' | 'oncopy' | 'oncuechange' | 'oncut' | 'ondblclick' | 'ondrag' | 'ondragend' | 'ondragenter' | 'ondragleave' | 'ondragover' | 'ondragstart' | 'ondrop' | 'ondurationchange' | 'onemptied' | 'onended' | 'onerror' | 'onfocus' | 'onfocusin' | 'onfocusout' | 'onformdata' | 'oninput' | 'oninvalid' | 'onkeydown' | 'onkeypress' | 'onkeyup' | 'onload' | 'onloadeddata' | 'onloadedmetadata' | 'onloadstart' | 'onmousedown' | 'onmouseenter' | 'onmouseleave' | 'onmousemove' | 'onmouseout' | 'onmouseover' | 'onmouseup' | 'onpaste' | 'onpause' | 'onplay' | 'onplaying' | 'onprogress' | 'onratechange' | 'onreset' | 'onresize' | 'onscroll' | 'onsecuritypolicyviolation' | 'onseeked' | 'onseeking' | 'onselect' | 'onslotchange' | 'onstalled' | 'onsubmit' | 'onsuspend' | 'ontimeupdate' | 'ontoggle' | 'onunload' | 'onvolumechange' | 'onwaiting' | 'onwebkitanimationend' | 'onwebkitanimationiteration' | 'onwebkitanimationstart' | 'onwebkittransitionend' | 'onwheel' | 'onanimationstart' | 'onanimationiteration' | 'onanimationend' | 'onanimationcancel' | 'ontransitionrun' | 'ontransitionstart' | 'ontransitionend' | 'ontransitioncancel')[];
16
16
  /**
17
17
  * @minItems 0
18
18
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Types and schema that specs of the Markup languages for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -26,15 +26,15 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@markuplint/ml-ast": "3.2.0",
29
- "@markuplint/types": "3.8.0",
29
+ "@markuplint/types": "3.9.0",
30
30
  "dom-accessibility-api": "^0.6.1",
31
31
  "is-plain-object": "^5.0.0",
32
- "tslib": "^2.5.3",
33
- "type-fest": "^3.11.1"
32
+ "tslib": "^2.6.0",
33
+ "type-fest": "^3.12.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@markuplint/test-tools": "3.5.0",
36
+ "@markuplint/test-tools": "3.6.0",
37
37
  "json-schema-to-typescript": "13.0.2"
38
38
  },
39
- "gitHead": "9547b8dca20736a93e4d01af2d61bee314ba5718"
39
+ "gitHead": "4ab20276db48a6acb29a923ea8666890ca853442"
40
40
  }
@@ -60,8 +60,12 @@ describe('1.2', () => {
60
60
  expect(c('<svg><rect role="graphics-symbol img"></rect></svg>', '1.2', 'rect').role?.name).toBe(
61
61
  'graphics-symbol',
62
62
  );
63
- expect(c('<svg><rect role="roletype img"></rect></svg>', '1.2', 'rect').role?.name).toBe('img');
64
- expect(c('<svg><rect role="roletype"></rect></svg>', '1.2', 'rect').role?.name).toBe('graphics-symbol');
63
+ expect(c('<svg><rect role="roletype img" aria-label="accname"></rect></svg>', '1.2', 'rect').role?.name).toBe(
64
+ 'img',
65
+ );
66
+ expect(c('<svg><rect role="roletype" aria-label="accname"></rect></svg>', '1.2', 'rect').role?.name).toBe(
67
+ 'graphics-symbol',
68
+ );
65
69
  });
66
70
 
67
71
  test('landmark', () => {
@@ -187,8 +191,12 @@ describe('1.3', () => {
187
191
  expect(c('<svg><rect role="graphics-symbol img"></rect></svg>', '1.3', 'rect').role?.name).toBe(
188
192
  'graphics-symbol',
189
193
  );
190
- expect(c('<svg><rect role="roletype img"></rect></svg>', '1.3', 'rect').role?.name).toBe('img');
191
- expect(c('<svg><rect role="roletype"></rect></svg>', '1.3', 'rect').role?.name).toBe('graphics-symbol');
194
+ expect(c('<svg><rect role="roletype img" aria-label="accname"></rect></svg>', '1.3', 'rect').role?.name).toBe(
195
+ 'img',
196
+ );
197
+ expect(c('<svg><rect role="roletype" aria-label="accname"></rect></svg>', '1.3', 'rect').role?.name).toBe(
198
+ 'graphics-symbol',
199
+ );
192
200
  });
193
201
 
194
202
  test('landmark', () => {
@@ -291,4 +299,17 @@ describe('Issues', () => {
291
299
  expect(c('<td role="gridcell"></td>', '1.2').role?.name).toBe('gridcell');
292
300
  expect(c('<td role="gridcell"></td>', '1.3').role?.name).toBe('gridcell');
293
301
  });
302
+
303
+ test('#1026', () => {
304
+ expect(c('<svg><rect width="30" height="30" /></svg>', '1.2', 'rect').role?.name).toBe(undefined);
305
+ expect(
306
+ c('<svg><rect width="30" height="30"><title>Accname</title></rect></svg>', '1.2', 'rect').role?.name,
307
+ ).toBe('graphics-symbol');
308
+ expect(c('<svg><rect aria-label="accname" width="30" height="30" /></svg>', '1.2', 'rect').role?.name).toBe(
309
+ 'graphics-symbol',
310
+ );
311
+ expect(
312
+ c('<svg role="img"><rect aria-label="accname" width="30" height="30" /></svg>', '1.2', 'rect').role?.name,
313
+ ).toBe('graphics-symbol');
314
+ });
294
315
  });