@markuplint/rules 2.4.2 → 3.0.0-alpha.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.
Files changed (98) hide show
  1. package/README.md +1 -5
  2. package/lib/attr-duplication/index.js +10 -7
  3. package/lib/attr-equal-space-after/index.d.ts +1 -1
  4. package/lib/attr-equal-space-before/index.d.ts +1 -1
  5. package/lib/attr-spacing/index.d.ts +3 -3
  6. package/lib/attr-value-quotes/index.js +21 -25
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -5
  8. package/lib/case-sensitive-attr-name/index.js +51 -81
  9. package/lib/case-sensitive-tag-name/index.js +38 -30
  10. package/lib/character-reference/index.d.ts +2 -1
  11. package/lib/character-reference/index.js +6 -8
  12. package/lib/class-naming/index.js +11 -11
  13. package/lib/deprecated-attr/index.js +17 -18
  14. package/lib/deprecated-element/index.js +5 -7
  15. package/lib/disallowed-element/index.js +8 -9
  16. package/lib/doctype/index.js +7 -7
  17. package/lib/end-tag/index.js +4 -1
  18. package/lib/helper/aria/get-aria.d.ts +7 -0
  19. package/lib/helper/aria/get-aria.js +53 -0
  20. package/lib/helper/aria/get-computed-role.d.ts +10 -0
  21. package/lib/helper/aria/get-computed-role.js +24 -0
  22. package/lib/helper/aria/get-implicit-role.d.ts +7 -0
  23. package/lib/helper/aria/get-implicit-role.js +12 -0
  24. package/lib/helper/aria/get-permitted-roles.d.ts +14 -0
  25. package/lib/helper/aria/get-permitted-roles.js +26 -0
  26. package/lib/helper/aria/resolve-version.d.ts +2 -0
  27. package/lib/helper/aria/resolve-version.js +21 -0
  28. package/lib/helper/spec/aria-spec.d.ts +5 -0
  29. package/lib/helper/spec/aria-spec.js +12 -0
  30. package/lib/helper/spec/get-role-spec.d.ts +11 -0
  31. package/lib/helper/spec/get-role-spec.js +39 -0
  32. package/lib/helper/spec/html-spec.d.ts +2 -0
  33. package/lib/helper/spec/html-spec.js +14 -0
  34. package/lib/helpers.d.ts +10 -28
  35. package/lib/helpers.js +29 -149
  36. package/lib/id-duplication/index.js +4 -6
  37. package/lib/indentation/index.d.ts +3 -3
  38. package/lib/index.d.ts +14 -19
  39. package/lib/index.js +0 -8
  40. package/lib/ineffective-attr/index.js +19 -27
  41. package/lib/invalid-attr/index.js +83 -83
  42. package/lib/landmark-roles/index.d.ts +2 -2
  43. package/lib/landmark-roles/index.js +9 -9
  44. package/lib/no-boolean-attr-value/index.js +33 -34
  45. package/lib/no-default-value/index.js +20 -24
  46. package/lib/no-hard-code-id/index.js +9 -13
  47. package/lib/no-refer-to-non-existent-id/index.d.ts +4 -1
  48. package/lib/no-refer-to-non-existent-id/index.js +77 -83
  49. package/lib/no-use-event-handler-attr/index.js +20 -22
  50. package/lib/permitted-contents/index.d.ts +5 -2
  51. package/lib/permitted-contents/index.js +67 -68
  52. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +5 -5
  53. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +19 -14
  54. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +2 -2
  55. package/lib/require-accessible-name/index.d.ts +5 -1
  56. package/lib/require-accessible-name/index.js +6 -3
  57. package/lib/required-attr/index.js +16 -25
  58. package/lib/required-element/index.d.ts +1 -1
  59. package/lib/required-element/index.js +6 -6
  60. package/lib/required-h1/index.d.ts +2 -2
  61. package/lib/required-h1/index.js +3 -3
  62. package/lib/wai-aria/checkings/abstract-role.d.ts +3 -0
  63. package/lib/wai-aria/checkings/abstract-role.js +22 -0
  64. package/lib/wai-aria/checkings/checking-required-owned-elements.d.ts +11 -0
  65. package/lib/wai-aria/checkings/checking-required-owned-elements.js +63 -0
  66. package/lib/wai-aria/checkings/default-value.d.ts +6 -0
  67. package/lib/wai-aria/checkings/default-value.js +17 -0
  68. package/lib/wai-aria/checkings/deprecated-props.d.ts +7 -0
  69. package/lib/wai-aria/checkings/deprecated-props.js +18 -0
  70. package/lib/wai-aria/checkings/disallowed-prop.d.ts +7 -0
  71. package/lib/wai-aria/checkings/disallowed-prop.js +22 -0
  72. package/lib/wai-aria/checkings/implicit-props.d.ts +7 -0
  73. package/lib/wai-aria/checkings/implicit-props.js +50 -0
  74. package/lib/wai-aria/checkings/implicit-role.d.ts +3 -0
  75. package/lib/wai-aria/checkings/implicit-role.js +21 -0
  76. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
  77. package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
  78. package/lib/wai-aria/checkings/no-global-prop.d.ts +6 -0
  79. package/lib/wai-aria/checkings/no-global-prop.js +14 -0
  80. package/lib/wai-aria/checkings/non-existant-role.d.ts +3 -0
  81. package/lib/wai-aria/checkings/non-existant-role.js +28 -0
  82. package/lib/wai-aria/checkings/permitted-roles.d.ts +3 -0
  83. package/lib/wai-aria/checkings/permitted-roles.js +28 -0
  84. package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
  85. package/lib/wai-aria/checkings/presentational-children.js +60 -0
  86. package/lib/wai-aria/checkings/required-owned-elements.d.ts +11 -0
  87. package/lib/wai-aria/checkings/required-owned-elements.js +63 -0
  88. package/lib/wai-aria/checkings/required-prop.d.ts +9 -0
  89. package/lib/wai-aria/checkings/required-prop.js +27 -0
  90. package/lib/wai-aria/checkings/value.d.ts +7 -0
  91. package/lib/wai-aria/checkings/value.js +21 -0
  92. package/lib/wai-aria/index.d.ts +1 -8
  93. package/lib/wai-aria/index.js +66 -207
  94. package/lib/wai-aria/types.d.ts +13 -0
  95. package/lib/wai-aria/types.js +2 -0
  96. package/package.json +6 -6
  97. package/schema.json +0 -12
  98. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getARIA = void 0;
4
+ const html_spec_1 = require("../spec/html-spec");
5
+ const resolve_version_1 = require("./resolve-version");
6
+ const cache = new Map();
7
+ function getARIA(specs, el, version) {
8
+ var _a, _b, _c, _d, _e;
9
+ const aria = getVersionResolvedARIA(specs, el, version);
10
+ if (!aria) {
11
+ return null;
12
+ }
13
+ const conditions = aria.conditions;
14
+ if (!conditions) {
15
+ return aria;
16
+ }
17
+ const conds = Object.keys(conditions);
18
+ let { implicitRole, permittedRoles, implicitProperties, properties, namingProhibited } = aria;
19
+ for (const cond of conds) {
20
+ if (!el.matches(cond)) {
21
+ continue;
22
+ }
23
+ const condARIA = conditions[cond];
24
+ implicitRole = (_a = condARIA.implicitRole) !== null && _a !== void 0 ? _a : implicitRole;
25
+ permittedRoles = (_b = condARIA.permittedRoles) !== null && _b !== void 0 ? _b : permittedRoles;
26
+ implicitProperties = (_c = condARIA.implicitProperties) !== null && _c !== void 0 ? _c : implicitProperties;
27
+ properties = (_d = condARIA.properties) !== null && _d !== void 0 ? _d : properties;
28
+ namingProhibited = (_e = condARIA.namingProhibited) !== null && _e !== void 0 ? _e : namingProhibited;
29
+ }
30
+ return {
31
+ implicitRole,
32
+ permittedRoles,
33
+ implicitProperties,
34
+ properties,
35
+ namingProhibited,
36
+ };
37
+ }
38
+ exports.getARIA = getARIA;
39
+ function getVersionResolvedARIA(specs, el, version) {
40
+ var _a;
41
+ let aria = cache.get(el.nameWithNS + version);
42
+ if (aria !== undefined) {
43
+ return aria;
44
+ }
45
+ const spec = (_a = (0, html_spec_1.htmlSpec)(specs, el.nameWithNS)) === null || _a === void 0 ? void 0 : _a.aria;
46
+ if (!spec) {
47
+ cache.set(el.nameWithNS + version, null);
48
+ return null;
49
+ }
50
+ aria = (0, resolve_version_1.resolveVersion)(spec, version);
51
+ cache.set(el.nameWithNS + version, aria);
52
+ return aria;
53
+ }
@@ -0,0 +1,10 @@
1
+ import type { Element } from '@markuplint/ml-core';
2
+ import type { ARIAVersion, MLMLSpec } from '@markuplint/ml-spec';
3
+ export declare function getComputedRole(
4
+ specs: Readonly<MLMLSpec>,
5
+ el: Element<any, any>,
6
+ version: ARIAVersion,
7
+ ): {
8
+ name: string;
9
+ isImplicit: boolean;
10
+ } | null;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getComputedRole = void 0;
4
+ const get_implicit_role_1 = require("./get-implicit-role");
5
+ function getComputedRole(specs, el, version) {
6
+ const roleAttrTokens = el.getAttributeToken('role');
7
+ const roleAttr = roleAttrTokens[0];
8
+ if (roleAttr) {
9
+ const roleName = roleAttr.value.trim().toLowerCase();
10
+ return {
11
+ name: roleName,
12
+ isImplicit: false,
13
+ };
14
+ }
15
+ const implicitRole = (0, get_implicit_role_1.getImplicitRole)(specs, el, version);
16
+ if (implicitRole) {
17
+ return {
18
+ name: implicitRole,
19
+ isImplicit: true,
20
+ };
21
+ }
22
+ return null;
23
+ }
24
+ exports.getComputedRole = getComputedRole;
@@ -0,0 +1,7 @@
1
+ import type { Element } from '@markuplint/ml-core';
2
+ import type { ARIAVersion, MLMLSpec } from '@markuplint/ml-spec';
3
+ export declare function getImplicitRole(
4
+ specs: Readonly<MLMLSpec>,
5
+ el: Element<any, any>,
6
+ version: ARIAVersion,
7
+ ): import('@markuplint/ml-spec').ImplicitRole;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImplicitRole = void 0;
4
+ const get_aria_1 = require("./get-aria");
5
+ function getImplicitRole(specs, el, version) {
6
+ const aria = (0, get_aria_1.getARIA)(specs, el, version);
7
+ if (!aria) {
8
+ return false;
9
+ }
10
+ return aria.implicitRole;
11
+ }
12
+ exports.getImplicitRole = getImplicitRole;
@@ -0,0 +1,14 @@
1
+ import type { Element } from '@markuplint/ml-core';
2
+ import type { ARIAVersion, MLMLSpec } from '@markuplint/ml-spec';
3
+ /**
4
+ * Getting permitted ARIA roles.
5
+ *
6
+ * - If an array, it is role list.
7
+ * - If `true`, this mean is "Any".
8
+ * - If `false`, this mean is "No".
9
+ */
10
+ export declare function getPermittedRoles(
11
+ specs: Readonly<MLMLSpec>,
12
+ el: Element<any, any>,
13
+ version: ARIAVersion,
14
+ ): import('@markuplint/ml-spec').PermittedRoles;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPermittedRoles = void 0;
4
+ const get_aria_1 = require("./get-aria");
5
+ /**
6
+ * Getting permitted ARIA roles.
7
+ *
8
+ * - If an array, it is role list.
9
+ * - If `true`, this mean is "Any".
10
+ * - If `false`, this mean is "No".
11
+ */
12
+ function getPermittedRoles(specs, el, version) {
13
+ const aria = (0, get_aria_1.getARIA)(specs, el, version);
14
+ if (!aria) {
15
+ return true;
16
+ }
17
+ const { implicitRole, permittedRoles } = aria;
18
+ if (implicitRole && Array.isArray(permittedRoles)) {
19
+ return [implicitRole, ...permittedRoles];
20
+ }
21
+ if (implicitRole && permittedRoles === false) {
22
+ return [implicitRole];
23
+ }
24
+ return permittedRoles;
25
+ }
26
+ exports.getPermittedRoles = getPermittedRoles;
@@ -0,0 +1,2 @@
1
+ import type { ARIA, ARIAVersion } from '@markuplint/ml-spec';
2
+ export declare function resolveVersion(aria: ARIA, version: ARIAVersion): Omit<ARIA, ARIAVersion>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveVersion = void 0;
4
+ function resolveVersion(aria, version) {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
+ const implicitRole = (_b = (_a = aria[version]) === null || _a === void 0 ? void 0 : _a.implicitRole) !== null && _b !== void 0 ? _b : aria.implicitRole;
7
+ const permittedRoles = (_d = (_c = aria[version]) === null || _c === void 0 ? void 0 : _c.permittedRoles) !== null && _d !== void 0 ? _d : aria.permittedRoles;
8
+ const implicitProperties = (_f = (_e = aria[version]) === null || _e === void 0 ? void 0 : _e.implicitProperties) !== null && _f !== void 0 ? _f : aria.implicitProperties;
9
+ const properties = (_h = (_g = aria[version]) === null || _g === void 0 ? void 0 : _g.properties) !== null && _h !== void 0 ? _h : aria.properties;
10
+ const namingProhibited = version === '1.2' ? (_k = (_j = aria[version]) === null || _j === void 0 ? void 0 : _j.namingProhibited) !== null && _k !== void 0 ? _k : aria.namingProhibited : aria.namingProhibited;
11
+ const conditions = (_m = (_l = aria[version]) === null || _l === void 0 ? void 0 : _l.conditions) !== null && _m !== void 0 ? _m : aria.conditions;
12
+ return {
13
+ implicitRole,
14
+ permittedRoles,
15
+ implicitProperties,
16
+ properties,
17
+ namingProhibited,
18
+ conditions,
19
+ };
20
+ }
21
+ exports.resolveVersion = resolveVersion;
@@ -0,0 +1,5 @@
1
+ import type { MLMLSpec } from '@markuplint/ml-spec';
2
+ export declare function ariaSpec(specs: Readonly<MLMLSpec>): {
3
+ roles: import('@markuplint/ml-spec').ARIRRoleAttribute[];
4
+ ariaAttrs: import('@markuplint/ml-spec').ARIAProperty[];
5
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ariaSpec = void 0;
4
+ function ariaSpec(specs) {
5
+ const roles = specs.def['#roles'];
6
+ const ariaAttrs = specs.def['#ariaAttrs'];
7
+ return {
8
+ roles,
9
+ ariaAttrs,
10
+ };
11
+ }
12
+ exports.ariaSpec = ariaSpec;
@@ -0,0 +1,11 @@
1
+ import type { ARIRRoleAttribute, MLMLSpec } from '@markuplint/ml-spec';
2
+ export declare function getRoleSpec(
3
+ specs: Readonly<MLMLSpec>,
4
+ roleName: string,
5
+ ): {
6
+ name: string;
7
+ isAbstract: boolean;
8
+ accessibleNameRequired: boolean;
9
+ statesAndProps: import('@markuplint/ml-spec').ARIARoleOwnedPropOrState[];
10
+ superClassRoles: ARIRRoleAttribute[];
11
+ } | null;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRoleSpec = void 0;
4
+ function getRoleSpec(specs, roleName) {
5
+ const role = getRoleByName(specs, roleName);
6
+ if (!role) {
7
+ return null;
8
+ }
9
+ const superClassRoles = recursiveTraverseSuperClassRoles(specs, roleName);
10
+ return {
11
+ name: role.name,
12
+ isAbstract: !!role.isAbstract,
13
+ accessibleNameRequired: role.accessibleNameRequired,
14
+ statesAndProps: role.ownedAttribute,
15
+ superClassRoles,
16
+ };
17
+ }
18
+ exports.getRoleSpec = getRoleSpec;
19
+ function getRoleByName(specs, roleName) {
20
+ const roles = specs.def['#roles'];
21
+ const role = roles.find(r => r.name === roleName);
22
+ return role;
23
+ }
24
+ function recursiveTraverseSuperClassRoles(specs, roleName) {
25
+ const roles = [];
26
+ const superClassRoles = getSuperClassRoles(specs, roleName);
27
+ if (superClassRoles) {
28
+ roles.push(...superClassRoles);
29
+ for (const superClassRole of superClassRoles) {
30
+ const ancestorRoles = recursiveTraverseSuperClassRoles(specs, superClassRole.name);
31
+ roles.push(...ancestorRoles);
32
+ }
33
+ }
34
+ return roles;
35
+ }
36
+ function getSuperClassRoles(specs, roleName) {
37
+ const role = getRoleByName(specs, roleName);
38
+ return ((role === null || role === void 0 ? void 0 : role.generalization.map(roleName => getRoleByName(specs, roleName)).filter((role) => !!role)) || null);
39
+ }
@@ -0,0 +1,2 @@
1
+ import type { ElementSpec, MLMLSpec } from '@markuplint/ml-spec';
2
+ export declare function htmlSpec(specs: Readonly<MLMLSpec>, nameWithNS: string): ElementSpec | null;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.htmlSpec = void 0;
4
+ const cache = new Map();
5
+ function htmlSpec(specs, nameWithNS) {
6
+ let spec = cache.get(nameWithNS);
7
+ if (spec !== undefined) {
8
+ return spec;
9
+ }
10
+ spec = specs.specs.find(spec => spec.name === nameWithNS) || null;
11
+ cache.set(nameWithNS, spec);
12
+ return spec;
13
+ }
14
+ exports.htmlSpec = htmlSpec;
package/lib/helpers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Log } from './debug';
2
2
  import type { Translator } from '@markuplint/i18n';
3
3
  import type { Element, RuleConfigValue, Document } from '@markuplint/ml-core';
4
- import type { ARIRRoleAttribute, Attribute, MLMLSpec, PermittedRoles } from '@markuplint/ml-spec';
4
+ import type { ARIAVersion, Attribute, MLMLSpec } from '@markuplint/ml-spec';
5
5
  export declare function attrMatches<T extends RuleConfigValue, R>(node: Element<T, R>, condition: Attribute['condition']): boolean;
6
6
  export declare function match(needle: string, pattern: string): boolean;
7
7
  /**
@@ -20,7 +20,6 @@ export declare function match(needle: string, pattern: string): boolean;
20
20
  * Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
21
21
  */
22
22
  export declare const rePCENChar: string;
23
- export declare function htmlSpec(specs: Readonly<MLMLSpec>, nameWithNS: string): import("@markuplint/ml-spec").ElementSpec | null;
24
23
  export declare function isValidAttr(t: Translator, name: string, value: string, isDynamicValue: boolean, node: Element<any, any>, attrSpecs: Attribute[], log?: Log): false | {
25
24
  invalidType: "non-existent" | "invalid-value";
26
25
  message: string;
@@ -31,30 +30,6 @@ export declare function isValidAttr(t: Translator, name: string, value: string,
31
30
  } | undefined;
32
31
  };
33
32
  export declare function toNormalizedValue(value: string, spec: Attribute): string;
34
- export declare function ariaSpec(specs: Readonly<MLMLSpec>): {
35
- roles: ARIRRoleAttribute[];
36
- ariaAttrs: import("@markuplint/ml-spec").ARIAAttribute[];
37
- };
38
- export declare function getRoleSpec(specs: Readonly<MLMLSpec>, roleName: string): {
39
- name: string;
40
- isAbstract: boolean;
41
- accessibleNameRequired: boolean;
42
- statesAndProps: import("@markuplint/ml-spec").ARIARoleOwnedPropOrState[];
43
- superClassRoles: ARIRRoleAttribute[];
44
- } | null;
45
- /**
46
- * Getting permitted ARIA roles.
47
- *
48
- * - If an array, it is role list.
49
- * - If `true`, this mean is "Any".
50
- * - If `false`, this mean is "No".
51
- */
52
- export declare function getPermittedRoles(specs: Readonly<MLMLSpec>, el: Element<any, any>): PermittedRoles;
53
- export declare function getImplicitRole(specs: Readonly<MLMLSpec>, el: Element<any, any>): string | false;
54
- export declare function getComputedRole(specs: Readonly<MLMLSpec>, el: Element<any, any>): {
55
- name: string;
56
- isImplicit: boolean;
57
- } | null;
58
33
  /**
59
34
  *
60
35
  * @see https://www.w3.org/TR/wai-aria-1.2/#propcharacteristic_value
@@ -64,7 +39,7 @@ export declare function getComputedRole(specs: Readonly<MLMLSpec>, el: Element<a
64
39
  * @param tokenEnum
65
40
  */
66
41
  export declare function checkAriaValue(type: string, value: string, tokenEnum: string[]): boolean;
67
- export declare function checkAria(specs: Readonly<MLMLSpec>, attrName: string, currentValue: string, role?: string): {
42
+ export declare function checkAria(specs: Readonly<MLMLSpec>, attrName: string, currentValue: string, version: ARIAVersion, role?: string): {
68
43
  currentValue: string;
69
44
  isValid: boolean;
70
45
  } | {
@@ -85,5 +60,12 @@ export declare function checkAria(specs: Readonly<MLMLSpec>, attrName: string, c
85
60
  valueDescriptions?: Record<string, string> | undefined;
86
61
  };
87
62
  export declare function accnameMayBeMutable(el: Element<any, any>, document: Document<any, any>): boolean;
88
- export declare function getOwnedLabel<V extends RuleConfigValue, O>(el: Element<V, O>, docuemnt: Document<V, O>): import("packages/@markuplint/ml-core/lib/ml-dom/tokens/abstract-element").default<V, O, import("packages/@markuplint/ml-ast/src").MLASTElement | import("packages/@markuplint/ml-ast/src").MLASTOmittedElement> | null;
63
+ export declare function getOwnedLabel<V extends RuleConfigValue, O>(el: Element<V, O>, docuemnt: Document<V, O>): Element<V, O> | null;
89
64
  export declare function decodeCharRef(characterReference: string): string;
65
+ export declare class Collection<T> {
66
+ #private;
67
+ constructor(...items: (T | null | undefined)[]);
68
+ add(...items: (T | null | undefined)[]): void;
69
+ toArray(): readonly T[];
70
+ [Symbol.iterator](): Iterator<T>;
71
+ }
package/lib/helpers.js CHANGED
@@ -1,33 +1,17 @@
1
1
  "use strict";
2
+ var _Collection_items;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeCharRef = exports.getOwnedLabel = exports.accnameMayBeMutable = exports.checkAria = exports.checkAriaValue = exports.getComputedRole = exports.getImplicitRole = exports.getPermittedRoles = exports.getRoleSpec = exports.ariaSpec = exports.toNormalizedValue = exports.isValidAttr = exports.htmlSpec = exports.rePCENChar = exports.match = exports.attrMatches = void 0;
4
+ exports.Collection = exports.decodeCharRef = exports.getOwnedLabel = exports.accnameMayBeMutable = exports.checkAria = exports.checkAriaValue = exports.toNormalizedValue = exports.isValidAttr = exports.rePCENChar = exports.match = exports.attrMatches = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const ml_core_1 = require("@markuplint/ml-core");
4
7
  const html_entities_1 = require("html-entities");
5
8
  const attr_check_1 = require("./attr-check");
6
9
  function attrMatches(node, condition) {
7
10
  if (!condition) {
8
11
  return true;
9
12
  }
10
- let matched = false;
11
- if ('self' in condition && condition.self) {
12
- const condSelector = Array.isArray(condition.self) ? condition.self.join(',') : condition.self;
13
- matched = node.matches(condSelector);
14
- }
15
- if ('ancestor' in condition && condition.ancestor) {
16
- let _node = node.parentNode;
17
- while (_node) {
18
- if (_node.type === 'Element') {
19
- const condSelector = Array.isArray(condition.ancestor)
20
- ? condition.ancestor.join(',')
21
- : condition.ancestor;
22
- if (_node.matches(condSelector)) {
23
- matched = true;
24
- break;
25
- }
26
- }
27
- _node = _node.parentNode;
28
- }
29
- }
30
- return matched;
13
+ const condSelector = Array.isArray(condition) ? condition.join(',') : condition;
14
+ return node.matches(condSelector);
31
15
  }
32
16
  exports.attrMatches = attrMatches;
33
17
  function match(needle, pattern) {
@@ -75,11 +59,6 @@ exports.rePCENChar = [
75
59
  '[\uFDF0-\uFFFD]',
76
60
  '[\uD800-\uDBFF][\uDC00-\uDFFF]',
77
61
  ].join('|');
78
- function htmlSpec(specs, nameWithNS) {
79
- const spec = specs.specs.find(spec => spec.name === nameWithNS);
80
- return spec || null;
81
- }
82
- exports.htmlSpec = htmlSpec;
83
62
  function isValidAttr(t, name, value, isDynamicValue, node, attrSpecs, log) {
84
63
  let invalid = false;
85
64
  const spec = attrSpecs.find(s => s.name.toLowerCase() === name.toLowerCase());
@@ -126,126 +105,6 @@ function toNormalizedValue(value, spec) {
126
105
  return normalized;
127
106
  }
128
107
  exports.toNormalizedValue = toNormalizedValue;
129
- function ariaSpec(specs) {
130
- const roles = specs.def['#roles'];
131
- const ariaAttrs = specs.def['#ariaAttrs'];
132
- return {
133
- roles,
134
- ariaAttrs,
135
- };
136
- }
137
- exports.ariaSpec = ariaSpec;
138
- function getRoleSpec(specs, roleName) {
139
- const role = getRoleByName(specs, roleName);
140
- if (!role) {
141
- return null;
142
- }
143
- const superClassRoles = recursiveTraverseSuperClassRoles(specs, roleName);
144
- return {
145
- name: role.name,
146
- isAbstract: !!role.isAbstract,
147
- accessibleNameRequired: role.accessibleNameRequired,
148
- statesAndProps: role.ownedAttribute,
149
- superClassRoles,
150
- };
151
- }
152
- exports.getRoleSpec = getRoleSpec;
153
- function getRoleByName(specs, roleName) {
154
- const roles = specs.def['#roles'];
155
- const role = roles.find(r => r.name === roleName);
156
- return role;
157
- }
158
- function getSuperClassRoles(specs, roleName) {
159
- const role = getRoleByName(specs, roleName);
160
- return ((role === null || role === void 0 ? void 0 : role.generalization.map(roleName => getRoleByName(specs, roleName)).filter((role) => !!role)) || null);
161
- }
162
- function recursiveTraverseSuperClassRoles(specs, roleName) {
163
- const roles = [];
164
- const superClassRoles = getSuperClassRoles(specs, roleName);
165
- if (superClassRoles) {
166
- roles.push(...superClassRoles);
167
- for (const superClassRole of superClassRoles) {
168
- const ancestorRoles = recursiveTraverseSuperClassRoles(specs, superClassRole.name);
169
- roles.push(...ancestorRoles);
170
- }
171
- }
172
- return roles;
173
- }
174
- /**
175
- * Getting permitted ARIA roles.
176
- *
177
- * - If an array, it is role list.
178
- * - If `true`, this mean is "Any".
179
- * - If `false`, this mean is "No".
180
- */
181
- function getPermittedRoles(specs, el) {
182
- var _a;
183
- const implicitRole = getImplicitRole(specs, el);
184
- const spec = (_a = htmlSpec(specs, el.nodeName)) === null || _a === void 0 ? void 0 : _a.permittedRoles;
185
- if (!spec) {
186
- return true;
187
- }
188
- if (spec.conditions) {
189
- for (const { condition, roles } of spec.conditions) {
190
- if (el.matches(condition)) {
191
- return mergeRoleList(implicitRole, roles);
192
- }
193
- }
194
- }
195
- if (implicitRole && Array.isArray(spec.roles)) {
196
- return [implicitRole, ...spec.roles];
197
- }
198
- if (implicitRole && spec.roles === false) {
199
- return [implicitRole];
200
- }
201
- return mergeRoleList(implicitRole, spec.roles);
202
- }
203
- exports.getPermittedRoles = getPermittedRoles;
204
- function mergeRoleList(implicitRole, permittedRoles) {
205
- if (implicitRole && Array.isArray(permittedRoles)) {
206
- return [implicitRole, ...permittedRoles];
207
- }
208
- if (implicitRole && permittedRoles === false) {
209
- return [implicitRole];
210
- }
211
- return permittedRoles;
212
- }
213
- function getImplicitRole(specs, el) {
214
- var _a;
215
- const implicitRole = (_a = htmlSpec(specs, el.nodeName)) === null || _a === void 0 ? void 0 : _a.implicitRole;
216
- if (!implicitRole) {
217
- return false;
218
- }
219
- if (implicitRole.conditions) {
220
- for (const { condition, role } of implicitRole.conditions) {
221
- if (el.matches(condition)) {
222
- return role;
223
- }
224
- }
225
- }
226
- return implicitRole.role;
227
- }
228
- exports.getImplicitRole = getImplicitRole;
229
- function getComputedRole(specs, el) {
230
- const roleAttrTokens = el.getAttributeToken('role');
231
- const roleAttr = roleAttrTokens[0];
232
- if (roleAttr) {
233
- const roleName = roleAttr.getValue().potential.trim().toLowerCase();
234
- return {
235
- name: roleName,
236
- isImplicit: false,
237
- };
238
- }
239
- const implicitRole = getImplicitRole(specs, el);
240
- if (implicitRole) {
241
- return {
242
- name: implicitRole,
243
- isImplicit: true,
244
- };
245
- }
246
- return null;
247
- }
248
- exports.getComputedRole = getComputedRole;
249
108
  /**
250
109
  *
251
110
  * @see https://www.w3.org/TR/wai-aria-1.2/#propcharacteristic_value
@@ -288,8 +147,8 @@ function checkAriaValue(type, value, tokenEnum) {
288
147
  return true;
289
148
  }
290
149
  exports.checkAriaValue = checkAriaValue;
291
- function checkAria(specs, attrName, currentValue, role) {
292
- const ariaAttrs = specs.def['#ariaAttrs'];
150
+ function checkAria(specs, attrName, currentValue, version, role) {
151
+ const ariaAttrs = (0, ml_core_1.ariaSpecs)(specs, version).props;
293
152
  const aria = ariaAttrs.find(a => a.name === attrName);
294
153
  if (!aria) {
295
154
  return {
@@ -345,3 +204,24 @@ function decodeCharRef(characterReference) {
345
204
  return (0, html_entities_1.decode)(characterReference);
346
205
  }
347
206
  exports.decodeCharRef = decodeCharRef;
207
+ class Collection {
208
+ constructor(...items) {
209
+ _Collection_items.set(this, new Set());
210
+ this.add(...items);
211
+ }
212
+ add(...items) {
213
+ for (const item of items) {
214
+ if (item == null) {
215
+ continue;
216
+ }
217
+ tslib_1.__classPrivateFieldGet(this, _Collection_items, "f").add(item);
218
+ }
219
+ }
220
+ toArray() {
221
+ return Object.freeze(Array.from(tslib_1.__classPrivateFieldGet(this, _Collection_items, "f")));
222
+ }
223
+ [(_Collection_items = new WeakMap(), Symbol.iterator)]() {
224
+ return tslib_1.__classPrivateFieldGet(this, _Collection_items, "f").values();
225
+ }
226
+ }
227
+ exports.Collection = Collection;
@@ -8,13 +8,11 @@ exports.default = (0, ml_core_1.createRule)({
8
8
  await document.walkOn('Element', node => {
9
9
  const idAttrs = node.getAttributeToken('id');
10
10
  for (const idAttr of idAttrs) {
11
- if (idAttr.attrType === 'ps-attr' ||
12
- (idAttr.attrType === 'html-attr' && idAttr.isDynamicValue) ||
13
- (idAttr.attrType === 'html-attr' && idAttr.isDirective)) {
11
+ if (idAttr.isDynamicValue || idAttr.isDirective) {
14
12
  continue;
15
13
  }
16
- const id = idAttr.getValue();
17
- if (idStack.includes(id.raw)) {
14
+ const id = idAttr.value;
15
+ if (idStack.includes(id)) {
18
16
  report({
19
17
  scope: node,
20
18
  message,
@@ -23,7 +21,7 @@ exports.default = (0, ml_core_1.createRule)({
23
21
  raw: idAttr.raw,
24
22
  });
25
23
  }
26
- idStack.push(id.raw);
24
+ idStack.push(id);
27
25
  }
28
26
  });
29
27
  },
@@ -1,7 +1,7 @@
1
1
  export declare type Value = 'tab' | number;
2
2
  export interface IndentationOptions {
3
- alignment?: boolean;
4
- 'indent-nested-nodes'?: boolean | 'always' | 'never';
3
+ alignment?: boolean;
4
+ 'indent-nested-nodes'?: boolean | 'always' | 'never';
5
5
  }
6
- declare const _default: import("@markuplint/ml-core").RuleSeed<Value, IndentationOptions>;
6
+ declare const _default: import('@markuplint/ml-core').RuleSeed<Value, IndentationOptions>;
7
7
  export default _default;