@markuplint/ml-spec 3.0.0-alpha.82 → 3.0.0-dev.176

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 (138) hide show
  1. package/README.md +8 -3
  2. package/lib/constant/aria-version.d.ts +2 -0
  3. package/lib/constant/aria-version.js +5 -0
  4. package/lib/dom-traverse/accname-computation.js +3 -1
  5. package/lib/dom-traverse/get-attr-specs.d.ts +1 -1
  6. package/lib/dom-traverse/get-attr-specs.js +3 -1
  7. package/lib/dom-traverse/get-computed-aria-props.d.ts +12 -0
  8. package/lib/dom-traverse/get-computed-aria-props.js +108 -0
  9. package/lib/dom-traverse/get-computed-role.d.ts +6 -1
  10. package/lib/dom-traverse/get-computed-role.js +54 -35
  11. package/lib/dom-traverse/get-content-model.d.ts +29 -0
  12. package/lib/dom-traverse/get-content-model.js +30 -0
  13. package/lib/dom-traverse/get-explicit-role.js +9 -4
  14. package/lib/dom-traverse/get-implicit-role.d.ts +6 -2
  15. package/lib/dom-traverse/get-implicit-role.js +6 -2
  16. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +10 -4
  17. package/lib/dom-traverse/get-non-presentational-ancestor.js +10 -2
  18. package/lib/dom-traverse/get-permitted-roles.d.ts +7 -3
  19. package/lib/dom-traverse/get-permitted-roles.js +3 -1
  20. package/lib/dom-traverse/get-spec.d.ts +5 -2
  21. package/lib/dom-traverse/get-spec.js +4 -2
  22. package/lib/dom-traverse/has-required-owned-elements.d.ts +8 -2
  23. package/lib/dom-traverse/has-required-owned-elements.js +26 -8
  24. package/lib/dom-traverse/is-exposed.d.ts +11 -0
  25. package/lib/dom-traverse/is-exposed.js +217 -0
  26. package/lib/dom-traverse/matches-context-role.d.ts +7 -0
  27. package/lib/dom-traverse/matches-context-role.js +27 -0
  28. package/lib/dom-traverse/may-be-focusable.d.ts +2 -0
  29. package/lib/dom-traverse/may-be-focusable.js +24 -0
  30. package/lib/index.d.ts +11 -1
  31. package/lib/index.js +11 -1
  32. package/lib/specs/aria-specs.d.ts +7 -4
  33. package/lib/specs/content-model-category-to-tag-names.d.ts +5 -2
  34. package/lib/specs/content-model-category-to-tag-names.js +2 -2
  35. package/lib/specs/get-aria.d.ts +8 -1
  36. package/lib/specs/get-aria.js +11 -5
  37. package/lib/specs/get-attr-specs.d.ts +7 -3
  38. package/lib/specs/get-attr-specs.js +2 -14
  39. package/lib/specs/get-implicit-role.d.ts +7 -1
  40. package/lib/specs/get-permitted-roles.d.ts +9 -3
  41. package/lib/specs/get-permitted-roles.js +19 -15
  42. package/lib/specs/get-role-spec.d.ts +10 -3
  43. package/lib/specs/get-role-spec.js +2 -2
  44. package/lib/specs/get-selectors-by-content-model-category.d.ts +2 -2
  45. package/lib/specs/get-selectors-by-content-model-category.js +1 -1
  46. package/lib/specs/get-spec-by-tag-name.d.ts +6 -2
  47. package/lib/specs/get-spec-by-tag-name.js +3 -2
  48. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  49. package/lib/specs/is-nothing-content-model.js +14 -0
  50. package/lib/specs/is-palpable-elements.d.ts +9 -0
  51. package/lib/specs/is-palpable-elements.js +49 -0
  52. package/lib/specs/is-void-element.d.ts +1 -0
  53. package/lib/specs/is-void-element.js +27 -0
  54. package/lib/specs/resolve-version.d.ts +5 -1
  55. package/lib/specs/resolve-version.js +1 -1
  56. package/lib/specs/schema-to-spec.d.ts +4 -4
  57. package/lib/specs/schema-to-spec.js +29 -18
  58. package/lib/types/aria.d.ts +150 -109
  59. package/lib/types/attributes.d.ts +1507 -73
  60. package/lib/types/index.d.ts +195 -166
  61. package/{src/types/permitted-structres.ts → lib/types/permitted-structures.d.ts} +24 -35
  62. package/lib/utils/get-ns.d.ts +2 -1
  63. package/lib/utils/get-ns.js +3 -0
  64. package/lib/utils/merge-array.d.ts +9 -4
  65. package/lib/utils/resolve-namespace.d.ts +7 -7
  66. package/lib/utils/resolve-namespace.js +19 -13
  67. package/lib/utils/validateAriaVersion.d.ts +2 -0
  68. package/lib/utils/validateAriaVersion.js +8 -0
  69. package/package.json +13 -8
  70. package/schema.json +6 -6
  71. package/{src/dom-traverse/accname-computation.spec.ts → test/dom-traverse/accname-computation.spec.js} +8 -8
  72. package/test/dom-traverse/get-computed-aria-props.spec.js +758 -0
  73. package/test/dom-traverse/get-computed-role.spec.js +294 -0
  74. package/test/dom-traverse/get-implicit-role.spec.js +40 -0
  75. package/{src/dom-traverse/has-required-owned-elements.spec.ts → test/dom-traverse/has-required-owned-elements.spec.js} +7 -9
  76. package/test/dom-traverse/is-exposed.spec.js +70 -0
  77. package/test/dom-traverse/matches-context-role.spec.js +60 -0
  78. package/{src/specs/get-attr-specs.spec.ts → test/specs/get-attr-specs.spec.js} +2 -8
  79. package/{src/specs/get-implicit-role.spec.ts → test/specs/get-implicit-role.spec.js} +9 -11
  80. package/{src/specs/get-permitted-roles.spec.ts → test/specs/get-permitted-roles.spec.js} +8 -10
  81. package/{src/specs/get-role-spec.spec.ts → test/specs/get-role-spec.spec.js} +4 -4
  82. package/{src/specs/get-spec-by-tag-name.spec.ts → test/specs/get-spec-by-tag-name.spec.js} +11 -11
  83. package/test/specs/resolve-version.spec.js +34 -0
  84. package/test/specs/schema-to-spec.spec.js +61 -0
  85. package/test/utils/resolve-namespace.spec.js +37 -0
  86. package/lib/dom-traverse/focusability-computation.d.ts +0 -1
  87. package/lib/dom-traverse/focusability-computation.js +0 -8
  88. package/lib/dom-traverse/get-aria.d.ts +0 -9
  89. package/lib/dom-traverse/get-aria.js +0 -54
  90. package/lib/specs/aria-spec.d.ts +0 -5
  91. package/lib/specs/aria-spec.js +0 -12
  92. package/lib/specs/get-spec.d.ts +0 -13
  93. package/lib/specs/get-spec.js +0 -85
  94. package/lib/specs/html-spec.d.ts +0 -6
  95. package/lib/specs/html-spec.js +0 -16
  96. package/lib/specs/resolve-namespace.d.ts +0 -9
  97. package/lib/specs/resolve-namespace.js +0 -26
  98. package/lib/types/permitted-structres.d.ts +0 -64
  99. package/lib/utils.d.ts +0 -8
  100. package/lib/utils.js +0 -50
  101. package/schemas/aria.schema.json +0 -258
  102. package/schemas/attributes.schema.json +0 -204
  103. package/schemas/content-models.schema.json +0 -215
  104. package/schemas/element.schema.json +0 -11
  105. package/schemas/global-attributes.schema.json +0 -761
  106. package/src/dom-traverse/accname-computation.ts +0 -5
  107. package/src/dom-traverse/get-attr-specs.ts +0 -8
  108. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  109. package/src/dom-traverse/get-computed-role.ts +0 -193
  110. package/src/dom-traverse/get-explicit-role.ts +0 -112
  111. package/src/dom-traverse/get-implicit-role.ts +0 -36
  112. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  113. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  114. package/src/dom-traverse/get-spec.ts +0 -7
  115. package/src/dom-traverse/has-required-owned-elements.ts +0 -72
  116. package/src/index.ts +0 -17
  117. package/src/specs/aria-specs.ts +0 -6
  118. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  119. package/src/specs/get-aria.ts +0 -85
  120. package/src/specs/get-attr-specs.ts +0 -116
  121. package/src/specs/get-implicit-role.ts +0 -17
  122. package/src/specs/get-permitted-roles.ts +0 -87
  123. package/src/specs/get-role-spec.ts +0 -72
  124. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  125. package/src/specs/get-spec-by-tag-name.ts +0 -16
  126. package/src/specs/is-presentational.ts +0 -6
  127. package/src/specs/resolve-version.ts +0 -20
  128. package/src/specs/schema-to-spec.spec.ts +0 -39
  129. package/src/specs/schema-to-spec.ts +0 -103
  130. package/src/types/aria.ts +0 -147
  131. package/src/types/attributes.ts +0 -1418
  132. package/src/types/index.ts +0 -255
  133. package/src/utils/get-ns.ts +0 -13
  134. package/src/utils/merge-array.ts +0 -35
  135. package/src/utils/resolve-namespace.ts +0 -36
  136. package/tsconfig.test.json +0 -3
  137. package/tsconfig.tsbuildinfo +0 -1
  138. /package/lib/types/{permitted-structres.js → permitted-structures.js} +0 -0
@@ -1,6 +1,6 @@
1
- import specs from '@markuplint/html-spec';
1
+ const { specs } = require('@markuplint/html-spec');
2
2
 
3
- import { getSpecByTagName } from './get-spec-by-tag-name';
3
+ const { getSpecByTagName } = require('../../lib/specs/get-spec-by-tag-name');
4
4
 
5
5
  const divSpec = {
6
6
  conditional: [
@@ -8,26 +8,26 @@ const divSpec = {
8
8
  condition: 'dl > div',
9
9
  contents: [
10
10
  {
11
- zeroOrMore: '#script-supporting',
11
+ zeroOrMore: ':model(script-supporting)',
12
12
  },
13
13
  {
14
14
  oneOrMore: 'dt',
15
15
  },
16
16
  {
17
- zeroOrMore: '#script-supporting',
17
+ zeroOrMore: ':model(script-supporting)',
18
18
  },
19
19
  {
20
20
  oneOrMore: 'dd',
21
21
  },
22
22
  {
23
- zeroOrMore: '#script-supporting',
23
+ zeroOrMore: ':model(script-supporting)',
24
24
  },
25
25
  ],
26
26
  },
27
27
  ],
28
28
  contents: [
29
29
  {
30
- zeroOrMore: '#flow',
30
+ oneOrMore: ':model(flow)',
31
31
  },
32
32
  ],
33
33
  };
@@ -43,11 +43,11 @@ test('svg:svg', () => {
43
43
  contents: [
44
44
  {
45
45
  zeroOrMore: [
46
- '#SVGAnimation',
47
- '#SVGDescriptive',
48
- '#SVGPaintServer',
49
- '#SVGShape',
50
- '#SVGStructural',
46
+ ':model(SVGAnimation)',
47
+ ':model(SVGDescriptive)',
48
+ ':model(SVGPaintServer)',
49
+ ':model(SVGShape)',
50
+ ':model(SVGStructural)',
51
51
  'svg|a',
52
52
  'svg|clipPath',
53
53
  'svg|filter',
@@ -0,0 +1,34 @@
1
+ const { resolveVersion } = require('../../lib/specs/resolve-version');
2
+
3
+ test('output', () => {
4
+ const aria = {
5
+ implicitRole: 'button',
6
+ permittedRoles: false,
7
+ };
8
+ const resolved = resolveVersion(aria, '1.1');
9
+ expect(resolved.implicitRole).toBe('button');
10
+ });
11
+
12
+ test('output the specified version', () => {
13
+ const aria = {
14
+ implicitRole: 'button',
15
+ permittedRoles: false,
16
+ 1.1: {
17
+ implicitRole: 'link',
18
+ },
19
+ };
20
+ const resolved = resolveVersion(aria, '1.1');
21
+ expect(resolved.implicitRole).toBe('link');
22
+ });
23
+
24
+ test('output the latest undefined version', () => {
25
+ const aria = {
26
+ implicitRole: 'button',
27
+ permittedRoles: false,
28
+ 1.1: {
29
+ implicitRole: 'link',
30
+ },
31
+ };
32
+ const resolved = resolveVersion(aria, '1.3');
33
+ expect(resolved.implicitRole).toBe('button');
34
+ });
@@ -0,0 +1,61 @@
1
+ const htmlSpec = require('@markuplint/html-spec');
2
+
3
+ const { schemaToSpec } = require('../../lib/specs/schema-to-spec');
4
+
5
+ describe('schemaToSpec', () => {
6
+ test('specs', () => {
7
+ const exAttr = {
8
+ ref: 'N/A',
9
+ type: 'Boolean',
10
+ description: 'For the unit test.',
11
+ };
12
+ const exAttr2 = {
13
+ ref: 'N/A',
14
+ type: 'Boolean',
15
+ description: 'For the unit test. Override.',
16
+ };
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
+
40
+ test('globalAttrs.extends', () => {
41
+ const keyAttr = {
42
+ type: 'NoEmptyAny',
43
+ description: 'A special attribute for list rendering',
44
+ condition: '[v-for]',
45
+ };
46
+ const mergedSpec = schemaToSpec([
47
+ htmlSpec,
48
+ {
49
+ def: {
50
+ '#globalAttrs': {
51
+ '#extends': {
52
+ key: keyAttr,
53
+ },
54
+ },
55
+ },
56
+ },
57
+ ]);
58
+ const key = mergedSpec.def['#globalAttrs']['#HTMLGlobalAttrs']['key'];
59
+ expect(key).toStrictEqual(keyAttr);
60
+ });
61
+ });
@@ -0,0 +1,37 @@
1
+ const { resolveNamespace } = require('../../lib/utils/resolve-namespace');
2
+
3
+ test('tag', () => {
4
+ expect(resolveNamespace('a')).toStrictEqual({
5
+ localName: 'a',
6
+ localNameWithNS: 'a',
7
+ namespace: 'html',
8
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
9
+ });
10
+ expect(resolveNamespace('svg:a')).toStrictEqual({
11
+ localName: 'a',
12
+ localNameWithNS: 'svg:a',
13
+ namespace: 'svg',
14
+ namespaceURI: 'http://www.w3.org/2000/svg',
15
+ });
16
+ });
17
+
18
+ test('attr', () => {
19
+ expect(resolveNamespace('href', 'http://www.w3.org/1999/xhtml')).toStrictEqual({
20
+ localName: 'href',
21
+ localNameWithNS: 'href',
22
+ namespace: 'html',
23
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
24
+ });
25
+ expect(resolveNamespace('href', 'http://www.w3.org/2000/svg')).toStrictEqual({
26
+ localName: 'href',
27
+ localNameWithNS: 'svg:href',
28
+ namespace: 'svg',
29
+ namespaceURI: 'http://www.w3.org/2000/svg',
30
+ });
31
+ expect(resolveNamespace('xlink:href', 'http://www.w3.org/2000/svg')).toStrictEqual({
32
+ localName: 'href',
33
+ localNameWithNS: 'xlink:href',
34
+ namespace: 'xlink',
35
+ namespaceURI: 'http://www.w3.org/1999/xlink',
36
+ });
37
+ });
@@ -1 +0,0 @@
1
- export declare function isFocusable(el: Element): boolean;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFocusable = void 0;
4
- const tabbable_1 = require("tabbable");
5
- function isFocusable(el) {
6
- return (0, tabbable_1.isFocusable)(el, { displayCheck: 'none' });
7
- }
8
- exports.isFocusable = isFocusable;
@@ -1,9 +0,0 @@
1
- import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
- import type { ARIA } from '../types/aria';
3
- export declare function getARIA(
4
- specs: Readonly<MLMLSpec>,
5
- localName: string,
6
- namespace: string | null,
7
- version: ARIAVersion,
8
- matches: Matches,
9
- ): Omit<ARIA, ARIAVersion | 'conditions'> | null;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getARIA = void 0;
4
- const html_spec_1 = require("../specs/html-spec");
5
- const resolve_version_1 = require("../specs/resolve-version");
6
- const cache = new Map();
7
- function getARIA(specs, localName, namespace, version, matches) {
8
- var _a, _b, _c, _d, _e;
9
- const aria = getVersionResolvedARIA(specs, localName, namespace, 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 (!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, localName, namespace, version) {
40
- var _a;
41
- const key = localName + namespace + version;
42
- let aria = cache.get(key);
43
- if (aria !== undefined) {
44
- return aria;
45
- }
46
- const spec = (_a = (0, html_spec_1.htmlSpec)(specs, localName, namespace)) === null || _a === void 0 ? void 0 : _a.aria;
47
- if (!spec) {
48
- cache.set(key, null);
49
- return null;
50
- }
51
- aria = (0, resolve_version_1.resolveVersion)(spec, version);
52
- cache.set(key, aria);
53
- return aria;
54
- }
@@ -1,5 +0,0 @@
1
- import type { MLMLSpec } from '../types';
2
- export declare function ariaSpec(specs: Readonly<MLMLSpec>): {
3
- roles: import('../types').ARIRRoleAttribute[];
4
- ariaAttrs: import('../types').ARIAAttribute[];
5
- };
@@ -1,12 +0,0 @@
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;
@@ -1,13 +0,0 @@
1
- import type { ElementSpec, ExtendedSpec, MLMLSpec } from '../types';
2
- /**
3
- * Merging HTML-spec schema and extended spec schemas
4
- *
5
- * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in cofigure files.
6
- *
7
- * @param schemas `MLDocument.schemas`
8
- */
9
- export declare function getSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]): {
10
- cites: import('../types').Cites;
11
- def: import('../types').SpecDefs;
12
- specs: ElementSpec[];
13
- };
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpec = void 0;
4
- const utils_1 = require("../utils");
5
- /**
6
- * Merging HTML-spec schema and extended spec schemas
7
- *
8
- * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in cofigure files.
9
- *
10
- * @param schemas `MLDocument.schemas`
11
- */
12
- function getSpec(schemas) {
13
- var _a, _b, _c;
14
- const [main, ...extendedSpecs] = schemas;
15
- const result = { ...main };
16
- for (const extendedSpec of extendedSpecs) {
17
- if (extendedSpec.cites) {
18
- result.cites = [...result.cites, ...extendedSpec.cites];
19
- }
20
- if (extendedSpec.def) {
21
- if (extendedSpec.def['#ariaAttrs']) {
22
- result.def['#ariaAttrs'] = [...result.def['#ariaAttrs'], ...extendedSpec.def['#ariaAttrs']];
23
- }
24
- if ((_a = extendedSpec.def['#globalAttrs']) === null || _a === void 0 ? void 0 : _a['#extends']) {
25
- result.def['#globalAttrs']['#HTMLGlobalAttrs'] = {
26
- ...(((_b = result.def['#globalAttrs']) === null || _b === void 0 ? void 0 : _b['#HTMLGlobalAttrs']) || {}),
27
- ...(((_c = extendedSpec.def['#globalAttrs']) === null || _c === void 0 ? void 0 : _c['#extends']) || {}),
28
- };
29
- }
30
- if (extendedSpec.def['#roles']) {
31
- result.def['#roles'] = [...result.def['#roles'], ...extendedSpec.def['#roles']];
32
- }
33
- if (extendedSpec.def['#contentModels']) {
34
- const keys = new Set([
35
- ...Object.keys(result.def['#contentModels']),
36
- ...Object.keys(extendedSpec.def['#contentModels']),
37
- ]);
38
- for (const modelName of keys) {
39
- const mainModel = result.def['#contentModels'][modelName];
40
- const exModel = extendedSpec.def['#contentModels'][modelName];
41
- result.def['#contentModels'][modelName] = [...(mainModel || []), ...(exModel || [])];
42
- }
43
- }
44
- }
45
- if (extendedSpec.specs) {
46
- const exSpecs = extendedSpec.specs.slice();
47
- const specs = [];
48
- for (const elSpec of result.specs) {
49
- const tagName = elSpec.name.toLowerCase();
50
- const index = exSpecs.findIndex(spec => spec.name.toLowerCase() === tagName);
51
- if (index === -1) {
52
- specs.push(elSpec);
53
- continue;
54
- }
55
- const exSpec = exSpecs.splice(index, 1)[0];
56
- specs.push({
57
- ...elSpec,
58
- ...exSpec,
59
- globalAttrs: {
60
- ...elSpec.globalAttrs,
61
- ...exSpec.globalAttrs,
62
- },
63
- attributes: mergeAttrSpec(elSpec.attributes, exSpec.attributes),
64
- categories: (0, utils_1.mergeArray)(elSpec.categories, exSpec.categories),
65
- });
66
- }
67
- result.specs = specs;
68
- }
69
- }
70
- return result;
71
- }
72
- exports.getSpec = getSpec;
73
- function mergeAttrSpec(std, ex = {}) {
74
- const result = {};
75
- const keys = Array.from(new Set([...Object.keys(std), ...Object.keys(ex)]));
76
- for (const key of keys) {
77
- const _std = std[key];
78
- const _ex = ex[key];
79
- result[key] = {
80
- ..._std,
81
- ..._ex,
82
- };
83
- }
84
- return result;
85
- }
@@ -1,6 +0,0 @@
1
- import type { ElementSpec, MLMLSpec } from '../types';
2
- export declare function htmlSpec(
3
- specs: Readonly<MLMLSpec>,
4
- localName: string,
5
- namespace: string | null,
6
- ): ElementSpec | null;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.htmlSpec = void 0;
4
- const resolve_namespace_1 = require("../utils/resolve-namespace");
5
- const cache = new Map();
6
- function htmlSpec(specs, localName, namespace) {
7
- const { localNameWithNS } = (0, resolve_namespace_1.resolveNamespace)(localName, namespace || undefined);
8
- let spec = cache.get(localNameWithNS);
9
- if (spec !== undefined) {
10
- return spec;
11
- }
12
- spec = specs.specs.find(spec => spec.name === localNameWithNS) || null;
13
- cache.set(localNameWithNS, spec);
14
- return spec;
15
- }
16
- exports.htmlSpec = htmlSpec;
@@ -1,9 +0,0 @@
1
- import type { NamespaceURI } from '@markuplint/ml-ast';
2
- declare type NamespacedElementName = {
3
- localNameWithNS: string;
4
- localName: string;
5
- namespace: 'html' | 'svg' | 'mml';
6
- namespaceURI: NamespaceURI;
7
- };
8
- export declare function resolveNamespace(localName: string, namespaceURI?: string): NamespacedElementName;
9
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveNamespace = void 0;
4
- const utils_1 = require("../utils");
5
- const cache = new Map();
6
- function resolveNamespace(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
7
- const cached = cache.get(localName + namespaceURI);
8
- if (cached) {
9
- return cached;
10
- }
11
- const name = localName.split(':')[1] || localName;
12
- const ns = (0, utils_1.getNS)(namespaceURI || null);
13
- const result = {
14
- localNameWithNS: `${ns === 'html' ? '' : `${ns}:`}${name}`,
15
- localName: name,
16
- namespace: ns,
17
- namespaceURI: [
18
- 'http://www.w3.org/1999/xhtml',
19
- 'http://www.w3.org/2000/svg',
20
- 'http://www.w3.org/1998/Math/MathML',
21
- ].find(ns => namespaceURI) || 'http://www.w3.org/1999/xhtml',
22
- };
23
- cache.set(localName + namespaceURI, result);
24
- return result;
25
- }
26
- exports.resolveNamespace = resolveNamespace;
@@ -1,64 +0,0 @@
1
- /**
2
- * This file was automatically generated by json-schema-to-typescript.
3
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
- * and run json-schema-to-typescript to regenerate this file.
5
- */
6
- export declare type PermittedContent = PermittedContentRequire | PermittedContentOptional | PermittedContentOneOrMore | PermittedContentZeroOrMore | PermittedContentChoice | PermittedContentInterleave;
7
- export declare type Target = ContentType | ContentType[];
8
- export declare type ContentType = string | Category;
9
- export declare type Category = '#text' | '#phrasing' | '#flow' | '#interactive' | '#heading' | '#sectioning' | '#metadata' | '#transparent' | '#embedded' | '#palpable' | '#script-supporting' | '#SVGAnimation' | '#SVGBasicShapes' | '#SVGContainer' | '#SVGDescriptive' | '#SVGFilterPrimitive' | '#SVGFont' | '#SVGGradient' | '#SVGGraphics' | '#SVGGraphicsReferencing' | '#SVGLightSource' | '#SVGNeverRendered' | '#SVGNone' | '#SVGPaintServer' | '#SVGRenderable' | '#SVGShape' | '#SVGStructural' | '#SVGStructurallyExternal' | '#SVGTextContent' | '#SVGTextContentChild' | '#SVGOtherXMLNamespace';
10
- export declare type PermittedContentSpec = PermittedContent[];
11
- export interface ContentModelsSchema {
12
- __contentModel?: ContentModel;
13
- }
14
- export interface ContentModel {
15
- contents: PermittedContentSpec | boolean;
16
- descendantOf?: string;
17
- conditional?: {
18
- condition: string;
19
- contents: PermittedContentSpec | boolean;
20
- }[];
21
- }
22
- export interface PermittedContentRequire {
23
- require: Target;
24
- ignore?: Target;
25
- notAllowedDescendants?: ContentType[];
26
- max?: number;
27
- min?: number;
28
- _TODO_?: string;
29
- }
30
- export interface PermittedContentOptional {
31
- optional: Target;
32
- ignore?: Target;
33
- notAllowedDescendants?: ContentType[];
34
- max?: number;
35
- _TODO_?: string;
36
- }
37
- export interface PermittedContentOneOrMore {
38
- oneOrMore: Target | PermittedContentSpec;
39
- ignore?: Target;
40
- notAllowedDescendants?: ContentType[];
41
- max?: number;
42
- _TODO_?: string;
43
- }
44
- export interface PermittedContentZeroOrMore {
45
- zeroOrMore: Target | PermittedContentSpec;
46
- ignore?: Target;
47
- notAllowedDescendants?: ContentType[];
48
- max?: number;
49
- _TODO_?: string;
50
- }
51
- export interface PermittedContentChoice {
52
- choice: [PermittedContentSpec, PermittedContentSpec] | [PermittedContentSpec, PermittedContentSpec, PermittedContentSpec] | [PermittedContentSpec, PermittedContentSpec, PermittedContentSpec, PermittedContentSpec] | [
53
- PermittedContentSpec,
54
- PermittedContentSpec,
55
- PermittedContentSpec,
56
- PermittedContentSpec,
57
- PermittedContentSpec
58
- ];
59
- _TODO_?: string;
60
- }
61
- export interface PermittedContentInterleave {
62
- interleave: [PermittedContentSpec, PermittedContentSpec, ...PermittedContentSpec[]];
63
- _TODO_?: string;
64
- }
package/lib/utils.d.ts DELETED
@@ -1,8 +0,0 @@
1
- declare type NamedDefinition =
2
- | string
3
- | {
4
- name: string;
5
- };
6
- export declare function getNS(namespaceURI: string | null): 'svg' | 'mml' | 'html';
7
- export declare function mergeArray<T extends NamedDefinition>(a: T[], b: T[] | null | undefined): T[];
8
- export {};
package/lib/utils.js DELETED
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeArray = exports.getNS = void 0;
4
- function getNS(namespaceURI) {
5
- switch (namespaceURI) {
6
- case 'http://www.w3.org/2000/svg': {
7
- return 'svg';
8
- }
9
- case 'http://www.w3.org/1998/Math/MathML': {
10
- return 'mml';
11
- }
12
- default: {
13
- return 'html';
14
- }
15
- }
16
- }
17
- exports.getNS = getNS;
18
- function mergeArray(a, b) {
19
- if (!b) {
20
- return a;
21
- }
22
- const result = a.slice();
23
- for (const bItem of b) {
24
- const bName = getName(bItem);
25
- const aIndex = result.findIndex(item => getName(item) === bName);
26
- if (aIndex === -1) {
27
- result.push(bItem);
28
- continue;
29
- }
30
- const aItem = result.splice(aIndex, 1)[0];
31
- if (typeof bItem === 'string') {
32
- continue;
33
- }
34
- if (typeof aItem === 'string') {
35
- result.push(bItem);
36
- continue;
37
- }
38
- const exItem = {
39
- ...aItem,
40
- ...bItem,
41
- };
42
- result.push(exItem);
43
- }
44
- return result;
45
- }
46
- exports.mergeArray = mergeArray;
47
- function getName(def) {
48
- const result = typeof def === 'string' ? def : def.name;
49
- return result.toLowerCase().trim();
50
- }