@markuplint/ml-spec 3.9.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.
Files changed (32) hide show
  1. package/lib/constant/aria-version.d.ts +2 -2
  2. package/lib/dom-traverse/get-attr-specs.d.ts +1 -1
  3. package/lib/dom-traverse/get-computed-aria-props.d.ts +5 -5
  4. package/lib/dom-traverse/get-computed-role.d.ts +1 -6
  5. package/lib/dom-traverse/get-computed-role.js +49 -3
  6. package/lib/dom-traverse/get-content-model.d.ts +1 -26
  7. package/lib/dom-traverse/get-implicit-role.d.ts +1 -5
  8. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +4 -10
  9. package/lib/dom-traverse/get-permitted-roles.d.ts +3 -7
  10. package/lib/dom-traverse/get-spec.d.ts +1 -4
  11. package/lib/dom-traverse/has-required-owned-elements.d.ts +1 -7
  12. package/lib/dom-traverse/matches-context-role.d.ts +1 -6
  13. package/lib/specs/aria-specs.d.ts +4 -7
  14. package/lib/specs/content-model-category-to-tag-names.d.ts +1 -4
  15. package/lib/specs/get-aria.d.ts +1 -7
  16. package/lib/specs/get-attr-specs.d.ts +2 -6
  17. package/lib/specs/get-implicit-role.d.ts +1 -7
  18. package/lib/specs/get-permitted-roles.d.ts +3 -9
  19. package/lib/specs/get-role-spec.d.ts +3 -10
  20. package/lib/specs/get-spec-by-tag-name.d.ts +1 -5
  21. package/lib/specs/is-palpable-elements.d.ts +4 -8
  22. package/lib/specs/resolve-version.d.ts +1 -4
  23. package/lib/specs/schema-to-spec.d.ts +3 -3
  24. package/lib/types/aria.d.ts +133 -147
  25. package/lib/types/attributes.d.ts +110 -1490
  26. package/lib/types/index.d.ts +145 -173
  27. package/lib/types/permitted-structures.d.ts +35 -74
  28. package/lib/utils/merge-array.d.ts +4 -9
  29. package/lib/utils/resolve-namespace.d.ts +4 -4
  30. package/package.json +9 -9
  31. package/test/dom-traverse/get-computed-aria-props.spec.js +2 -2
  32. package/test/dom-traverse/get-computed-role.spec.js +25 -4
@@ -1,2 +1,2 @@
1
- export declare const ariaVersions: readonly ['1.1', '1.2', '1.3'];
2
- export declare const ARIA_RECOMMENDED_VERSION: '1.2';
1
+ export declare const ariaVersions: readonly ["1.1", "1.2", "1.3"];
2
+ export declare const ARIA_RECOMMENDED_VERSION: "1.2";
@@ -1,2 +1,2 @@
1
1
  import type { MLMLSpec } from '../types';
2
- export declare function getAttrSpecs(el: Element, schema: MLMLSpec): readonly import('../types').Attribute[] | null;
2
+ export declare function getAttrSpecs(el: Element, schema: MLMLSpec): readonly import("../types").Attribute[] | null;
@@ -1,11 +1,11 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
2
  type ARIAProps = Record<string, ARIAProp>;
3
3
  type ARIAProp = {
4
- name: string;
5
- value: string | undefined;
6
- required: boolean;
7
- deprecated: boolean;
8
- from: ARIAPropReferenceType;
4
+ name: string;
5
+ value: string | undefined;
6
+ required: boolean;
7
+ deprecated: boolean;
8
+ from: ARIAPropReferenceType;
9
9
  };
10
10
  type ARIAPropReferenceType = 'default' | 'html-attr' | 'aria-attr';
11
11
  export declare function getComputedAriaProps(specs: MLMLSpec, el: Element, version: ARIAVersion): ARIAProps;
@@ -1,7 +1,2 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
- export declare function getComputedRole(
3
- specs: MLMLSpec,
4
- el: Element,
5
- version: ARIAVersion,
6
- assumeSingleNode?: boolean,
7
- ): ComputedRole;
2
+ export declare function getComputedRole(specs: MLMLSpec, el: Element, version: ARIAVersion, assumeSingleNode?: boolean): ComputedRole;
@@ -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',
@@ -1,29 +1,4 @@
1
1
  import type { ElementSpec } from '../types';
2
2
  type Specs = readonly Pick<ElementSpec, 'name' | 'contentModel'>[];
3
- export declare function getContentModel(
4
- el: Element,
5
- specs: Specs,
6
- ):
7
- | boolean
8
- | readonly (
9
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
10
- import('../types/permitted-structures').PermittedContentRequire
11
- >
12
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
13
- import('../types/permitted-structures').PermittedContentOptional
14
- >
15
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
16
- import('../types/permitted-structures').PermittedContentOneOrMore
17
- >
18
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
19
- import('../types/permitted-structures').PermittedContentZeroOrMore
20
- >
21
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
22
- import('../types/permitted-structures').PermittedContentChoice
23
- >
24
- | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
25
- import('../types/permitted-structures').PermittedContentTransparent
26
- >
27
- )[]
28
- | null;
3
+ export declare function getContentModel(el: Element, specs: Specs): boolean | readonly (import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentRequire> | import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentOptional> | import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentOneOrMore> | import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentZeroOrMore> | import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentChoice> | import("type-fest/source/readonly-deep").ReadonlyObjectDeep<import("../types/permitted-structures").PermittedContentTransparent>)[] | null;
29
4
  export {};
@@ -1,7 +1,3 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
2
  export declare function getImplicitRole(specs: MLMLSpec, el: Element, version: ARIAVersion): ComputedRole;
3
- export declare function getImplicitRoleName(
4
- el: Element,
5
- version: ARIAVersion,
6
- specs: MLMLSpec,
7
- ): import('..').ImplicitRole;
3
+ export declare function getImplicitRoleName(el: Element, version: ARIAVersion, specs: MLMLSpec): import("..").ImplicitRole;
@@ -1,11 +1,5 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
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
- };
2
+ export declare function getNonPresentationalAncestor(el: Element, specs: MLMLSpec, version: ARIAVersion): import("../types").ComputedRole | {
3
+ el: null;
4
+ role: null;
5
+ };
@@ -1,9 +1,5 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
- export declare function getPermittedRoles(
3
- el: Element,
4
- version: ARIAVersion,
5
- specs: MLMLSpec,
6
- ): readonly {
7
- readonly name: string;
8
- readonly deprecated?: boolean | undefined;
2
+ export declare function getPermittedRoles(el: Element, version: ARIAVersion, specs: MLMLSpec): readonly {
3
+ readonly name: string;
4
+ readonly deprecated?: boolean | undefined;
9
5
  }[];
@@ -1,5 +1,2 @@
1
1
  import type { ElementSpec } from '../types';
2
- export declare function getSpec<K extends keyof ElementSpec>(
3
- el: Element,
4
- specs: readonly Pick<ElementSpec, 'name' | K>[],
5
- ): Pick<ElementSpec, 'name' | K> | null;
2
+ export declare function getSpec<K extends keyof ElementSpec>(el: Element, specs: readonly Pick<ElementSpec, 'name' | K>[]): Pick<ElementSpec, "name" | K> | null;
@@ -1,9 +1,3 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
2
  export declare function hasRequiredOwnedElement(el: Element, specs: MLMLSpec, version: ARIAVersion): boolean;
3
- export declare function isRequiredOwnedElement(
4
- el: Element,
5
- role: ComputedRole['role'],
6
- query: string,
7
- specs: MLMLSpec,
8
- version: ARIAVersion,
9
- ): boolean;
3
+ export declare function isRequiredOwnedElement(el: Element, role: ComputedRole['role'], query: string, specs: MLMLSpec, version: ARIAVersion): boolean;
@@ -1,7 +1,2 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
- export declare function matchesContextRole(
3
- conditions: readonly string[],
4
- ownedEl: Element,
5
- specs: MLMLSpec,
6
- version: ARIAVersion,
7
- ): boolean;
2
+ export declare function matchesContextRole(conditions: readonly string[], ownedEl: Element, specs: MLMLSpec, version: ARIAVersion): boolean;
@@ -1,9 +1,6 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
- export declare function ariaSpecs(
3
- specs: MLMLSpec,
4
- version: ARIAVersion,
5
- ): {
6
- readonly roles: readonly import('../types').ARIARoleInSchema[];
7
- readonly graphicsRoles: readonly import('../types').ARIARoleInSchema[];
8
- readonly props: readonly import('../types').ARIAProperty[];
2
+ export declare function ariaSpecs(specs: MLMLSpec, version: ARIAVersion): {
3
+ readonly roles: readonly import("../types").ARIARoleInSchema[];
4
+ readonly graphicsRoles: readonly import("../types").ARIARoleInSchema[];
5
+ readonly props: readonly import("../types").ARIAProperty[];
9
6
  };
@@ -1,6 +1,3 @@
1
1
  import type { MLMLSpec } from '../types';
2
2
  import type { Category } from '../types/permitted-structures';
3
- export declare function contentModelCategoryToTagNames(
4
- contentModel: Category,
5
- def: MLMLSpec['def'],
6
- ): ReadonlyArray<string>;
3
+ export declare function contentModelCategoryToTagNames(contentModel: Category, def: MLMLSpec['def']): ReadonlyArray<string>;
@@ -1,10 +1,4 @@
1
1
  import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
2
  import type { ARIA } from '../types/aria';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
- export declare function getARIA(
5
- specs: MLMLSpec,
6
- localName: string,
7
- namespace: string | null,
8
- version: ARIAVersion,
9
- matches: Matches,
10
- ): Omit<ReadonlyDeep<ARIA>, ARIAVersion | 'conditions'> | null;
4
+ export declare function getARIA(specs: MLMLSpec, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): Omit<ReadonlyDeep<ARIA>, ARIAVersion | 'conditions'> | null;
@@ -1,12 +1,8 @@
1
1
  import type { MLMLSpec, Attribute } from '../types';
2
2
  import type { NamespaceURI } from '@markuplint/ml-ast';
3
- export declare function getAttrSpecs(
4
- localName: string,
5
- namespace: NamespaceURI | null,
6
- schema: MLMLSpec,
7
- ): readonly Attribute[] | null;
3
+ export declare function getAttrSpecs(localName: string, namespace: NamespaceURI | null, schema: MLMLSpec): readonly Attribute[] | null;
8
4
  type HasName = {
9
- readonly name: string;
5
+ readonly name: string;
10
6
  };
11
7
  export declare function nameCompare(a: HasName | string, b: HasName | string): 1 | -1 | 0;
12
8
  export {};
@@ -1,8 +1,2 @@
1
1
  import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
- export declare function getImplicitRole(
3
- specs: MLMLSpec,
4
- localName: string,
5
- namespace: string | null,
6
- version: ARIAVersion,
7
- matches: Matches,
8
- ): import('..').ImplicitRole;
2
+ export declare function getImplicitRole(specs: MLMLSpec, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): import("..").ImplicitRole;
@@ -6,13 +6,7 @@ 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
- specs: MLMLSpec,
11
- localName: string,
12
- namespace: string | null,
13
- version: ARIAVersion,
14
- matches: Matches,
15
- ): readonly {
16
- readonly name: string;
17
- readonly deprecated?: boolean;
9
+ export declare function getPermittedRoles(specs: MLMLSpec, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): readonly {
10
+ readonly name: string;
11
+ readonly deprecated?: boolean;
18
12
  }[];
@@ -1,12 +1,5 @@
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
- specs: MLMLSpec,
5
- roleName: string,
6
- namespace: NamespaceURI,
7
- version: ARIAVersion,
8
- ):
9
- | (ARIARole & {
10
- superClassRoles: ARIARoleInSchema[];
11
- })
12
- | null;
3
+ export declare function getRoleSpec(specs: MLMLSpec, roleName: string, namespace: NamespaceURI, version: ARIAVersion): (ARIARole & {
4
+ superClassRoles: ARIARoleInSchema[];
5
+ }) | null;
@@ -1,6 +1,2 @@
1
1
  import type { ElementSpec } from '../types';
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;
2
+ export declare function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(specs: readonly Pick<ElementSpec, 'name' | K>[], localName: string, namespace: string | null): Pick<ElementSpec, "name" | K> | null;
@@ -1,9 +1,5 @@
1
1
  import type { MLMLSpec } from '../types';
2
- export declare function isPalpableElement(
3
- el: Element,
4
- specs: MLMLSpec,
5
- options?: {
6
- readonly extendsSvg?: boolean;
7
- readonly extendsExposableElements?: boolean;
8
- },
9
- ): boolean;
2
+ export declare function isPalpableElement(el: Element, specs: MLMLSpec, options?: {
3
+ readonly extendsSvg?: boolean;
4
+ readonly extendsExposableElements?: boolean;
5
+ }): boolean;
@@ -1,7 +1,4 @@
1
1
  import type { ARIAVersion } from '../types';
2
2
  import type { ARIA } from '../types/aria';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
- export declare function resolveVersion(
5
- aria: ReadonlyDeep<ARIA>,
6
- version: ARIAVersion,
7
- ): Omit<ReadonlyDeep<ARIA>, ARIAVersion>;
4
+ export declare function resolveVersion(aria: ReadonlyDeep<ARIA>, version: ARIAVersion): Omit<ReadonlyDeep<ARIA>, ARIAVersion>;
@@ -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
- cites: import('../types').Cites;
11
- def: import('../types').SpecDefs;
12
- specs: readonly ElementSpec[];
10
+ cites: import("../types").Cites;
11
+ def: import("../types").SpecDefs;
12
+ specs: readonly ElementSpec[];
13
13
  };