@markuplint/rules 3.15.0 → 4.0.0-alpha.10

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 (178) hide show
  1. package/.eslintrc +5 -0
  2. package/LICENSE +1 -1
  3. package/lib/attr-check.d.ts +8 -19
  4. package/lib/attr-check.js +16 -21
  5. package/lib/attr-duplication/index.d.ts +1 -3
  6. package/lib/attr-duplication/index.js +6 -6
  7. package/lib/attr-value-quotes/index.d.ts +2 -2
  8. package/lib/attr-value-quotes/index.js +8 -10
  9. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  10. package/lib/case-sensitive-attr-name/index.js +12 -13
  11. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  12. package/lib/case-sensitive-tag-name/index.js +5 -4
  13. package/lib/character-reference/index.d.ts +1 -1
  14. package/lib/character-reference/index.js +13 -12
  15. package/lib/class-naming/index.d.ts +1 -1
  16. package/lib/class-naming/index.js +14 -13
  17. package/lib/create-message.d.ts +2 -12
  18. package/lib/create-message.js +26 -26
  19. package/lib/debug.js +2 -6
  20. package/lib/deprecated-attr/index.d.ts +1 -3
  21. package/lib/deprecated-attr/index.js +9 -9
  22. package/lib/deprecated-element/index.d.ts +1 -3
  23. package/lib/deprecated-element/index.js +7 -6
  24. package/lib/disallowed-element/index.d.ts +1 -1
  25. package/lib/disallowed-element/index.js +9 -8
  26. package/lib/doctype/index.d.ts +2 -2
  27. package/lib/doctype/index.js +5 -4
  28. package/lib/end-tag/index.d.ts +1 -1
  29. package/lib/end-tag/index.js +8 -8
  30. package/lib/helpers.d.ts +17 -35
  31. package/lib/helpers.js +25 -32
  32. package/lib/id-duplication/index.d.ts +1 -3
  33. package/lib/id-duplication/index.js +5 -4
  34. package/lib/index.d.ts +21 -17
  35. package/lib/index.js +63 -66
  36. package/lib/ineffective-attr/index.d.ts +1 -3
  37. package/lib/ineffective-attr/index.js +8 -7
  38. package/lib/invalid-attr/index.d.ts +31 -38
  39. package/lib/invalid-attr/index.js +33 -33
  40. package/lib/label-has-control/index.d.ts +1 -3
  41. package/lib/label-has-control/index.js +5 -4
  42. package/lib/landmark-roles/index.d.ts +3 -3
  43. package/lib/landmark-roles/index.js +16 -18
  44. package/lib/no-boolean-attr-value/index.d.ts +1 -3
  45. package/lib/no-boolean-attr-value/index.js +9 -9
  46. package/lib/no-default-value/index.d.ts +1 -3
  47. package/lib/no-default-value/index.js +12 -12
  48. package/lib/no-empty-palpable-content/index.d.ts +3 -3
  49. package/lib/no-empty-palpable-content/index.js +9 -8
  50. package/lib/no-hard-code-id/index.d.ts +1 -3
  51. package/lib/no-hard-code-id/index.js +5 -4
  52. package/lib/no-refer-to-non-existent-id/index.d.ts +1 -1
  53. package/lib/no-refer-to-non-existent-id/index.js +37 -38
  54. package/lib/no-use-event-handler-attr/index.d.ts +2 -2
  55. package/lib/no-use-event-handler-attr/index.js +7 -6
  56. package/lib/permitted-contents/choice.d.ts +2 -8
  57. package/lib/permitted-contents/choice.js +14 -19
  58. package/lib/permitted-contents/complex-branch.d.ts +2 -8
  59. package/lib/permitted-contents/complex-branch.js +10 -14
  60. package/lib/permitted-contents/content-model.d.ts +1 -1
  61. package/lib/permitted-contents/content-model.js +10 -11
  62. package/lib/permitted-contents/count-pattern.d.ts +3 -18
  63. package/lib/permitted-contents/count-pattern.js +19 -24
  64. package/lib/permitted-contents/debug.browser.d.ts +16 -16
  65. package/lib/permitted-contents/debug.browser.js +9 -12
  66. package/lib/permitted-contents/debug.d.ts +10 -3
  67. package/lib/permitted-contents/debug.js +12 -13
  68. package/lib/permitted-contents/index.d.ts +2 -2
  69. package/lib/permitted-contents/index.js +13 -13
  70. package/lib/permitted-contents/matches-selector.d.ts +2 -7
  71. package/lib/permitted-contents/matches-selector.js +13 -18
  72. package/lib/permitted-contents/order.d.ts +2 -8
  73. package/lib/permitted-contents/order.js +19 -24
  74. package/lib/permitted-contents/recursive-branch.d.ts +3 -9
  75. package/lib/permitted-contents/recursive-branch.js +9 -13
  76. package/lib/permitted-contents/represent-transparent-nodes.d.ts +4 -8
  77. package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
  78. package/lib/permitted-contents/start.d.ts +2 -7
  79. package/lib/permitted-contents/start.js +13 -21
  80. package/lib/permitted-contents/transparent.d.ts +1 -1
  81. package/lib/permitted-contents/transparent.js +6 -11
  82. package/lib/permitted-contents/types.d.ts +29 -29
  83. package/lib/permitted-contents/types.js +1 -2
  84. package/lib/permitted-contents/utils.d.ts +42 -79
  85. package/lib/permitted-contents/utils.js +72 -82
  86. package/lib/placeholder-label-option/index.d.ts +1 -1
  87. package/lib/placeholder-label-option/index.js +12 -13
  88. package/lib/require-accessible-name/index.d.ts +2 -2
  89. package/lib/require-accessible-name/index.js +12 -15
  90. package/lib/require-datetime/index.d.ts +3 -3
  91. package/lib/require-datetime/index.js +14 -13
  92. package/lib/require-datetime/types.d.ts +2 -2
  93. package/lib/require-datetime/types.js +1 -2
  94. package/lib/require-datetime/utils.d.ts +1 -1
  95. package/lib/require-datetime/utils.js +5 -12
  96. package/lib/required-attr/index.d.ts +3 -3
  97. package/lib/required-attr/index.js +11 -11
  98. package/lib/required-element/index.d.ts +2 -2
  99. package/lib/required-element/index.js +7 -7
  100. package/lib/required-h1/index.d.ts +3 -3
  101. package/lib/required-h1/index.js +6 -6
  102. package/lib/use-list/index.d.ts +6 -2
  103. package/lib/use-list/index.js +27 -11
  104. package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
  105. package/lib/wai-aria/checkings/abstract-role.js +5 -10
  106. package/lib/wai-aria/checkings/default-value.d.ts +4 -8
  107. package/lib/wai-aria/checkings/default-value.js +2 -6
  108. package/lib/wai-aria/checkings/deprecated-props.d.ts +5 -9
  109. package/lib/wai-aria/checkings/deprecated-props.js +3 -8
  110. package/lib/wai-aria/checkings/disallowed-prop.d.ts +5 -9
  111. package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
  112. package/lib/wai-aria/checkings/implicit-props.d.ts +5 -9
  113. package/lib/wai-aria/checkings/implicit-props.js +12 -17
  114. package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
  115. package/lib/wai-aria/checkings/implicit-role.js +4 -9
  116. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
  117. package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
  118. package/lib/wai-aria/checkings/no-global-prop.d.ts +4 -8
  119. package/lib/wai-aria/checkings/no-global-prop.js +2 -7
  120. package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
  121. package/lib/wai-aria/checkings/non-existent-role.js +4 -9
  122. package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
  123. package/lib/wai-aria/checkings/permitted-roles.js +4 -9
  124. package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
  125. package/lib/wai-aria/checkings/presentational-children.js +5 -10
  126. package/lib/wai-aria/checkings/required-owned-elements.d.ts +4 -8
  127. package/lib/wai-aria/checkings/required-owned-elements.js +7 -11
  128. package/lib/wai-aria/checkings/required-prop.d.ts +7 -13
  129. package/lib/wai-aria/checkings/required-prop.js +2 -7
  130. package/lib/wai-aria/checkings/value.d.ts +7 -16
  131. package/lib/wai-aria/checkings/value.js +7 -13
  132. package/lib/wai-aria/index.d.ts +2 -2
  133. package/lib/wai-aria/index.js +41 -40
  134. package/lib/wai-aria/types.d.ts +10 -10
  135. package/lib/wai-aria/types.js +1 -2
  136. package/package.json +17 -13
  137. package/test/attr-check.spec.js +0 -77
  138. package/test/attr-duplication/index.spec.js +0 -159
  139. package/test/attr-value-quotes/index.spec.js +0 -133
  140. package/test/case-sensitive-attr-name/index.spec.js +0 -65
  141. package/test/case-sensitive-tag-name/index.spec.js +0 -80
  142. package/test/character-reference/index.spec.js +0 -72
  143. package/test/class-naming/index.spec.js +0 -470
  144. package/test/create-message.spec.js +0 -497
  145. package/test/deprecated-attr/index.spec.js +0 -48
  146. package/test/deprecated-element/index.spec.js +0 -35
  147. package/test/disallowed-element/index.spec.js +0 -90
  148. package/test/doctype/index.spec.js +0 -50
  149. package/test/end-tag/index.spec.js +0 -162
  150. package/test/id-duplication/index.spec.js +0 -47
  151. package/test/ineffective-attr/index.spec.js +0 -31
  152. package/test/invalid-attr/index.spec.js +0 -1631
  153. package/test/label-has-control/index.spec.js +0 -29
  154. package/test/landmark-roles/index.spec.js +0 -187
  155. package/test/no-boolean-attr-value/index.spec.js +0 -41
  156. package/test/no-default-value/index.spec.js +0 -74
  157. package/test/no-empty-palpable-content/index.spec.js +0 -115
  158. package/test/no-hard-code-id/index.spec.js +0 -100
  159. package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
  160. package/test/no-use-event-handler-attr/index.spec.js +0 -57
  161. package/test/permitted-contents/choice.spec.js +0 -174
  162. package/test/permitted-contents/count-pattern.spec.js +0 -308
  163. package/test/permitted-contents/index.spec.js +0 -1395
  164. package/test/permitted-contents/matches-selector.spec.js +0 -59
  165. package/test/permitted-contents/order.spec.js +0 -351
  166. package/test/permitted-contents/recursive-branch.spec.js +0 -41
  167. package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
  168. package/test/permitted-contents/start.spec.js +0 -67
  169. package/test/placeholder-label-option/index.spec.js +0 -113
  170. package/test/require-accessible-name/index.spec.js +0 -444
  171. package/test/require-datetime/index.spec.js +0 -54
  172. package/test/require-datetime/utils.spec.js +0 -52
  173. package/test/required-attr/index.spec.js +0 -414
  174. package/test/required-element/index.spec.js +0 -188
  175. package/test/required-h1/index.spec.js +0 -69
  176. package/test/use-list/index.spec.js +0 -109
  177. package/test/wai-aria/checkings/value.spec.js +0 -33
  178. package/test/wai-aria/index.spec.js +0 -1203
@@ -1,12 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const shared_1 = require("@markuplint/shared");
1
+ import { createRule, getAttrSpecs, ariaSpecs } from '@markuplint/ml-core';
2
+ import { ARIA_RECOMMENDED_VERSION } from '@markuplint/ml-spec';
3
+ import { decodeEntities, decodeHref } from '@markuplint/shared';
6
4
  const HYPERLINK_SELECTOR = 'a[href], area[href]';
7
- exports.default = (0, ml_core_1.createRule)({
5
+ export default createRule({
6
+ meta: {
7
+ category: 'a11y',
8
+ },
8
9
  defaultOptions: {
9
- ariaVersion: ml_spec_1.ARIA_RECOMMENDED_VERSION,
10
+ ariaVersion: ARIA_RECOMMENDED_VERSION,
10
11
  fragmentRefersNameAttr: false,
11
12
  },
12
13
  async verify({ document, report, t }) {
@@ -18,36 +19,35 @@ exports.default = (0, ml_core_1.createRule)({
18
19
  if (isMutable) {
19
20
  return;
20
21
  }
21
- document.querySelectorAll('[id]').forEach(el => {
22
+ for (const el of document.querySelectorAll('[id]')) {
22
23
  const attr = el.getAttributeNode('id');
23
24
  if (!attr) {
24
- return;
25
+ continue;
25
26
  }
26
27
  if (attr.isDynamicValue) {
27
28
  hasDynamicId = true;
28
29
  }
29
30
  if (attr.valueType !== 'code') {
30
- idList.add((0, shared_1.decodeEntities)(attr.value));
31
+ idList.add(decodeEntities(attr.value));
31
32
  }
32
- });
33
+ }
33
34
  if (hasDynamicId) {
34
35
  return;
35
36
  }
36
- document.querySelectorAll('[name]').forEach(el => {
37
+ for (const el of document.querySelectorAll('[name]')) {
37
38
  const attr = el.getAttributeNode('name');
38
39
  if (!attr) {
39
- return;
40
+ continue;
40
41
  }
41
42
  if (attr.isDynamicValue) {
42
43
  hasDynamicName = true;
43
44
  }
44
45
  if (attr.valueType !== 'code') {
45
- nameList.add((0, shared_1.decodeEntities)(attr.value));
46
+ nameList.add(decodeEntities(attr.value));
46
47
  }
47
- });
48
+ }
48
49
  await document.walkOn('Attr', attr => {
49
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
50
- const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
50
+ const attrSpec = getAttrSpecs(attr.ownerElement, document.specs);
51
51
  if (!attrSpec) {
52
52
  return;
53
53
  }
@@ -68,9 +68,9 @@ exports.default = (0, ml_core_1.createRule)({
68
68
  if (spec.type === 'DOMID' && !idList.has(value)) {
69
69
  report({
70
70
  scope: attr,
71
- line: (_a = attr.valueNode) === null || _a === void 0 ? void 0 : _a.startLine,
72
- col: (_b = attr.valueNode) === null || _b === void 0 ? void 0 : _b.startCol,
73
- raw: (_c = attr.valueNode) === null || _c === void 0 ? void 0 : _c.raw,
71
+ line: attr.valueNode?.startLine,
72
+ col: attr.valueNode?.startCol,
73
+ raw: attr.valueNode?.raw,
74
74
  message: t('Missing {0}', t('"{0*}" ID', value)),
75
75
  });
76
76
  }
@@ -78,29 +78,29 @@ exports.default = (0, ml_core_1.createRule)({
78
78
  const refs = value
79
79
  .split(spec.type.separator === 'space' ? /\s/ : ',')
80
80
  .map(id => id.trim())
81
- .filter(_ => _);
81
+ .filter(Boolean);
82
82
  for (const ref of refs) {
83
83
  if (!idList.has(ref)) {
84
84
  report({
85
85
  scope: attr,
86
- line: (_d = attr.valueNode) === null || _d === void 0 ? void 0 : _d.startLine,
87
- col: (_e = attr.valueNode) === null || _e === void 0 ? void 0 : _e.startCol,
88
- raw: (_f = attr.valueNode) === null || _f === void 0 ? void 0 : _f.raw,
86
+ line: attr.valueNode?.startLine,
87
+ col: attr.valueNode?.startCol,
88
+ raw: attr.valueNode?.raw,
89
89
  message: t('Missing {0}', t('"{0*}" ID', ref)),
90
90
  });
91
91
  }
92
92
  }
93
93
  }
94
94
  }
95
- const { props } = (0, ml_core_1.ariaSpecs)(document.specs, attr.rule.options.ariaVersion);
95
+ const { props } = ariaSpecs(document.specs, attr.rule.options.ariaVersion);
96
96
  const aria = props.find(prop => prop.name === name);
97
97
  if (aria) {
98
98
  if (aria.value === 'ID reference' && !idList.has(value)) {
99
99
  report({
100
100
  scope: attr,
101
- line: (_g = attr.valueNode) === null || _g === void 0 ? void 0 : _g.startLine,
102
- col: (_h = attr.valueNode) === null || _h === void 0 ? void 0 : _h.startCol,
103
- raw: (_j = attr.valueNode) === null || _j === void 0 ? void 0 : _j.raw,
101
+ line: attr.valueNode?.startLine,
102
+ col: attr.valueNode?.startCol,
103
+ raw: attr.valueNode?.raw,
104
104
  message: t('Missing {0}', t('"{0*}" ID', value)),
105
105
  });
106
106
  }
@@ -108,14 +108,14 @@ exports.default = (0, ml_core_1.createRule)({
108
108
  const refs = value
109
109
  .split(/\s/)
110
110
  .map(id => id.trim())
111
- .filter(_ => _);
111
+ .filter(Boolean);
112
112
  for (const ref of refs) {
113
113
  if (!idList.has(ref)) {
114
114
  report({
115
115
  scope: attr,
116
- line: (_k = attr.valueNode) === null || _k === void 0 ? void 0 : _k.startLine,
117
- col: (_l = attr.valueNode) === null || _l === void 0 ? void 0 : _l.startCol,
118
- raw: (_m = attr.valueNode) === null || _m === void 0 ? void 0 : _m.raw,
116
+ line: attr.valueNode?.startLine,
117
+ col: attr.valueNode?.startCol,
118
+ raw: attr.valueNode?.raw,
119
119
  message: t('Missing {0}', t('"{0*}" ID', ref)),
120
120
  });
121
121
  }
@@ -127,7 +127,6 @@ exports.default = (0, ml_core_1.createRule)({
127
127
  * @see https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
128
128
  */
129
129
  await document.walkOn('Element', el => {
130
- var _a, _b, _c, _d;
131
130
  if (el.rule.options.fragmentRefersNameAttr && hasDynamicName) {
132
131
  return;
133
132
  }
@@ -138,11 +137,11 @@ exports.default = (0, ml_core_1.createRule)({
138
137
  if (!href) {
139
138
  return;
140
139
  }
141
- const rawFragment = (_a = href.value.match(/^#(.+)/)) === null || _a === void 0 ? void 0 : _a[1];
140
+ const rawFragment = href.value.match(/^#(.+)/)?.[1];
142
141
  if (rawFragment == null) {
143
142
  return;
144
143
  }
145
- const decodedFragment = (0, shared_1.decodeHref)(rawFragment);
144
+ const decodedFragment = decodeHref(rawFragment);
146
145
  // > 2. If fragment is the empty string, then return the special value top of the document.
147
146
  // >
148
147
  // > 9. If decodedFragment is an ASCII case-insensitive match for the string top, then return the top of the document.
@@ -153,9 +152,9 @@ exports.default = (0, ml_core_1.createRule)({
153
152
  (el.rule.options.fragmentRefersNameAttr ? !nameList.has(decodedFragment) : true)) {
154
153
  report({
155
154
  scope: href,
156
- line: (_b = href.valueNode) === null || _b === void 0 ? void 0 : _b.startLine,
157
- col: (_c = href.valueNode) === null || _c === void 0 ? void 0 : _c.startCol,
158
- raw: (_d = href.valueNode) === null || _d === void 0 ? void 0 : _d.raw,
155
+ line: href.valueNode?.startLine,
156
+ col: href.valueNode?.startCol,
157
+ raw: href.valueNode?.raw,
159
158
  message: t('Missing {0}', t('"{0*}" ID', decodedFragment)),
160
159
  });
161
160
  }
@@ -1,5 +1,5 @@
1
1
  type Options = {
2
- ignore?: string | string[];
2
+ ignore?: string | string[];
3
3
  };
4
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
4
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
5
5
  export default _default;
@@ -1,8 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const helpers_1 = require("../helpers");
5
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ import { match } from '../helpers.js';
3
+ export default createRule({
4
+ meta: {
5
+ category: 'maintainability',
6
+ },
6
7
  defaultSeverity: 'warning',
7
8
  defaultOptions: {},
8
9
  async verify({ document, report, t }) {
@@ -17,7 +18,7 @@ exports.default = (0, ml_core_1.createRule)({
17
18
  : [];
18
19
  const name = attr.name;
19
20
  for (const ignore of ignoreList) {
20
- if ((0, helpers_1.match)(name, ignore)) {
21
+ if (match(name, ignore)) {
21
22
  return;
22
23
  }
23
24
  }
@@ -1,10 +1,4 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
1
+ import type { ChildNode, Options, Result, Specs } from './types.js';
2
2
  import type { PermittedContentChoice } from '@markuplint/ml-spec';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
- export declare function choice(
5
- pattern: ReadonlyDeep<PermittedContentChoice>,
6
- elements: readonly ChildNode[],
7
- specs: Specs,
8
- options: Options,
9
- depth: number,
10
- ): Result;
4
+ export declare function choice(pattern: ReadonlyDeep<PermittedContentChoice>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.choice = void 0;
4
- const debug_1 = require("./debug");
5
- const order_1 = require("./order");
6
- const utils_1 = require("./utils");
1
+ import { bgBlue, bgGreen, cmLog } from './debug.js';
2
+ import { order } from './order.js';
3
+ import { Collection, modelLog } from './utils.js';
7
4
  const indexes = new WeakMap();
8
- function choice(pattern,
5
+ export function choice(pattern,
9
6
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
7
  elements, specs, options, depth) {
11
- const choiceLog = debug_1.cmLog.extend(`choice#${depth}`);
12
- const collection = new utils_1.Collection(elements);
8
+ const choiceLog = cmLog.extend(`choice#${depth}`);
9
+ const collection = new Collection(elements);
13
10
  const unmatchedResults = [];
14
11
  let i = 0;
15
12
  for (const some of pattern.choice) {
16
- choiceLog('Patterns[%s]: %s', i, (0, utils_1.modelLog)(some, ''));
17
- const result = (0, order_1.order)(some, collection.unmatched, specs, options, depth + 1);
13
+ choiceLog('Patterns[%s]: %s', i, modelLog(some, ''));
14
+ const result = order(some, collection.unmatched, specs, options, depth + 1);
18
15
  if (result.type === 'MATCHED' ||
19
16
  result.type === 'MATCHED_ZERO' ||
20
- (result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length >= 1)) {
17
+ (result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length > 0)) {
21
18
  choiceLog('Results[%s]: %s', i, choiceLogString(pattern.choice, i));
22
19
  return {
23
20
  type: result.type,
@@ -34,7 +31,6 @@ elements, specs, options, depth) {
34
31
  i++;
35
32
  }
36
33
  const barelyMatchedResult = unmatchedResults.sort((a, b) => {
37
- var _c, _d, _e, _f;
38
34
  if (a.type !== b.type) {
39
35
  if (a.type === 'UNEXPECTED_EXTRA_NODE') {
40
36
  return -1;
@@ -47,8 +43,8 @@ elements, specs, options, depth) {
47
43
  if (computed1 !== 0) {
48
44
  return computed1;
49
45
  }
50
- const _a = (_d = (_c = a.hint.missing) === null || _c === void 0 ? void 0 : _c.barelyMatchedElements) !== null && _d !== void 0 ? _d : 0;
51
- const _b = (_f = (_e = b.hint.missing) === null || _e === void 0 ? void 0 : _e.barelyMatchedElements) !== null && _f !== void 0 ? _f : 0;
46
+ const _a = a.hint.missing?.barelyMatchedElements ?? 0;
47
+ const _b = b.hint.missing?.barelyMatchedElements ?? 0;
52
48
  const computed2 = _b - _a;
53
49
  return computed2;
54
50
  })[0];
@@ -68,15 +64,14 @@ elements, specs, options, depth) {
68
64
  hint: barelyMatchedResult.hint,
69
65
  };
70
66
  }
71
- exports.choice = choice;
72
67
  function choiceLogString(choice, index, barely = false) {
73
- const colorFn = barely ? debug_1.bgBlue : debug_1.bgGreen;
68
+ const colorFn = barely ? bgBlue : bgGreen;
74
69
  return choice
75
70
  .map((pattern, i) => {
76
71
  if (i === index) {
77
- return colorFn((0, utils_1.modelLog)(pattern, ''));
72
+ return colorFn(modelLog(pattern, ''));
78
73
  }
79
- return (0, utils_1.modelLog)(pattern, '');
74
+ return modelLog(pattern, '');
80
75
  })
81
76
  .join(', ');
82
77
  }
@@ -1,4 +1,4 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
1
+ import type { ChildNode, Options, Result, Specs } from './types.js';
2
2
  import type { PermittedContentPattern } from '@markuplint/ml-spec';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
4
  /**
@@ -11,10 +11,4 @@ import type { ReadonlyDeep } from 'type-fest';
11
11
  * @param depth
12
12
  * @returns
13
13
  */
14
- export declare function complexBranch(
15
- pattern: ReadonlyDeep<PermittedContentPattern>,
16
- elements: readonly ChildNode[],
17
- specs: Specs,
18
- options: Options,
19
- depth: number,
20
- ): Result;
14
+ export declare function complexBranch(pattern: ReadonlyDeep<PermittedContentPattern>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.complexBranch = void 0;
4
- const choice_1 = require("./choice");
5
- const count_pattern_1 = require("./count-pattern");
6
- const transparent_1 = require("./transparent");
7
- const utils_1 = require("./utils");
1
+ import { choice } from './choice.js';
2
+ import { countPattern } from './count-pattern.js';
3
+ import { transparent } from './transparent.js';
4
+ import { isChoice, isTransparent } from './utils.js';
8
5
  /**
9
6
  * Check content condition
10
7
  *
@@ -15,15 +12,14 @@ const utils_1 = require("./utils");
15
12
  * @param depth
16
13
  * @returns
17
14
  */
18
- function complexBranch(pattern,
15
+ export function complexBranch(pattern,
19
16
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
17
  elements, specs, options, depth) {
21
- if ((0, utils_1.isChoice)(pattern)) {
22
- return (0, choice_1.choice)(pattern, elements, specs, options, depth);
18
+ if (isChoice(pattern)) {
19
+ return choice(pattern, elements, specs, options, depth);
23
20
  }
24
- if ((0, utils_1.isTransparent)(pattern)) {
25
- return (0, transparent_1.transparent)(elements);
21
+ if (isTransparent(pattern)) {
22
+ return transparent(elements);
26
23
  }
27
- return (0, count_pattern_1.countPattern)(pattern, elements, specs, options, depth);
24
+ return countPattern(pattern, elements, specs, options, depth);
28
25
  }
29
- exports.complexBranch = complexBranch;
@@ -1,2 +1,2 @@
1
- import type { ContentModelResult, Element, Options, TagRule } from './types';
1
+ import type { ContentModelResult, Element, Options, TagRule } from './types.js';
2
2
  export declare function contentModel(el: Element, rules: readonly TagRule[], options: Options): ContentModelResult[];
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contentModel = void 0;
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const start_1 = require("./start");
6
- function contentModel(
1
+ import { getContentModel } from '@markuplint/ml-spec';
2
+ import { start } from './start.js';
3
+ export function contentModel(
7
4
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
5
  el, rules, options) {
9
- const model = createModel(el, rules);
6
+ const { model, specs } = createModel(el, rules);
10
7
  if (model == null) {
11
8
  return [
12
9
  {
@@ -17,16 +14,18 @@ el, rules, options) {
17
14
  },
18
15
  ];
19
16
  }
20
- const result = (0, start_1.start)(model, el, el.ownerMLDocument.specs, options);
17
+ const result = start(model, el, specs, options);
21
18
  return result;
22
19
  }
23
- exports.contentModel = contentModel;
24
20
  function createModel(
25
21
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
26
22
  el, rules) {
27
23
  const specs = cachedSpecs(el.ownerMLDocument.specs, rules);
28
- const model = (0, ml_spec_1.getContentModel)(el, specs.specs);
29
- return model;
24
+ const model = getContentModel(el, specs.specs);
25
+ return {
26
+ model,
27
+ specs,
28
+ };
30
29
  }
31
30
  const caches = new Map();
32
31
  function cachedSpecs(specs, rules) {
@@ -1,10 +1,5 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
2
- import type {
3
- PermittedContentOneOrMore,
4
- PermittedContentOptional,
5
- PermittedContentRequire,
6
- PermittedContentZeroOrMore,
7
- } from '@markuplint/ml-spec';
1
+ import type { ChildNode, Options, Result, Specs } from './types.js';
2
+ import type { PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentZeroOrMore } from '@markuplint/ml-spec';
8
3
  import type { ReadonlyDeep } from 'type-fest';
9
4
  /**
10
5
  * Check count
@@ -16,14 +11,4 @@ import type { ReadonlyDeep } from 'type-fest';
16
11
  * @param depth
17
12
  * @returns
18
13
  */
19
- export declare function countPattern(
20
- pattern:
21
- | ReadonlyDeep<PermittedContentOneOrMore>
22
- | ReadonlyDeep<PermittedContentOptional>
23
- | ReadonlyDeep<PermittedContentRequire>
24
- | ReadonlyDeep<PermittedContentZeroOrMore>,
25
- elements: readonly ChildNode[],
26
- specs: Specs,
27
- options: Options,
28
- depth: number,
29
- ): Result;
14
+ export declare function countPattern(pattern: ReadonlyDeep<PermittedContentOneOrMore> | ReadonlyDeep<PermittedContentOptional> | ReadonlyDeep<PermittedContentRequire> | ReadonlyDeep<PermittedContentZeroOrMore>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.countPattern = void 0;
4
- const debug_1 = require("./debug");
5
- const recursive_branch_1 = require("./recursive-branch");
6
- const utils_1 = require("./utils");
7
- const cLog = debug_1.cmLog.extend('countCompereResult');
1
+ import { cmLog } from './debug.js';
2
+ import { recursiveBranch } from './recursive-branch.js';
3
+ import { Collection, mergeHints, modelLog, normalizeModel } from './utils.js';
4
+ const cLog = cmLog.extend('countCompereResult');
8
5
  /**
9
6
  * Check count
10
7
  *
@@ -15,13 +12,13 @@ const cLog = debug_1.cmLog.extend('countCompereResult');
15
12
  * @param depth
16
13
  * @returns
17
14
  */
18
- function countPattern(pattern,
15
+ export function countPattern(pattern,
19
16
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
17
  elements, specs, options, depth) {
21
- const ptLog = debug_1.cmLog.extend(`countPattern#${depth}`);
22
- const collection = new utils_1.Collection(elements);
23
- const { model, min, max, repeat, missingType } = (0, utils_1.normalizeModel)(pattern);
24
- ptLog('Model:\n RegEx: %s\n Schema: %o', (0, utils_1.modelLog)(model, repeat), pattern);
18
+ const ptLog = cmLog.extend(`countPattern#${depth}`);
19
+ const collection = new Collection(elements);
20
+ const { model, min, max, repeat, missingType } = normalizeModel(pattern);
21
+ ptLog('Model:\n RegEx: %s\n Schema: %o', modelLog(model, repeat), pattern);
25
22
  let prevResult = null;
26
23
  let barelyResult = null;
27
24
  let loopCount = 0;
@@ -29,11 +26,11 @@ elements, specs, options, depth) {
29
26
  while (true) {
30
27
  loopCount++;
31
28
  ptLog('Check#%s: %s', loopCount, collection);
32
- const result = (0, recursive_branch_1.recursiveBranch)(model, collection.unmatched, specs, options, depth);
29
+ const result = recursiveBranch(model, collection.unmatched, specs, options, depth);
33
30
  const added = collection.addMatched(result.matched);
34
31
  const { matchedCount } = collection;
35
32
  if (result.type === 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY') {
36
- ptLog('MATCHED_ZERO:\n model: %s\n max: %s\n collection: %s\n matched element: %s', (0, utils_1.modelLog)(model, repeat), max, collection, matchedCount);
33
+ ptLog('MATCHED_ZERO:\n model: %s\n max: %s\n collection: %s\n matched element: %s', modelLog(model, repeat), max, collection, matchedCount);
37
34
  return compereResult({
38
35
  type: 'MATCHED_ZERO',
39
36
  matched: collection.matched,
@@ -45,14 +42,14 @@ elements, specs, options, depth) {
45
42
  }
46
43
  if (max < collection.matchedCount) {
47
44
  collection.max(max);
48
- ptLog('UNEXPECTED_EXTRA_NODE:\n model: %s\n max: %s\n collection: %s\n matched element: %s', (0, utils_1.modelLog)(model, repeat), max, collection, matchedCount);
45
+ ptLog('UNEXPECTED_EXTRA_NODE:\n model: %s\n max: %s\n collection: %s\n matched element: %s', modelLog(model, repeat), max, collection, matchedCount);
49
46
  return compereResult({
50
47
  type: 'UNEXPECTED_EXTRA_NODE',
51
48
  matched: collection.matched,
52
49
  unmatched: collection.unmatched,
53
50
  zeroMatch: result.zeroMatch,
54
51
  query: result.query,
55
- hint: (0, utils_1.mergeHints)(result.hint, { max }),
52
+ hint: mergeHints(result.hint, { max }),
56
53
  }, barelyResult);
57
54
  }
58
55
  if (prevResult) {
@@ -91,7 +88,7 @@ elements, specs, options, depth) {
91
88
  result.type === 'MISSING_NODE_ONE_OR_MORE' ||
92
89
  result.type === 'TRANSPARENT_MODEL_DISALLOWS'
93
90
  ? result.type
94
- : missingType !== null && missingType !== void 0 ? missingType : 'MISSING_NODE_REQUIRED';
91
+ : missingType ?? 'MISSING_NODE_REQUIRED';
95
92
  ptLog('%s(in %s); Needs %s', resultType, missingType, result.query);
96
93
  return compereResult({
97
94
  type: resultType,
@@ -99,7 +96,7 @@ elements, specs, options, depth) {
99
96
  unmatched: collection.unmatched,
100
97
  zeroMatch: result.zeroMatch,
101
98
  query: result.query,
102
- hint: (0, utils_1.mergeHints)(result.hint, {
99
+ hint: mergeHints(result.hint, {
103
100
  missing: {
104
101
  barelyMatchedElements: collection.matched.length,
105
102
  need: result.query,
@@ -115,7 +112,7 @@ elements, specs, options, depth) {
115
112
  unmatched: collection.unmatched,
116
113
  zeroMatch,
117
114
  query: result.query,
118
- hint: (0, utils_1.mergeHints)(result.hint, {
115
+ hint: mergeHints(result.hint, {
119
116
  missing: {
120
117
  barelyMatchedElements: collection.matched.length,
121
118
  need: result.query,
@@ -127,7 +124,7 @@ elements, specs, options, depth) {
127
124
  ptLog('continue⤴️ (add prev)');
128
125
  continue;
129
126
  }
130
- ptLog('%s:\n model: %s\n max: %s\n collection: %s\n matched element: %s', resultType, (0, utils_1.modelLog)(model, repeat), max, collection, matchedCount);
127
+ ptLog('%s:\n model: %s\n max: %s\n collection: %s\n matched element: %s', resultType, modelLog(model, repeat), max, collection, matchedCount);
131
128
  if (result.type === 'MISSING_NODE_REQUIRED' ||
132
129
  result.type === 'MISSING_NODE_ONE_OR_MORE' ||
133
130
  result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
@@ -143,20 +140,18 @@ elements, specs, options, depth) {
143
140
  return compereResult(matchedResult, barelyResult);
144
141
  }
145
142
  }
146
- exports.countPattern = countPattern;
147
143
  function compereResult(
148
144
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
149
145
  a,
150
146
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
151
147
  b) {
152
- var _a;
153
- cLog('current: %s %O\nbarely: %s %O', a.type, a.hint, b === null || b === void 0 ? void 0 : b.type, b === null || b === void 0 ? void 0 : b.hint);
148
+ cLog('current: %s %O\nbarely: %s %O', a.type, a.hint, b?.type, b?.hint);
154
149
  if (b == null) {
155
150
  return a;
156
151
  }
157
152
  if (a.type === 'MATCHED' || a.type === 'MATCHED_ZERO' || a.type === 'UNEXPECTED_EXTRA_NODE') {
158
153
  return a;
159
154
  }
160
- const result = (_a = [a, b].sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.hint.missing) === null || _c === void 0 ? void 0 : _c.barelyMatchedElements) !== null && _d !== void 0 ? _d : 0); })[0]) !== null && _a !== void 0 ? _a : a;
155
+ const result = [a, b].sort((a, b) => (b.hint.missing?.barelyMatchedElements ?? 0) - (a.hint.missing?.barelyMatchedElements ?? 0))[0] ?? a;
161
156
  return result;
162
157
  }
@@ -1,30 +1,30 @@
1
- /// <reference types="debug" />
2
- export declare const cmLog: import('debug').Debugger;
1
+ import type { Log } from '../debug.js';
2
+ export declare const cmLog: Log;
3
3
  export declare const bgGreen: {
4
- (): void;
5
- bold(): void;
4
+ (): void;
5
+ bold(): void;
6
6
  };
7
7
  export declare const green: {
8
- (): void;
9
- bold(): void;
8
+ (): void;
9
+ bold(): void;
10
10
  };
11
11
  export declare const bgRed: {
12
- (): void;
13
- bold(): void;
12
+ (): void;
13
+ bold(): void;
14
14
  };
15
15
  export declare const bgBlue: {
16
- (): void;
17
- bold(): void;
16
+ (): void;
17
+ bold(): void;
18
18
  };
19
19
  export declare const blue: {
20
- (): void;
21
- bold(): void;
20
+ (): void;
21
+ bold(): void;
22
22
  };
23
23
  export declare const bgMagenta: {
24
- (): void;
25
- bold(): void;
24
+ (): void;
25
+ bold(): void;
26
26
  };
27
27
  export declare const cyan: {
28
- (): void;
29
- bold(): void;
28
+ (): void;
29
+ bold(): void;
30
30
  };
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cyan = exports.bgMagenta = exports.blue = exports.bgBlue = exports.bgRed = exports.green = exports.bgGreen = exports.cmLog = void 0;
4
- const debug_1 = require("../debug");
5
- exports.cmLog = debug_1.log.extend('content-model');
1
+ import { log } from '../debug.js';
2
+ export const cmLog = log.extend('content-model');
6
3
  const fn = () => { };
7
4
  fn.bold = () => { };
8
- exports.bgGreen = fn;
9
- exports.green = fn;
10
- exports.bgRed = fn;
11
- exports.bgBlue = fn;
12
- exports.blue = fn;
13
- exports.bgMagenta = fn;
14
- exports.cyan = fn;
5
+ export const bgGreen = fn;
6
+ export const green = fn;
7
+ export const bgRed = fn;
8
+ export const bgBlue = fn;
9
+ export const blue = fn;
10
+ export const bgMagenta = fn;
11
+ export const cyan = fn;
@@ -1,3 +1,10 @@
1
- /// <reference types="debug" />
2
- export declare const cmLog: import('debug').Debugger;
3
- export { bgGreen, green, bgRed, bgBlue, blue, bgMagenta, cyan } from 'ansi-colors';
1
+ import type { Log } from '../debug.js';
2
+ import color from 'ansi-colors';
3
+ export declare const cmLog: Log;
4
+ export declare const bgGreen: color.StyleFunction;
5
+ export declare const green: color.StyleFunction;
6
+ export declare const bgRed: color.StyleFunction;
7
+ export declare const bgBlue: color.StyleFunction;
8
+ export declare const blue: color.StyleFunction;
9
+ export declare const bgMagenta: color.StyleFunction;
10
+ export declare const cyan: color.StyleFunction;