@markuplint/ml-spec 3.7.0 → 3.9.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/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { getAttrSpecs as getAttrSpecsByNames } from './specs/get-attr-specs';
1
2
  export * from './constant/aria-version';
2
3
  export * from './dom-traverse/accname-computation';
3
4
  export * from './dom-traverse/get-attr-specs';
package/lib/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAttrSpecsByNames = void 0;
3
4
  const tslib_1 = require("tslib");
5
+ var get_attr_specs_1 = require("./specs/get-attr-specs");
6
+ Object.defineProperty(exports, "getAttrSpecsByNames", { enumerable: true, get: function () { return get_attr_specs_1.getAttrSpecs; } });
4
7
  tslib_1.__exportStar(require("./constant/aria-version"), exports);
5
8
  tslib_1.__exportStar(require("./dom-traverse/accname-computation"), exports);
6
9
  tslib_1.__exportStar(require("./dom-traverse/get-attr-specs"), exports);
@@ -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/lib/types/aria.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
2
  /**
4
3
  * This file was automatically generated by json-schema-to-typescript.
5
4
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
2
  /**
4
3
  * This file was automatically generated by json-schema-to-typescript.
5
4
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
2
  /**
4
3
  * This file was automatically generated by json-schema-to-typescript.
5
4
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "3.7.0",
3
+ "version": "3.9.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
- "dom-accessibility-api": "^0.5.14",
29
+ "@markuplint/types": "3.7.0",
30
+ "dom-accessibility-api": "^0.5.16",
30
31
  "is-plain-object": "^5.0.0",
31
- "tslib": "^2.4.1"
32
+ "tslib": "^2.5.0",
33
+ "type-fest": "^3.10.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.4.0",
37
+ "json-schema-to-typescript": "13.0.1"
38
38
  },
39
- "gitHead": "42b97b47d22b37437024e693a72a458e2963e261"
39
+ "gitHead": "af370797bfc887e5a5a2ff57fbaa8392ac98ead2"
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
+ });