@markuplint/ml-spec 3.4.0 → 3.6.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 (49) hide show
  1. package/lib/dom-traverse/accname-computation.js +3 -1
  2. package/lib/dom-traverse/get-attr-specs.d.ts +1 -1
  3. package/lib/dom-traverse/get-attr-specs.js +3 -1
  4. package/lib/dom-traverse/get-computed-aria-props.d.ts +1 -1
  5. package/lib/dom-traverse/get-computed-aria-props.js +4 -2
  6. package/lib/dom-traverse/get-computed-role.d.ts +1 -1
  7. package/lib/dom-traverse/get-computed-role.js +15 -9
  8. package/lib/dom-traverse/get-content-model.d.ts +26 -3
  9. package/lib/dom-traverse/get-content-model.js +4 -2
  10. package/lib/dom-traverse/get-explicit-role.js +8 -3
  11. package/lib/dom-traverse/get-implicit-role.d.ts +2 -2
  12. package/lib/dom-traverse/get-implicit-role.js +6 -2
  13. package/lib/dom-traverse/get-non-presentational-ancestor.js +3 -1
  14. package/lib/dom-traverse/get-permitted-roles.d.ts +3 -7
  15. package/lib/dom-traverse/get-permitted-roles.js +3 -1
  16. package/lib/dom-traverse/get-spec.d.ts +1 -1
  17. package/lib/dom-traverse/get-spec.js +3 -1
  18. package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -2
  19. package/lib/dom-traverse/has-required-owned-elements.js +14 -8
  20. package/lib/dom-traverse/is-exposed.d.ts +1 -1
  21. package/lib/dom-traverse/is-exposed.js +21 -8
  22. package/lib/dom-traverse/may-be-focusable.d.ts +1 -1
  23. package/lib/dom-traverse/may-be-focusable.js +3 -1
  24. package/lib/specs/aria-specs.d.ts +4 -4
  25. package/lib/specs/get-aria.d.ts +2 -7
  26. package/lib/specs/get-aria.js +5 -2
  27. package/lib/specs/get-attr-specs.d.ts +2 -2
  28. package/lib/specs/get-attr-specs.js +2 -14
  29. package/lib/specs/get-implicit-role.d.ts +1 -1
  30. package/lib/specs/get-permitted-roles.d.ts +3 -9
  31. package/lib/specs/get-permitted-roles.js +19 -15
  32. package/lib/specs/get-role-spec.d.ts +1 -1
  33. package/lib/specs/get-role-spec.js +2 -2
  34. package/lib/specs/get-selectors-by-content-model-category.d.ts +1 -4
  35. package/lib/specs/get-selectors-by-content-model-category.js +1 -1
  36. package/lib/specs/get-spec-by-tag-name.d.ts +1 -1
  37. package/lib/specs/get-spec-by-tag-name.js +3 -2
  38. package/lib/specs/is-nothing-content-model.js +3 -1
  39. package/lib/specs/is-palpable-elements.d.ts +3 -3
  40. package/lib/specs/is-palpable-elements.js +6 -4
  41. package/lib/specs/is-void-element.js +3 -1
  42. package/lib/specs/resolve-version.d.ts +5 -1
  43. package/lib/specs/schema-to-spec.d.ts +1 -1
  44. package/lib/specs/schema-to-spec.js +20 -14
  45. package/lib/types/aria.d.ts +5 -4
  46. package/lib/types/index.d.ts +87 -88
  47. package/lib/utils/merge-array.d.ts +5 -2
  48. package/lib/utils/resolve-namespace.js +1 -1
  49. package/package.json +8 -6
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPermittedRoles = void 0;
4
+ const is_plain_object_1 = require("is-plain-object");
4
5
  const merge_array_1 = require("../utils/merge-array");
5
6
  const aria_specs_1 = require("./aria-specs");
6
7
  const get_aria_1 = require("./get-aria");
@@ -26,17 +27,7 @@ function getPermittedRoles(specs, localName, namespace, version, matches) {
26
27
  name: role.name,
27
28
  })));
28
29
  }
29
- if (Array.isArray(permittedRoles)) {
30
- permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, permittedRoles.map(role => {
31
- if (typeof role === 'string') {
32
- return {
33
- name: role,
34
- };
35
- }
36
- return role;
37
- }));
38
- }
39
- else if (!(typeof permittedRoles === 'boolean')) {
30
+ if (isAAMInfo(permittedRoles)) {
40
31
  if (permittedRoles['core-aam']) {
41
32
  permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, roles
42
33
  .filter(role => !role.isAbstract)
@@ -52,10 +43,23 @@ function getPermittedRoles(specs, localName, namespace, version, matches) {
52
43
  })));
53
44
  }
54
45
  }
55
- if (implicitRole) {
56
- const implicitRoles = implicitRole === 'presentation' || implicitRole === 'none' ? ['none', 'presentation'] : [implicitRole];
57
- return (0, merge_array_1.mergeArray)(implicitRoles.map(r => ({ name: r })), permittedRoleList);
46
+ else if (typeof permittedRoles !== 'boolean') {
47
+ permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, permittedRoles.map(role => {
48
+ if (typeof role === 'string') {
49
+ return {
50
+ name: role,
51
+ };
52
+ }
53
+ return role;
54
+ }));
58
55
  }
59
- return permittedRoleList;
56
+ if (implicitRole === false) {
57
+ return permittedRoleList;
58
+ }
59
+ const implicitRoles = implicitRole === 'presentation' || implicitRole === 'none' ? ['none', 'presentation'] : [implicitRole];
60
+ return (0, merge_array_1.mergeArray)(implicitRoles.map(r => ({ name: r })), permittedRoleList);
60
61
  }
61
62
  exports.getPermittedRoles = getPermittedRoles;
63
+ function isAAMInfo(permittedRoles) {
64
+ return (0, is_plain_object_1.isPlainObject)(permittedRoles);
65
+ }
@@ -1,7 +1,7 @@
1
1
  import type { ARIAVersion, ARIARoleInSchema, MLMLSpec, ARIARole } from '../types';
2
2
  import type { NamespaceURI } from '@markuplint/ml-ast';
3
3
  export declare function getRoleSpec(
4
- specs: Readonly<MLMLSpec>,
4
+ specs: MLMLSpec,
5
5
  roleName: string,
6
6
  namespace: NamespaceURI,
7
7
  version: ARIAVersion,
@@ -38,9 +38,9 @@ function recursiveTraverseSuperClassRoles(specs, roleName, namespace, version) {
38
38
  return roles;
39
39
  }
40
40
  function getSuperClassRoles(specs, roleName, namespace, version) {
41
- var _a;
41
+ var _a, _b;
42
42
  const role = getRoleByName(specs, roleName, namespace, version);
43
- return (((_a = role === null || role === void 0 ? void 0 : role.generalization) === null || _a === void 0 ? void 0 : _a.map(roleName => getRoleByName(specs, roleName, namespace, version)).filter((role) => !!role)) || null);
43
+ return ((_b = (_a = role === null || role === void 0 ? void 0 : role.generalization) === null || _a === void 0 ? void 0 : _a.map(roleName => getRoleByName(specs, roleName, namespace, version)).filter((role) => !!role)) !== null && _b !== void 0 ? _b : null);
44
44
  }
45
45
  function getRoleByName(specs, roleName, namespace, version) {
46
46
  const { roles, graphicsRoles } = (0, aria_specs_1.ariaSpecs)(specs, version);
@@ -1,6 +1,3 @@
1
1
  import type { MLMLSpec } from '../types';
2
2
  import type { Category } from '../types/permitted-structures';
3
- export declare function getSelectorsByContentModelCategory(
4
- specs: Readonly<MLMLSpec>,
5
- category: Category,
6
- ): ReadonlyArray<string>;
3
+ export declare function getSelectorsByContentModelCategory(specs: MLMLSpec, category: Category): ReadonlyArray<string>;
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSelectorsByContentModelCategory = void 0;
4
4
  function getSelectorsByContentModelCategory(specs, category) {
5
5
  const selectors = specs.def['#contentModels'][category];
6
- return selectors || [];
6
+ return selectors !== null && selectors !== void 0 ? selectors : [];
7
7
  }
8
8
  exports.getSelectorsByContentModelCategory = getSelectorsByContentModelCategory;
@@ -1,6 +1,6 @@
1
1
  import type { ElementSpec } from '../types';
2
2
  export declare function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(
3
- specs: Readonly<Pick<ElementSpec, 'name' | K>[]>,
3
+ specs: readonly Pick<ElementSpec, 'name' | K>[],
4
4
  localName: string,
5
5
  namespace: string | null,
6
6
  ): Pick<ElementSpec, 'name' | K> | null;
@@ -4,12 +4,13 @@ exports.getSpecByTagName = void 0;
4
4
  const resolve_namespace_1 = require("../utils/resolve-namespace");
5
5
  const cache = new Map();
6
6
  function getSpecByTagName(specs, localName, namespace) {
7
- const { localNameWithNS } = (0, resolve_namespace_1.resolveNamespace)(localName, namespace || undefined);
7
+ var _a;
8
+ const { localNameWithNS } = (0, resolve_namespace_1.resolveNamespace)(localName, namespace !== null && namespace !== void 0 ? namespace : undefined);
8
9
  let spec = cache.get(localNameWithNS);
9
10
  if (spec !== undefined) {
10
11
  return spec;
11
12
  }
12
- spec = specs.find(spec => spec.name === localNameWithNS) || null;
13
+ spec = (_a = specs.find(spec => spec.name === localNameWithNS)) !== null && _a !== void 0 ? _a : null;
13
14
  cache.set(localNameWithNS, spec);
14
15
  return spec;
15
16
  }
@@ -6,7 +6,9 @@ const is_void_element_1 = require("./is-void-element");
6
6
  * @see https://html.spec.whatwg.org/multipage/dom.html#the-nothing-content-model
7
7
  * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
8
8
  */
9
- function isNothingContentModel(el) {
9
+ function isNothingContentModel(
10
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
+ el) {
10
12
  return (0, is_void_element_1.isVoidElement)(el) || ['iframe', 'template'].includes(el.localName);
11
13
  }
12
14
  exports.isNothingContentModel = isNothingContentModel;
@@ -1,9 +1,9 @@
1
1
  import type { MLMLSpec } from '../types';
2
2
  export declare function isPalpableElement(
3
3
  el: Element,
4
- specs: Readonly<MLMLSpec>,
4
+ specs: MLMLSpec,
5
5
  options?: {
6
- extendsSvg?: boolean;
7
- extendsExposableElements?: boolean;
6
+ readonly extendsSvg?: boolean;
7
+ readonly extendsExposableElements?: boolean;
8
8
  },
9
9
  ): boolean;
@@ -31,11 +31,13 @@ const exposableElementsThatAreNoBelongingAModel = [
31
31
  'thead',
32
32
  'tr',
33
33
  ];
34
- function isPalpableElement(el, specs, options) {
35
- var _a, _b;
36
- const conditions = [((_a = specs.def['#contentModels']['#palpable']) === null || _a === void 0 ? void 0 : _a.join(',')) || ''];
34
+ function isPalpableElement(
35
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
36
+ el, specs, options) {
37
+ var _a, _b, _c, _d;
38
+ const conditions = [(_b = (_a = specs.def['#contentModels']['#palpable']) === null || _a === void 0 ? void 0 : _a.join(',')) !== null && _b !== void 0 ? _b : ''];
37
39
  if ((options === null || options === void 0 ? void 0 : options.extendsSvg) !== false /* default true */) {
38
- conditions.push(((_b = specs.def['#contentModels']['#SVGRenderable']) === null || _b === void 0 ? void 0 : _b.join(',')) || '');
40
+ conditions.push((_d = (_c = specs.def['#contentModels']['#SVGRenderable']) === null || _c === void 0 ? void 0 : _c.join(',')) !== null && _d !== void 0 ? _d : '');
39
41
  }
40
42
  if (options === null || options === void 0 ? void 0 : options.extendsExposableElements /* default false */) {
41
43
  conditions.push(exposableElementsThatAreNoBelongingAModel.join(','));
@@ -19,7 +19,9 @@ const voidElements = [
19
19
  'track',
20
20
  'wbr',
21
21
  ];
22
- function isVoidElement(el) {
22
+ function isVoidElement(
23
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
24
+ el) {
23
25
  return voidElements.includes(el.localName);
24
26
  }
25
27
  exports.isVoidElement = isVoidElement;
@@ -1,3 +1,7 @@
1
1
  import type { ARIAVersion } from '../types';
2
2
  import type { ARIA } from '../types/aria';
3
- export declare function resolveVersion(aria: ARIA, version: ARIAVersion): Omit<ARIA, ARIAVersion>;
3
+ import type { ReadonlyDeep } from 'type-fest';
4
+ export declare function resolveVersion(
5
+ aria: ReadonlyDeep<ARIA>,
6
+ version: ARIAVersion,
7
+ ): Omit<ReadonlyDeep<ARIA>, ARIAVersion>;
@@ -9,5 +9,5 @@ import type { ElementSpec, ExtendedSpec, MLMLSpec } from '../types';
9
9
  export declare function schemaToSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]): {
10
10
  cites: import('../types').Cites;
11
11
  def: import('../types').SpecDefs;
12
- specs: ElementSpec[];
12
+ specs: readonly ElementSpec[];
13
13
  };
@@ -10,7 +10,7 @@ const merge_array_1 = require("../utils/merge-array");
10
10
  * @param schemas `MLDocument.schemas`
11
11
  */
12
12
  function schemaToSpec(schemas) {
13
- var _a, _b, _c;
13
+ var _a, _b, _c, _d, _e;
14
14
  const [main, ...extendedSpecs] = schemas;
15
15
  const result = { ...main };
16
16
  for (const extendedSpec of extendedSpecs) {
@@ -18,37 +18,43 @@ function schemaToSpec(schemas) {
18
18
  result.cites = [...result.cites, ...extendedSpec.cites];
19
19
  }
20
20
  if (extendedSpec.def) {
21
+ const def = { ...result.def };
21
22
  if ((_a = extendedSpec.def['#globalAttrs']) === null || _a === void 0 ? void 0 : _a['#extends']) {
22
- result.def['#globalAttrs']['#HTMLGlobalAttrs'] = {
23
- ...(((_b = result.def['#globalAttrs']) === null || _b === void 0 ? void 0 : _b['#HTMLGlobalAttrs']) || {}),
24
- ...(((_c = extendedSpec.def['#globalAttrs']) === null || _c === void 0 ? void 0 : _c['#extends']) || {}),
23
+ const gAttrs = { ...def['#globalAttrs'] };
24
+ gAttrs['#HTMLGlobalAttrs'] = {
25
+ ...((_c = (_b = def['#globalAttrs']) === null || _b === void 0 ? void 0 : _b['#HTMLGlobalAttrs']) !== null && _c !== void 0 ? _c : {}),
26
+ ...((_e = (_d = extendedSpec.def['#globalAttrs']) === null || _d === void 0 ? void 0 : _d['#extends']) !== null && _e !== void 0 ? _e : {}),
25
27
  };
28
+ def['#globalAttrs'] = gAttrs;
26
29
  }
27
30
  if (extendedSpec.def['#aria']) {
28
- result.def['#aria'] = {
31
+ def['#aria'] = {
29
32
  '1.1': {
30
- roles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].roles, extendedSpec.def['#aria']['1.1'].roles),
31
- props: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].props, extendedSpec.def['#aria']['1.1'].props),
32
- graphicsRoles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].graphicsRoles, extendedSpec.def['#aria']['1.1'].graphicsRoles),
33
+ roles: (0, merge_array_1.mergeArray)(def['#aria']['1.1'].roles, extendedSpec.def['#aria']['1.1'].roles),
34
+ props: (0, merge_array_1.mergeArray)(def['#aria']['1.1'].props, extendedSpec.def['#aria']['1.1'].props),
35
+ graphicsRoles: (0, merge_array_1.mergeArray)(def['#aria']['1.1'].graphicsRoles, extendedSpec.def['#aria']['1.1'].graphicsRoles),
33
36
  },
34
37
  '1.2': {
35
- roles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].roles, extendedSpec.def['#aria']['1.2'].roles),
36
- props: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].props, extendedSpec.def['#aria']['1.2'].props),
37
- graphicsRoles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].graphicsRoles, extendedSpec.def['#aria']['1.2'].graphicsRoles),
38
+ roles: (0, merge_array_1.mergeArray)(def['#aria']['1.2'].roles, extendedSpec.def['#aria']['1.2'].roles),
39
+ props: (0, merge_array_1.mergeArray)(def['#aria']['1.2'].props, extendedSpec.def['#aria']['1.2'].props),
40
+ graphicsRoles: (0, merge_array_1.mergeArray)(def['#aria']['1.2'].graphicsRoles, extendedSpec.def['#aria']['1.2'].graphicsRoles),
38
41
  },
39
42
  };
40
43
  }
41
44
  if (extendedSpec.def['#contentModels']) {
45
+ const models = { ...def['#contentModels'] };
42
46
  const keys = new Set([
43
- ...Object.keys(result.def['#contentModels']),
47
+ ...Object.keys(def['#contentModels']),
44
48
  ...Object.keys(extendedSpec.def['#contentModels']),
45
49
  ]);
46
50
  for (const modelName of keys) {
47
- const mainModel = result.def['#contentModels'][modelName];
51
+ const mainModel = def['#contentModels'][modelName];
48
52
  const exModel = extendedSpec.def['#contentModels'][modelName];
49
- result.def['#contentModels'][modelName] = [...(mainModel || []), ...(exModel || [])];
53
+ models[modelName] = [...(mainModel !== null && mainModel !== void 0 ? mainModel : []), ...(exModel !== null && exModel !== void 0 ? exModel : [])];
50
54
  }
55
+ def['#contentModels'] = models;
51
56
  }
57
+ result.def = def;
52
58
  }
53
59
  if (extendedSpec.specs) {
54
60
  const exSpecs = extendedSpec.specs.slice();
@@ -20,10 +20,7 @@ export type PermittedRoles =
20
20
  [k: string]: unknown;
21
21
  }
22
22
  )[]
23
- | {
24
- 'core-aam'?: true;
25
- 'graphics-aam'?: true;
26
- };
23
+ | PermittedARIAAAMInfo;
27
24
  /**
28
25
  * If set false:
29
26
  * > No role or aria-* attributes
@@ -141,6 +138,10 @@ export interface ARIA {
141
138
  };
142
139
  };
143
140
  }
141
+ export interface PermittedARIAAAMInfo {
142
+ 'core-aam'?: true;
143
+ 'graphics-aam'?: true;
144
+ }
144
145
  export interface ImplicitProperties {
145
146
  /**
146
147
  * This interface was referenced by `ImplicitProperties`'s JSON-Schema definition
@@ -2,45 +2,44 @@ import type { ARIA } from './aria';
2
2
  import type { AttributeJSON, AttributeType, GlobalAttributes } from './attributes';
3
3
  import type { ContentModel, Category } from './permitted-structures';
4
4
  import type { NamespaceURI } from '@markuplint/ml-ast';
5
+ import type { ReadonlyDeep } from 'type-fest';
5
6
  /**
6
7
  * markuplint Markup-language spec
7
8
  */
8
9
  export interface MLMLSpec {
9
- cites: Cites;
10
- def: SpecDefs;
11
- specs: ElementSpec[];
10
+ readonly cites: Cites;
11
+ readonly def: SpecDefs;
12
+ readonly specs: readonly ElementSpec[];
12
13
  }
13
14
  export type ExtendedElementSpec = Partial<Omit<ElementSpec, 'name' | 'attributes'>> & {
14
- name: ElementSpec['name'];
15
- attributes?: Record<string, Partial<Attribute>>;
15
+ readonly name: ElementSpec['name'];
16
+ readonly attributes?: Readonly<Record<string, Partial<Attribute>>>;
16
17
  };
17
18
  export type ExtendedSpec = {
18
- cites?: Cites;
19
- def?: Partial<SpecDefs>;
20
- specs?: ExtendedElementSpec[];
19
+ readonly cites?: Cites;
20
+ readonly def?: Partial<SpecDefs>;
21
+ readonly specs?: readonly ExtendedElementSpec[];
21
22
  };
22
23
  /**
23
24
  * Reference URLs
24
25
  */
25
- export type Cites = string[];
26
+ export type Cites = readonly string[];
26
27
  export type SpecDefs = {
27
- '#globalAttrs': Partial<{
28
- '#extends': Record<string, Partial<Attribute>>;
29
- '#HTMLGlobalAttrs': Record<string, Partial<Attribute>>;
30
- [OtherGlobalAttrs: string]: Record<string, Partial<Attribute>>;
31
- }>;
32
- '#aria': {
33
- '1.2': ARIASpec;
34
- '1.1': ARIASpec;
28
+ readonly '#globalAttrs': {
29
+ readonly [category: string]: Readonly<Record<string, Partial<Attribute>>>;
35
30
  };
36
- '#contentModels': {
37
- [model in Category]?: string[];
31
+ readonly '#aria': {
32
+ readonly '1.2': ARIASpec;
33
+ readonly '1.1': ARIASpec;
34
+ };
35
+ readonly '#contentModels': {
36
+ readonly [model in Category]?: readonly string[];
38
37
  };
39
38
  };
40
39
  type ARIASpec = {
41
- roles: ARIARoleInSchema[];
42
- graphicsRoles: ARIARoleInSchema[];
43
- props: ARIAProperty[];
40
+ readonly roles: readonly ARIARoleInSchema[];
41
+ readonly graphicsRoles: readonly ARIARoleInSchema[];
42
+ readonly props: readonly ARIAProperty[];
44
43
  };
45
44
  /**
46
45
  * Element spec
@@ -49,64 +48,64 @@ export type ElementSpec = {
49
48
  /**
50
49
  * Tag name
51
50
  */
52
- name: string;
51
+ readonly name: string;
53
52
  /**
54
53
  * Namespaces in XML
55
54
  * @see https://www.w3.org/TR/xml-names/
56
55
  */
57
- namespace?: NamespaceURI;
56
+ readonly namespace?: NamespaceURI;
58
57
  /**
59
58
  * Reference URL
60
59
  */
61
- cite: string;
60
+ readonly cite: string;
62
61
  /**
63
62
  * Description
64
63
  */
65
- description?: string;
64
+ readonly description?: string;
66
65
  /**
67
66
  * Experimental technology
68
67
  */
69
- experimental?: true;
68
+ readonly experimental?: true;
70
69
  /**
71
70
  * Obsolete or alternative elements
72
71
  */
73
- obsolete?:
72
+ readonly obsolete?:
74
73
  | true
75
74
  | {
76
- alt: string;
75
+ readonly alt: string;
77
76
  };
78
77
  /**
79
78
  * Deprecated
80
79
  */
81
- deprecated?: true;
80
+ readonly deprecated?: true;
82
81
  /**
83
82
  * Non-standard
84
83
  */
85
- nonStandard?: true;
84
+ readonly nonStandard?: true;
86
85
  /**
87
86
  * Element categories
88
87
  */
89
- categories: Category[];
88
+ readonly categories: readonly Category[];
90
89
  /**
91
90
  * Permitted contents and permitted parents
92
91
  */
93
- contentModel: ContentModel;
92
+ readonly contentModel: ReadonlyDeep<ContentModel>;
94
93
  /**
95
94
  * Tag omission
96
95
  */
97
- omission: ElementSpecOmission;
96
+ readonly omission: ElementSpecOmission;
98
97
  /**
99
98
  * Global Attributes
100
99
  */
101
- globalAttrs: GlobalAttributes;
100
+ readonly globalAttrs: ReadonlyDeep<GlobalAttributes>;
102
101
  /**
103
102
  * Attributes
104
103
  */
105
- attributes: Record<string, Attribute>;
104
+ readonly attributes: Readonly<Record<string, Attribute>>;
106
105
  /**
107
106
  * WAI-ARIA role and properties
108
107
  */
109
- aria: ARIA;
108
+ readonly aria: ReadonlyDeep<ARIA>;
110
109
  /**
111
110
  * If true, it is possible to add any properties as attributes,
112
111
  * for example, when using a template engine or a view language.
@@ -115,68 +114,68 @@ export type ElementSpec = {
115
114
  *
116
115
  * **It assumes to specify it on the parser plugin.**
117
116
  */
118
- possibleToAddProperties?: true;
117
+ readonly possibleToAddProperties?: true;
119
118
  };
120
119
  type ElementSpecOmission = false | ElementSpecOmissionTags;
121
120
  type ElementSpecOmissionTags = {
122
- startTag: boolean | ElementCondition;
123
- endTag: boolean | ElementCondition;
121
+ readonly startTag: boolean | ElementCondition;
122
+ readonly endTag: boolean | ElementCondition;
124
123
  };
125
124
  type ElementCondition = {
126
- __WIP__: 'WORK_IN_PROGRESS';
125
+ readonly __WIP__: 'WORK_IN_PROGRESS';
127
126
  };
128
127
  export type Attribute = {
129
- name: string;
130
- type: AttributeType | AttributeType[];
131
- description?: string;
132
- caseSensitive?: true;
133
- experimental?: boolean;
134
- obsolete?: true;
135
- deprecated?: boolean;
136
- nonStandard?: true;
128
+ readonly name: string;
129
+ readonly type: ReadonlyDeep<AttributeType> | readonly ReadonlyDeep<AttributeType>[];
130
+ readonly description?: string;
131
+ readonly caseSensitive?: true;
132
+ readonly experimental?: boolean;
133
+ readonly obsolete?: true;
134
+ readonly deprecated?: boolean;
135
+ readonly nonStandard?: true;
137
136
  } & ExtendableAttributeSpec;
138
- type ExtendableAttributeSpec = Omit<AttributeJSON, 'type'>;
137
+ type ExtendableAttributeSpec = Omit<ReadonlyDeep<AttributeJSON>, 'type'>;
139
138
  export type ARIARole = {
140
- name: string;
141
- isAbstract: boolean;
142
- requiredContextRole: string[];
143
- requiredOwnedElements: string[];
144
- accessibleNameRequired: boolean;
145
- accessibleNameFromAuthor: boolean;
146
- accessibleNameFromContent: boolean;
147
- accessibleNameProhibited: boolean;
148
- childrenPresentational: boolean;
149
- ownedProperties: ARIARoleOwnedProperties[];
150
- prohibitedProperties: string[];
139
+ readonly name: string;
140
+ readonly isAbstract: boolean;
141
+ readonly requiredContextRole: readonly string[];
142
+ readonly requiredOwnedElements: readonly string[];
143
+ readonly accessibleNameRequired: boolean;
144
+ readonly accessibleNameFromAuthor: boolean;
145
+ readonly accessibleNameFromContent: boolean;
146
+ readonly accessibleNameProhibited: boolean;
147
+ readonly childrenPresentational: boolean;
148
+ readonly ownedProperties: readonly ARIARoleOwnedProperties[];
149
+ readonly prohibitedProperties: readonly string[];
151
150
  };
152
151
  export type ARIARoleInSchema = Partial<
153
152
  ARIARole & {
154
- description: string;
155
- generalization: string[];
153
+ readonly description: string;
154
+ readonly generalization: readonly string[];
156
155
  }
157
156
  > & {
158
- name: string;
157
+ readonly name: string;
159
158
  };
160
159
  export type ARIARoleOwnedProperties = {
161
- name: string;
162
- inherited?: true;
163
- required?: true;
164
- deprecated?: true;
160
+ readonly name: string;
161
+ readonly inherited?: true;
162
+ readonly required?: true;
163
+ readonly deprecated?: true;
165
164
  };
166
165
  export type ARIAProperty = {
167
- name: string;
168
- type: 'property' | 'state';
169
- deprecated?: true;
170
- isGlobal?: true;
171
- value: ARIAAttributeValue;
172
- conditionalValue?: {
173
- role: string[];
174
- value: ARIAAttributeValue;
166
+ readonly name: string;
167
+ readonly type: 'property' | 'state';
168
+ readonly deprecated?: true;
169
+ readonly isGlobal?: true;
170
+ readonly value: ARIAAttributeValue;
171
+ readonly conditionalValue?: readonly {
172
+ readonly role: readonly string[];
173
+ readonly value: ARIAAttributeValue;
175
174
  }[];
176
- enum: string[];
177
- defaultValue?: string;
178
- equivalentHtmlAttrs?: EquivalentHtmlAttr[];
179
- valueDescriptions?: Record<string, string>;
175
+ readonly enum: readonly string[];
176
+ readonly defaultValue?: string;
177
+ readonly equivalentHtmlAttrs?: readonly EquivalentHtmlAttr[];
178
+ readonly valueDescriptions?: Readonly<Record<string, string>>;
180
179
  };
181
180
  export type ARIAAttributeValue =
182
181
  | 'true/false'
@@ -192,20 +191,20 @@ export type ARIAAttributeValue =
192
191
  | 'URI';
193
192
  export type ARIAVersion = '1.1' | '1.2';
194
193
  export type EquivalentHtmlAttr = {
195
- htmlAttrName: string;
196
- isNotStrictEquivalent?: true;
197
- value: string | null;
194
+ readonly htmlAttrName: string;
195
+ readonly isNotStrictEquivalent?: true;
196
+ readonly value: string | null;
198
197
  };
199
198
  export type Matches = (selector: string) => boolean;
200
199
  export type ComputedRole = {
201
- el: Element;
202
- role:
200
+ readonly el: Element;
201
+ readonly role:
203
202
  | (ARIARole & {
204
- superClassRoles: ARIARoleInSchema[];
205
- isImplicit?: boolean;
203
+ readonly superClassRoles: readonly ARIARoleInSchema[];
204
+ readonly isImplicit?: boolean;
206
205
  })
207
206
  | null;
208
- errorType?: RoleComputationError;
207
+ readonly errorType?: RoleComputationError;
209
208
  };
210
209
  export type RoleComputationError =
211
210
  | 'ABSTRACT'
@@ -1,7 +1,10 @@
1
1
  type NamedDefinition =
2
2
  | string
3
3
  | {
4
- name: string;
4
+ readonly name: string;
5
5
  };
6
- export declare function mergeArray<T extends NamedDefinition>(a: T[], b: T[] | null | undefined): T[];
6
+ export declare function mergeArray<T extends NamedDefinition>(
7
+ a: readonly T[],
8
+ b: readonly T[] | null | undefined,
9
+ ): readonly T[];
7
10
  export {};
@@ -18,7 +18,7 @@ function resolveNamespace(name, namespaceURI = 'http://www.w3.org/1999/xhtml') {
18
18
  const [_explicitNS, _localName] = name.split(':');
19
19
  const explicitNS = _localName ? _explicitNS : null;
20
20
  const localName = (_a = _localName !== null && _localName !== void 0 ? _localName : _explicitNS) !== null && _a !== void 0 ? _a : '';
21
- const namespace = ['html', 'svg', 'mml', 'xlink'].find(_ns => _ns === (explicitNS || (0, get_ns_1.getNS)(namespaceURI || null))) ||
21
+ const namespace = ['html', 'svg', 'mml', 'xlink'].find(_ns => _ns === (explicitNS || (0, get_ns_1.getNS)(namespaceURI !== null && namespaceURI !== void 0 ? namespaceURI : null))) ||
22
22
  'html';
23
23
  const result = {
24
24
  localNameWithNS: `${namespace === 'html' ? '' : `${namespace}:`}${localName}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "3.4.0",
3
+ "version": "3.6.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>",
@@ -25,14 +25,16 @@
25
25
  "schema": "run-s schema:*"
26
26
  },
27
27
  "dependencies": {
28
- "@markuplint/ml-ast": "3.0.0",
28
+ "@markuplint/ml-ast": "3.1.0",
29
29
  "dom-accessibility-api": "^0.5.14",
30
+ "is-plain-object": "^5.0.0",
30
31
  "tslib": "^2.4.1"
31
32
  },
32
33
  "devDependencies": {
33
- "@markuplint/test-tools": "3.0.0",
34
- "@markuplint/types": "3.3.0",
35
- "json-schema-to-typescript": "11.0.2"
34
+ "@markuplint/test-tools": "3.1.0",
35
+ "@markuplint/types": "3.5.0",
36
+ "json-schema-to-typescript": "11.0.2",
37
+ "type-fest": "^3.6.1"
36
38
  },
37
- "gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
39
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
38
40
  }