@markuplint/ml-spec 3.7.0 → 3.8.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.
@@ -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(localName: string, namespace: NamespaceURI | null, schema: MLMLSpec): readonly Attribute[] | null;
3
+ export declare function getAttrSpecs(
4
+ localName: string,
5
+ namespace: NamespaceURI | null,
6
+ schema: MLMLSpec,
7
+ ): readonly Attribute[] | null;
4
8
  type HasName = {
5
- readonly name: string;
9
+ readonly name: string;
6
10
  };
7
- export declare function nameCompare(a: HasName | string, b: HasName | string): 0 | 1 | -1;
11
+ export declare function nameCompare(a: HasName | string, b: HasName | string): 1 | -1 | 0;
8
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "3.7.0",
3
+ "version": "3.8.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.1.0",
29
+ "@markuplint/types": "3.6.0",
29
30
  "dom-accessibility-api": "^0.5.14",
30
31
  "is-plain-object": "^5.0.0",
31
- "tslib": "^2.4.1"
32
+ "tslib": "^2.4.1",
33
+ "type-fest": "^3.8.0"
32
34
  },
33
35
  "devDependencies": {
34
- "@markuplint/test-tools": "3.2.0",
35
- "@markuplint/types": "3.5.1",
36
- "json-schema-to-typescript": "11.0.2",
37
- "type-fest": "^3.6.1"
36
+ "@markuplint/test-tools": "3.3.0",
37
+ "json-schema-to-typescript": "11.0.2"
38
38
  },
39
- "gitHead": "42b97b47d22b37437024e693a72a458e2963e261"
39
+ "gitHead": "adc6e432cccba7cfad0dc8bf9f92e5aaf1107359"
40
40
  }
@@ -0,0 +1,69 @@
1
+ const { createJSDOMElement: c } = require('@markuplint/test-tools');
2
+
3
+ const { getAccname } = require('../../lib/dom-traverse/accname-computation');
4
+
5
+ test('Get accessible name', () => {
6
+ expect(getAccname(c('<button>label</button>'))).toBe('label');
7
+ expect(getAccname(c('<div>text</div>'))).toBe('');
8
+ expect(getAccname(c('<div aria-label="label">text</div>'))).toBe('label');
9
+ expect(getAccname(c('<span aria-label="label">text</span>'))).toBe('label');
10
+ expect(getAccname(c('<img alt="alternative-text" />'))).toBe('alternative-text');
11
+ expect(getAccname(c('<img title="title" />'))).toBe('title');
12
+ expect(getAccname(c('<div><label for="a">label</label><input id="a" /></div>').children[1])).toBe('label');
13
+ });
14
+
15
+ test('Invisible element', () => {
16
+ expect(getAccname(c('<button>label</button>'))).toBe('label');
17
+ expect(getAccname(c('<button aria-disabled="true">label</button>'))).toBe('label');
18
+ expect(getAccname(c('<button aria-hidden="true">label</button>'))).toBe('');
19
+ expect(getAccname(c('<button hidden>label</button>'))).toBe('');
20
+ expect(getAccname(c('<button style="display: none">label</button>'))).toBe('');
21
+ });
22
+
23
+ /**
24
+ * @see https://www.w3.org/TR/accname-1.1/#ex-1-example-1-element1-id-el1-aria-labelledby-el3-element2-id-el2-aria-labelledby-el1-element3-id-el3-hello-element3
25
+ */
26
+ test('accname-1.1 Example 1', () => {
27
+ const complex = c(`<div>
28
+ <input id="el1" aria-labelledby="el3" />
29
+ <input id="el2" aria-labelledby="el1" />
30
+ <h1 id="el3"> hello </h1>
31
+ </div>`);
32
+ expect(getAccname(complex.children[0])).toBe('hello');
33
+ expect(getAccname(complex.children[1])).toBe('');
34
+ expect(getAccname(complex.children[2])).toBe('hello');
35
+ });
36
+
37
+ /**
38
+ * @see https://www.w3.org/TR/accname-1.1/#ex-2-example-2-h1-files-h1-ul-li-a-id-file_row1-href-files-documentation-pdf-documentation-pdf-a-span-role-button-tabindex-0-id-del_row1-aria-label-delete-aria-labelledby-del_row1-file_row1-span-li-li-a-id-file_row2-href-files-holidayletter-pdf-holidayletter-pdf-a-span-role-button-tabindex-0-id-del_row2-aria-label-delete-aria-labelledby-del_row2-file_row2-span-li-ul
39
+ */
40
+ test('accname-1.1 Example 2', () => {
41
+ const complex = c(`<ul>
42
+ <li>
43
+ <a id="file_row1" href="./files/Documentation.pdf">Documentation.pdf</a>
44
+ <span role="button" tabindex="0" id="del_row1" aria-label="Delete" aria-labelledby="del_row1 file_row1"></span>
45
+ </li>
46
+ <li>
47
+ <a id="file_row2" href="./files/HolidayLetter.pdf">HolidayLetter.pdf</a>
48
+ <span role="button" tabindex="0" id="del_row2" aria-label="Delete" aria-labelledby="del_row2 file_row2"></span>
49
+ </li>
50
+ </ul>`);
51
+ const spans = complex.querySelectorAll('span');
52
+ expect(getAccname(spans[0])).toBe('Delete Documentation.pdf');
53
+ expect(getAccname(spans[1])).toBe('Delete HolidayLetter.pdf');
54
+ });
55
+
56
+ /**
57
+ * @see https://www.w3.org/TR/accname-1.1/#ex-3-example-3-div-role-checkbox-aria-checked-false-flash-the-screen-span-role-textbox-aria-multiline-false-5-span-times-div
58
+ */
59
+ test('accname-1.1 Example 3', () => {
60
+ const complex = c(
61
+ '<div role="checkbox" aria-checked="false">Flash the screen <span role="textbox" aria-multiline="false"> 5 </span> times</div>',
62
+ );
63
+ expect(getAccname(complex)).toBe('Flash the screen 5 times');
64
+ });
65
+
66
+ test('with comment', () => {
67
+ expect(getAccname(c('<button>label</button>'))).toBe('label');
68
+ expect(getAccname(c('<button>label<!-- comment --></button>'))).toBe('label');
69
+ });