@markuplint/ml-spec 3.0.0-alpha.2 → 3.0.0-alpha.27

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 (74) hide show
  1. package/README.md +8 -3
  2. package/lib/dom-traverse/get-computed-aria-props.d.ts +12 -0
  3. package/lib/dom-traverse/get-computed-aria-props.js +106 -0
  4. package/lib/dom-traverse/get-explicit-role.js +1 -1
  5. package/lib/dom-traverse/is-exposed.d.ts +11 -0
  6. package/lib/dom-traverse/is-exposed.js +181 -0
  7. package/lib/index.d.ts +5 -0
  8. package/lib/index.js +5 -0
  9. package/lib/specs/get-attr-specs.d.ts +1 -1
  10. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  11. package/lib/specs/is-nothing-content-model.js +12 -0
  12. package/lib/specs/is-palpable-elements.d.ts +5 -0
  13. package/lib/specs/is-palpable-elements.js +47 -0
  14. package/lib/specs/is-void-element.d.ts +1 -0
  15. package/lib/specs/is-void-element.js +25 -0
  16. package/lib/specs/schema-to-spec.d.ts +1 -1
  17. package/lib/specs/schema-to-spec.js +1 -1
  18. package/lib/types/aria.d.ts +3 -3
  19. package/lib/types/attributes.d.ts +2 -2
  20. package/lib/types/index.d.ts +21 -21
  21. package/lib/types/permitted-structres.d.ts +4 -4
  22. package/lib/types/permitted-structures.d.ts +4 -4
  23. package/lib/utils/merge-array.d.ts +1 -1
  24. package/lib/utils/resolve-namespace.d.ts +1 -1
  25. package/package.json +6 -6
  26. package/schemas/aria.schema.json +0 -258
  27. package/schemas/attributes.schema.json +0 -204
  28. package/schemas/content-models.schema.json +0 -200
  29. package/schemas/element.schema.json +0 -11
  30. package/schemas/global-attributes.schema.json +0 -761
  31. package/src/dom-traverse/accname-computation.spec.ts +0 -69
  32. package/src/dom-traverse/accname-computation.ts +0 -5
  33. package/src/dom-traverse/get-attr-specs.ts +0 -8
  34. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  35. package/src/dom-traverse/get-computed-role.ts +0 -181
  36. package/src/dom-traverse/get-content-model.ts +0 -32
  37. package/src/dom-traverse/get-explicit-role.ts +0 -112
  38. package/src/dom-traverse/get-implicit-role.ts +0 -36
  39. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  40. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  41. package/src/dom-traverse/get-spec.ts +0 -7
  42. package/src/dom-traverse/has-required-owned-elements.spec.ts +0 -36
  43. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  44. package/src/dom-traverse/may-be-focusable.ts +0 -21
  45. package/src/index.ts +0 -19
  46. package/src/specs/aria-specs.ts +0 -6
  47. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  48. package/src/specs/get-aria.ts +0 -85
  49. package/src/specs/get-attr-specs.spec.ts +0 -47
  50. package/src/specs/get-attr-specs.ts +0 -116
  51. package/src/specs/get-implicit-role.spec.ts +0 -81
  52. package/src/specs/get-implicit-role.ts +0 -17
  53. package/src/specs/get-permitted-roles.spec.ts +0 -420
  54. package/src/specs/get-permitted-roles.ts +0 -87
  55. package/src/specs/get-role-spec.spec.ts +0 -67
  56. package/src/specs/get-role-spec.ts +0 -72
  57. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  58. package/src/specs/get-spec-by-tag-name.spec.ts +0 -68
  59. package/src/specs/get-spec-by-tag-name.ts +0 -20
  60. package/src/specs/is-presentational.ts +0 -6
  61. package/src/specs/resolve-version.ts +0 -20
  62. package/src/specs/schema-to-spec.spec.ts +0 -39
  63. package/src/specs/schema-to-spec.ts +0 -103
  64. package/src/types/aria.ts +0 -153
  65. package/src/types/attributes.ts +0 -1473
  66. package/src/types/index.ts +0 -255
  67. package/src/types/permitted-structres.ts +0 -101
  68. package/src/types/permitted-structures.ts +0 -97
  69. package/src/utils/get-ns.ts +0 -18
  70. package/src/utils/merge-array.ts +0 -35
  71. package/src/utils/resolve-namespace.spec.ts +0 -37
  72. package/src/utils/resolve-namespace.ts +0 -40
  73. package/tsconfig.test.json +0 -3
  74. 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,6 +0,0 @@
1
- export function isPresentational(roleName?: string) {
2
- if (!roleName) {
3
- return false;
4
- }
5
- return ['presentation', 'none'].includes(roleName);
6
- }
@@ -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: ["@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
- }