@markuplint/ml-spec 3.0.0-dev.25 → 3.0.0-dev.38

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 (58) hide show
  1. package/lib/dom-traverse/is-exposed.js +8 -0
  2. package/package.json +4 -4
  3. package/schemas/aria.schema.json +0 -258
  4. package/schemas/attributes.schema.json +0 -204
  5. package/schemas/content-models.schema.json +0 -199
  6. package/schemas/element.schema.json +0 -11
  7. package/schemas/global-attributes.schema.json +0 -761
  8. package/src/dom-traverse/accname-computation.spec.ts +0 -69
  9. package/src/dom-traverse/accname-computation.ts +0 -5
  10. package/src/dom-traverse/get-attr-specs.ts +0 -8
  11. package/src/dom-traverse/get-computed-aria-props.spec.ts +0 -368
  12. package/src/dom-traverse/get-computed-aria-props.ts +0 -130
  13. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  14. package/src/dom-traverse/get-computed-role.ts +0 -181
  15. package/src/dom-traverse/get-content-model.ts +0 -32
  16. package/src/dom-traverse/get-explicit-role.ts +0 -112
  17. package/src/dom-traverse/get-implicit-role.ts +0 -36
  18. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  19. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  20. package/src/dom-traverse/get-spec.ts +0 -7
  21. package/src/dom-traverse/has-required-owned-elements.spec.ts +0 -36
  22. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  23. package/src/dom-traverse/is-exposed.spec.ts +0 -50
  24. package/src/dom-traverse/is-exposed.ts +0 -196
  25. package/src/dom-traverse/may-be-focusable.ts +0 -21
  26. package/src/index.ts +0 -24
  27. package/src/specs/aria-specs.ts +0 -6
  28. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  29. package/src/specs/get-aria.ts +0 -85
  30. package/src/specs/get-attr-specs.spec.ts +0 -47
  31. package/src/specs/get-attr-specs.ts +0 -116
  32. package/src/specs/get-implicit-role.spec.ts +0 -81
  33. package/src/specs/get-implicit-role.ts +0 -17
  34. package/src/specs/get-permitted-roles.spec.ts +0 -420
  35. package/src/specs/get-permitted-roles.ts +0 -87
  36. package/src/specs/get-role-spec.spec.ts +0 -67
  37. package/src/specs/get-role-spec.ts +0 -72
  38. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  39. package/src/specs/get-spec-by-tag-name.spec.ts +0 -68
  40. package/src/specs/get-spec-by-tag-name.ts +0 -20
  41. package/src/specs/is-nothing-content-model.ts +0 -9
  42. package/src/specs/is-palpable-elements.ts +0 -55
  43. package/src/specs/is-presentational.ts +0 -6
  44. package/src/specs/is-void-element.ts +0 -22
  45. package/src/specs/resolve-version.ts +0 -20
  46. package/src/specs/schema-to-spec.spec.ts +0 -39
  47. package/src/specs/schema-to-spec.ts +0 -103
  48. package/src/types/aria.ts +0 -153
  49. package/src/types/attributes.ts +0 -1524
  50. package/src/types/index.ts +0 -255
  51. package/src/types/permitted-structres.ts +0 -100
  52. package/src/types/permitted-structures.ts +0 -96
  53. package/src/utils/get-ns.ts +0 -18
  54. package/src/utils/merge-array.ts +0 -35
  55. package/src/utils/resolve-namespace.spec.ts +0 -37
  56. package/src/utils/resolve-namespace.ts +0 -40
  57. package/tsconfig.test.json +0 -3
  58. package/tsconfig.tsbuildinfo +0 -1
@@ -1,68 +0,0 @@
1
- import { specs } from '@markuplint/html-spec';
2
-
3
- import { getSpecByTagName } from './get-spec-by-tag-name';
4
-
5
- const divSpec = {
6
- conditional: [
7
- {
8
- condition: 'dl > div',
9
- contents: [
10
- {
11
- zeroOrMore: ':model(script-supporting)',
12
- },
13
- {
14
- oneOrMore: 'dt',
15
- },
16
- {
17
- zeroOrMore: ':model(script-supporting)',
18
- },
19
- {
20
- oneOrMore: 'dd',
21
- },
22
- {
23
- zeroOrMore: ':model(script-supporting)',
24
- },
25
- ],
26
- },
27
- ],
28
- contents: [
29
- {
30
- oneOrMore: ':model(flow)',
31
- },
32
- ],
33
- };
34
-
35
- test('html:div', () => {
36
- expect(getSpecByTagName(specs, 'div', null)?.contentModel).toStrictEqual(divSpec);
37
- expect(getSpecByTagName(specs, 'div', 'unknown-namespace')?.contentModel).toStrictEqual(divSpec);
38
- expect(getSpecByTagName(specs, 'div', 'http://www.w3.org/1999/xhtml')?.contentModel).toStrictEqual(divSpec);
39
- });
40
-
41
- test('svg:svg', () => {
42
- expect(getSpecByTagName(specs, 'svg', 'http://www.w3.org/2000/svg')?.contentModel).toStrictEqual({
43
- contents: [
44
- {
45
- zeroOrMore: [
46
- ':model(SVGAnimation)',
47
- ':model(SVGDescriptive)',
48
- ':model(SVGPaintServer)',
49
- ':model(SVGShape)',
50
- ':model(SVGStructural)',
51
- 'svg|a',
52
- 'svg|clipPath',
53
- 'svg|filter',
54
- 'svg|foreignObject',
55
- 'svg|image',
56
- 'svg|marker',
57
- 'svg|mask',
58
- 'svg|script',
59
- 'svg|style',
60
- 'svg|switch',
61
- 'svg|text',
62
- 'svg|view',
63
- ],
64
- },
65
- ],
66
- });
67
- expect(getSpecByTagName(specs, 'svg', null)).toBe(null);
68
- });
@@ -1,20 +0,0 @@
1
- import type { ElementSpec } from '../types';
2
-
3
- import { resolveNamespace } from '../utils/resolve-namespace';
4
-
5
- const cache = new Map<string, any>();
6
-
7
- export function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(
8
- specs: Readonly<Pick<ElementSpec, 'name' | K>[]>,
9
- localName: string,
10
- namespace: string | null,
11
- ) {
12
- const { localNameWithNS } = resolveNamespace(localName, namespace || undefined);
13
- let spec: Pick<ElementSpec, 'name' | K> | null | undefined = cache.get(localNameWithNS);
14
- if (spec !== undefined) {
15
- return spec;
16
- }
17
- spec = specs.find(spec => spec.name === localNameWithNS) || null;
18
- cache.set(localNameWithNS, spec);
19
- return spec;
20
- }
@@ -1,9 +0,0 @@
1
- import { isVoidElement } from './is-void-element';
2
-
3
- /**
4
- * @see https://html.spec.whatwg.org/multipage/dom.html#the-nothing-content-model
5
- * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
6
- */
7
- export function isNothingContentModel(el: Element) {
8
- return isVoidElement(el) || ['iframe', 'template'].includes(el.localName);
9
- }
@@ -1,55 +0,0 @@
1
- import type { MLMLSpec } from '../types';
2
-
3
- /**
4
- * Exposable content models and elements
5
- *
6
- * **WARNING**:
7
- * This implementation is through the author's interpretation.
8
- * Want a issue request.
9
- * https://github.com/markuplint/markuplint/issues/new
10
- *
11
- * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
12
- */
13
- const exposableElementsThatAreNoBelongingAModel: string[] = [
14
- 'body',
15
- 'dd',
16
- 'dt',
17
- 'figcaption',
18
- 'html',
19
- 'legend',
20
- 'li',
21
- 'optgroup',
22
- 'option',
23
- 'rp',
24
- 'rt',
25
- 'summary',
26
- 'tbody',
27
- 'td',
28
- 'tfoot',
29
- 'th',
30
- 'thead',
31
- 'tr',
32
- ];
33
-
34
- export function isPalpableElement(
35
- el: Element,
36
- specs: Readonly<MLMLSpec>,
37
- options?: {
38
- extendsSvg?: boolean;
39
- extendsExposableElements?: boolean;
40
- },
41
- ) {
42
- const conditions = [specs.def['#contentModels']['#palpable']?.join(',') || ''];
43
-
44
- if (options?.extendsSvg !== false /* default true */) {
45
- conditions.push(specs.def['#contentModels']['#SVGRenderable']?.join(',') || '');
46
- }
47
-
48
- if (options?.extendsExposableElements /* default false */) {
49
- conditions.push(exposableElementsThatAreNoBelongingAModel.join(','));
50
- }
51
-
52
- return conditions.some(condition => {
53
- return el.matches(condition);
54
- });
55
- }
@@ -1,6 +0,0 @@
1
- export function isPresentational(roleName?: string) {
2
- if (!roleName) {
3
- return false;
4
- }
5
- return ['presentation', 'none'].includes(roleName);
6
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * @see https://html.spec.whatwg.org/multipage/syntax.html#void-elements
3
- */
4
- const voidElements = [
5
- 'area',
6
- 'base',
7
- 'br',
8
- 'col',
9
- 'embed',
10
- 'hr',
11
- 'img',
12
- 'input',
13
- 'link',
14
- 'meta',
15
- 'source',
16
- 'track',
17
- 'wbr',
18
- ];
19
-
20
- export function isVoidElement(el: Element) {
21
- return voidElements.includes(el.localName);
22
- }
@@ -1,20 +0,0 @@
1
- import type { ARIAVersion } from '../types';
2
- import type { ARIA } from '../types/aria';
3
-
4
- export function resolveVersion(aria: ARIA, version: ARIAVersion): Omit<ARIA, ARIAVersion> {
5
- const implicitRole = aria[version]?.implicitRole ?? aria.implicitRole;
6
- const permittedRoles = aria[version]?.permittedRoles ?? aria.permittedRoles;
7
- const implicitProperties = aria[version]?.implicitProperties ?? aria.implicitProperties;
8
- const properties = aria[version]?.properties ?? aria.properties;
9
- const namingProhibited =
10
- version === '1.2' ? aria[version]?.namingProhibited ?? aria.namingProhibited : aria.namingProhibited;
11
- const conditions = aria[version]?.conditions ?? aria.conditions;
12
- return {
13
- implicitRole,
14
- permittedRoles,
15
- implicitProperties,
16
- properties,
17
- namingProhibited,
18
- conditions,
19
- };
20
- }
@@ -1,39 +0,0 @@
1
- import htmlSpec from '@markuplint/html-spec';
2
-
3
- import { schemaToSpec } from './schema-to-spec';
4
-
5
- describe('getSpec', () => {
6
- test('Overriding', () => {
7
- const exAttr = {
8
- ref: 'N/A',
9
- type: 'Boolean',
10
- description: 'For the unit test.',
11
- } as const;
12
- const exAttr2 = {
13
- ref: 'N/A',
14
- type: 'Boolean',
15
- description: 'For the unit test. Override.',
16
- } as const;
17
- const mergedSpec = schemaToSpec([
18
- htmlSpec,
19
- {
20
- specs: [
21
- {
22
- name: 'a',
23
- attributes: { 'extended-attr': exAttr },
24
- },
25
- ],
26
- },
27
- {
28
- specs: [
29
- {
30
- name: 'a',
31
- attributes: { 'extended-attr': exAttr2 },
32
- },
33
- ],
34
- },
35
- ]);
36
- const aElAttrs = mergedSpec.specs.find(el => el.name === 'a')!.attributes;
37
- expect(aElAttrs['extended-attr']).toStrictEqual(exAttr2);
38
- });
39
- });
@@ -1,103 +0,0 @@
1
- import type { ElementSpec, ExtendedSpec, MLMLSpec, Attribute } from '../types';
2
-
3
- import { mergeArray } from '../utils/merge-array';
4
-
5
- /**
6
- * Merging HTML-spec schema and extended spec schemas
7
- *
8
- * Ex: `@markuplint/html-spec` + `{ specs: { "\\.vue$": "@markuplint/vue-spec" } }` in configure files.
9
- *
10
- * @param schemas `MLDocument.schemas`
11
- */
12
- export function schemaToSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]) {
13
- const [main, ...extendedSpecs] = schemas;
14
- const result = { ...main };
15
- for (const extendedSpec of extendedSpecs) {
16
- if (extendedSpec.cites) {
17
- result.cites = [...result.cites, ...extendedSpec.cites];
18
- }
19
- if (extendedSpec.def) {
20
- if (extendedSpec.def['#globalAttrs']?.['#extends']) {
21
- result.def['#globalAttrs']['#HTMLGlobalAttrs'] = {
22
- ...(result.def['#globalAttrs']?.['#HTMLGlobalAttrs'] || {}),
23
- ...(extendedSpec.def['#globalAttrs']?.['#extends'] || {}),
24
- };
25
- }
26
- if (extendedSpec.def['#aria']) {
27
- result.def['#aria'] = {
28
- '1.1': {
29
- roles: mergeArray(result.def['#aria']['1.1'].roles, extendedSpec.def['#aria']['1.1'].roles),
30
- props: mergeArray(result.def['#aria']['1.1'].props, extendedSpec.def['#aria']['1.1'].props),
31
- graphicsRoles: mergeArray(
32
- result.def['#aria']['1.1'].graphicsRoles,
33
- extendedSpec.def['#aria']['1.1'].graphicsRoles,
34
- ),
35
- },
36
- '1.2': {
37
- roles: mergeArray(result.def['#aria']['1.2'].roles, extendedSpec.def['#aria']['1.2'].roles),
38
- props: mergeArray(result.def['#aria']['1.2'].props, extendedSpec.def['#aria']['1.2'].props),
39
- graphicsRoles: mergeArray(
40
- result.def['#aria']['1.2'].graphicsRoles,
41
- extendedSpec.def['#aria']['1.2'].graphicsRoles,
42
- ),
43
- },
44
- };
45
- }
46
- if (extendedSpec.def['#contentModels']) {
47
- const keys = new Set([
48
- ...Object.keys(result.def['#contentModels']),
49
- ...Object.keys(extendedSpec.def['#contentModels']),
50
- ]) as Set<keyof typeof result.def['#contentModels']>;
51
- for (const modelName of keys) {
52
- const mainModel = result.def['#contentModels'][modelName];
53
- const exModel = extendedSpec.def['#contentModels'][modelName];
54
- result.def['#contentModels'][modelName] = [...(mainModel || []), ...(exModel || [])];
55
- }
56
- }
57
- }
58
- if (extendedSpec.specs) {
59
- const exSpecs = extendedSpec.specs.slice();
60
- const specs: ElementSpec[] = [];
61
- for (const elSpec of result.specs) {
62
- const tagName = elSpec.name.toLowerCase();
63
- const index = exSpecs.findIndex(spec => spec.name.toLowerCase() === tagName);
64
- if (index === -1) {
65
- specs.push(elSpec);
66
- continue;
67
- }
68
- const exSpec = exSpecs.splice(index, 1)[0];
69
- specs.push({
70
- ...elSpec,
71
- ...exSpec,
72
- globalAttrs: {
73
- ...elSpec.globalAttrs,
74
- ...exSpec.globalAttrs,
75
- },
76
- attributes: mergeAttrSpec(elSpec.attributes, exSpec.attributes),
77
- categories: mergeArray(elSpec.categories, exSpec.categories),
78
- });
79
- }
80
-
81
- result.specs = specs;
82
- }
83
- }
84
-
85
- return result;
86
- }
87
-
88
- function mergeAttrSpec(
89
- std: Record<string, Attribute>,
90
- ex: Record<string, Partial<Attribute>> = {},
91
- ): Record<string, Attribute> {
92
- const result: Record<string, Attribute> = {};
93
- const keys = Array.from(new Set([...Object.keys(std), ...Object.keys(ex)]));
94
- for (const key of keys) {
95
- const _std = std[key];
96
- const _ex = ex[key];
97
- result[key] = {
98
- ..._std,
99
- ..._ex,
100
- };
101
- }
102
- return result;
103
- }
package/src/types/aria.ts DELETED
@@ -1,153 +0,0 @@
1
- /* tslint:disable */
2
- /**
3
- * This file was automatically generated by json-schema-to-typescript.
4
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
- * and run json-schema-to-typescript to regenerate this file.
6
- */
7
-
8
- /**
9
- * If `false`, this mean is "No corresponding role".
10
- */
11
- export type ImplicitRole = false | string;
12
- /**
13
- * If `true`, this mean is "Any". If `false`, this mean is "No".
14
- */
15
- export type PermittedRoles =
16
- | boolean
17
- | (
18
- | string
19
- | {
20
- name: string;
21
- deprecated?: true;
22
- [k: string]: unknown;
23
- }
24
- )[]
25
- | {
26
- 'core-aam'?: true;
27
- 'graphics-aam'?: true;
28
- };
29
- /**
30
- * If set false:
31
- * > No role or aria-* attributes
32
- */
33
- export type PermittedARIAProperties =
34
- | false
35
- | {
36
- global?: true;
37
- /**
38
- * Set true if the spec says "and any aria-* attributes applicable to the allowed roles."
39
- */
40
- role?: true | string | [string, ...string[]];
41
- /**
42
- * @minItems 1
43
- */
44
- only?: [
45
- (
46
- | string
47
- | {
48
- name: string;
49
- value?: string;
50
- }
51
- ),
52
- ...(
53
- | string
54
- | {
55
- name: string;
56
- value?: string;
57
- }
58
- )[],
59
- ];
60
- /**
61
- * @minItems 1
62
- */
63
- without?: [
64
- {
65
- type: 'not-recommended' | 'should-not' | 'must-not';
66
- name: string;
67
- value?: string;
68
- alt?: {
69
- method: 'remove-attr' | 'set-attr';
70
- target: string;
71
- };
72
- },
73
- ...{
74
- type: 'not-recommended' | 'should-not' | 'must-not';
75
- name: string;
76
- value?: string;
77
- alt?: {
78
- method: 'remove-attr' | 'set-attr';
79
- target: string;
80
- };
81
- }[],
82
- ];
83
- };
84
-
85
- export interface AriaSchema {
86
- _?: ARIA;
87
- [k: string]: unknown;
88
- }
89
- export interface ARIA {
90
- implicitRole: ImplicitRole;
91
- permittedRoles: PermittedRoles;
92
- namingProhibited?: true;
93
- implicitProperties?: ImplicitProperties;
94
- properties?: PermittedARIAProperties;
95
- conditions?: {
96
- /**
97
- * This interface was referenced by `undefined`'s JSON-Schema definition
98
- * via the `patternProperty` ".+".
99
- */
100
- [k: string]: {
101
- implicitRole?: ImplicitRole;
102
- permittedRoles?: PermittedRoles;
103
- namingProhibited?: true;
104
- implicitProperties?: ImplicitProperties;
105
- properties?: PermittedARIAProperties;
106
- };
107
- };
108
- '1.2'?: {
109
- implicitRole?: ImplicitRole;
110
- permittedRoles?: PermittedRoles;
111
- namingProhibited?: true;
112
- implicitProperties?: ImplicitProperties;
113
- properties?: PermittedARIAProperties;
114
- conditions?: {
115
- /**
116
- * This interface was referenced by `undefined`'s JSON-Schema definition
117
- * via the `patternProperty` ".+".
118
- */
119
- [k: string]: {
120
- implicitRole?: ImplicitRole;
121
- permittedRoles?: PermittedRoles;
122
- namingProhibited?: true;
123
- implicitProperties?: ImplicitProperties;
124
- properties?: PermittedARIAProperties;
125
- };
126
- };
127
- };
128
- '1.1'?: {
129
- implicitRole?: ImplicitRole;
130
- permittedRoles?: PermittedRoles;
131
- implicitProperties?: ImplicitProperties;
132
- properties?: PermittedARIAProperties;
133
- conditions?: {
134
- /**
135
- * This interface was referenced by `undefined`'s JSON-Schema definition
136
- * via the `patternProperty` ".+".
137
- */
138
- [k: string]: {
139
- implicitRole?: ImplicitRole;
140
- permittedRoles?: PermittedRoles;
141
- implicitProperties?: ImplicitProperties;
142
- properties?: PermittedARIAProperties;
143
- };
144
- };
145
- };
146
- }
147
- export interface ImplicitProperties {
148
- /**
149
- * This interface was referenced by `ImplicitProperties`'s JSON-Schema definition
150
- * via the `patternProperty` "^aria-.+".
151
- */
152
- [k: string]: string;
153
- }