@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,13 +1,12 @@
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');
6
- var ansi_colors_1 = require("ansi-colors");
7
- Object.defineProperty(exports, "bgGreen", { enumerable: true, get: function () { return ansi_colors_1.bgGreen; } });
8
- Object.defineProperty(exports, "green", { enumerable: true, get: function () { return ansi_colors_1.green; } });
9
- Object.defineProperty(exports, "bgRed", { enumerable: true, get: function () { return ansi_colors_1.bgRed; } });
10
- Object.defineProperty(exports, "bgBlue", { enumerable: true, get: function () { return ansi_colors_1.bgBlue; } });
11
- Object.defineProperty(exports, "blue", { enumerable: true, get: function () { return ansi_colors_1.blue; } });
12
- Object.defineProperty(exports, "bgMagenta", { enumerable: true, get: function () { return ansi_colors_1.bgMagenta; } });
13
- Object.defineProperty(exports, "cyan", { enumerable: true, get: function () { return ansi_colors_1.cyan; } });
1
+ import color from 'ansi-colors';
2
+ import { log } from '../debug.js';
3
+ export const cmLog = log.extend('content-model');
4
+ /* eslint-disable import/no-named-as-default-member */
5
+ export const bgGreen = color.bgGreen;
6
+ export const green = color.green;
7
+ export const bgRed = color.bgRed;
8
+ export const bgBlue = color.bgBlue;
9
+ export const blue = color.blue;
10
+ export const bgMagenta = color.bgMagenta;
11
+ export const cyan = color.cyan;
12
+ /* eslint-enable import/no-named-as-default-member */
@@ -1,3 +1,3 @@
1
- import type { Options, TagRule } from './types';
2
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<TagRule[], Options>>;
1
+ import type { Options, TagRule } from './types.js';
2
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<TagRule[], Options>>;
3
3
  export default _default;
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const content_model_1 = require("./content-model");
5
- const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
6
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ import { contentModel } from './content-model.js';
3
+ import { transparentMode } from './represent-transparent-nodes.js';
4
+ export default createRule({
5
+ meta: {
6
+ category: 'validation',
7
+ },
7
8
  defaultValue: [],
8
9
  defaultOptions: {
9
10
  ignoreHasMutableChildren: true,
10
11
  },
11
12
  async verify({ document, report, t }) {
12
13
  await document.walkOn('Element', el => {
13
- var _a, _b, _c;
14
14
  if (el.rule.options.ignoreHasMutableChildren && el.hasMutableChildren()) {
15
15
  return;
16
16
  }
17
- const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.options);
17
+ const results = contentModel(el, el.rule.value, el.rule.options);
18
18
  for (const { type, scope, query, hint } of results) {
19
19
  let message = '';
20
20
  if (hint.max != null) {
@@ -49,10 +49,10 @@ exports.default = (0, ml_core_1.createRule)({
49
49
  break;
50
50
  }
51
51
  case 'UNEXPECTED_EXTRA_NODE': {
52
- const not = (_a = hint.not) !== null && _a !== void 0 ? _a : scope;
52
+ const not = hint.not ?? scope;
53
53
  message =
54
54
  message ||
55
- (represent_transparent_nodes_1.transparentMode.has(scope)
55
+ (transparentMode.has(scope)
56
56
  ? t('{0} is not allowed in {1} through the transparent model in this context', name(not, t), name(el, t))
57
57
  : t('{0} is not allowed in {1} in this context', name(not, t), name(el, t)));
58
58
  report({
@@ -62,8 +62,8 @@ exports.default = (0, ml_core_1.createRule)({
62
62
  break;
63
63
  }
64
64
  case 'TRANSPARENT_MODEL_DISALLOWS': {
65
- const not = (_b = hint.not) !== null && _b !== void 0 ? _b : scope;
66
- const tp = (_c = hint.transparent) !== null && _c !== void 0 ? _c : el;
65
+ const not = hint.not ?? scope;
66
+ const tp = hint.transparent ?? el;
67
67
  report({
68
68
  scope: not,
69
69
  message: t('{0} is {1} but {2}', name(tp, t), t('a {0}', 'transparent model'), t('also disallows {0} in this context', name(not, t))),
@@ -82,7 +82,7 @@ exports.default = (0, ml_core_1.createRule)({
82
82
  }
83
83
  }
84
84
  }
85
- represent_transparent_nodes_1.transparentMode.clear();
85
+ transparentMode.clear();
86
86
  });
87
87
  },
88
88
  });
@@ -1,8 +1,3 @@
1
- import type { ChildNode, Result, Specs } from './types';
1
+ import type { ChildNode, Result, Specs } from './types.js';
2
2
  export type SelectorResult = Result<'UNMATCHED_SELECTOR_BUT_MAY_EMPTY' | 'MISSING_NODE' | 'UNMATCHED_SELECTORS'>;
3
- export declare function matchesSelector(
4
- query: string,
5
- node: ChildNode | undefined,
6
- specs: Specs,
7
- depth: number,
8
- ): SelectorResult;
3
+ export declare function matchesSelector(query: string, node: ChildNode | undefined, specs: Specs, depth: number): SelectorResult;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchesSelector = void 0;
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const debug_1 = require("./debug");
6
- const utils_1 = require("./utils");
7
- function matchesSelector(query,
1
+ import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';
2
+ import { cmLog } from './debug.js';
3
+ import { cleanObject, matches } from './utils.js';
4
+ export function matchesSelector(query,
8
5
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
6
  node, specs, depth) {
10
- const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
7
+ const nodeLog = cmLog.extend(`node#${depth}`);
11
8
  const { selector, hasText, hasCustom } = optCondition(query, specs);
12
9
  if (node == null) {
13
10
  if (hasText) {
@@ -86,7 +83,7 @@ node, specs, depth) {
86
83
  hint: {},
87
84
  };
88
85
  }
89
- const result = (0, utils_1.matches)(selector, node, specs);
86
+ const result = matches(selector, node, specs);
90
87
  nodeLog('%s.matches(%s) => %s', node.raw, query, result.matched);
91
88
  if (result.matched) {
92
89
  return {
@@ -105,7 +102,7 @@ node, specs, depth) {
105
102
  unmatched: [node],
106
103
  zeroMatch: true,
107
104
  query,
108
- hint: (0, utils_1.cleanObject)({
105
+ hint: cleanObject({
109
106
  not: result.not,
110
107
  }),
111
108
  };
@@ -116,7 +113,7 @@ node, specs, depth) {
116
113
  unmatched: [node],
117
114
  zeroMatch: false,
118
115
  query,
119
- hint: (0, utils_1.cleanObject)({
116
+ hint: cleanObject({
120
117
  not: result.not,
121
118
  }),
122
119
  };
@@ -130,7 +127,6 @@ node, specs, depth) {
130
127
  hint: {},
131
128
  };
132
129
  }
133
- exports.matchesSelector = matchesSelector;
134
130
  const conditionWithoutSpecs = {
135
131
  '#custom': {
136
132
  selector: '#custom',
@@ -145,22 +141,21 @@ const conditionWithoutSpecs = {
145
141
  };
146
142
  const optConditionSpecsBaseCaches = new Map();
147
143
  function optCondition(query, specs) {
148
- var _a;
149
144
  const condWithoutSpecs = conditionWithoutSpecs[query];
150
145
  if (condWithoutSpecs) {
151
146
  return condWithoutSpecs;
152
147
  }
153
- const queryCaches = (_a = optConditionSpecsBaseCaches.get(specs)) !== null && _a !== void 0 ? _a : new Map();
148
+ const queryCaches = optConditionSpecsBaseCaches.get(specs) ?? new Map();
154
149
  const cached = queryCaches.get(query);
155
150
  if (cached) {
156
151
  return cached;
157
152
  }
158
153
  let hasCustom = false;
159
154
  let hasText = false;
160
- const selector = query.replace(/^(?::model\(([^)]+)\)|#([a-z-]+))(.*)$/, (_, $model, _model, $last) => {
161
- const _selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${$model !== null && $model !== void 0 ? $model : _model}`, specs.def);
155
+ const selector = query.replace(/^:model\(([^)]+)\)|^#([a-z-]+)/, (_, $model, _model) => {
156
+ const _selectors = contentModelCategoryToTagNames(`#${$model ?? _model}`, specs.def);
162
157
  if (_selectors.length === 0) {
163
- throw new Error(`${$model !== null && $model !== void 0 ? $model : _model} is empty`);
158
+ throw new Error(`${$model ?? _model} is empty`);
164
159
  }
165
160
  const selectors = [];
166
161
  for (const selector of _selectors) {
@@ -174,7 +169,7 @@ function optCondition(query, specs) {
174
169
  }
175
170
  selectors.push(selector);
176
171
  }
177
- return `:is(${selectors.join(',')})${$last !== null && $last !== void 0 ? $last : ''}`;
172
+ return `:is(${selectors.join(',')})`;
178
173
  });
179
174
  const result = {
180
175
  selector,
@@ -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 order(
15
- contents: ReadonlyDeep<PermittedContentPattern[]>,
16
- nodes: readonly ChildNode[],
17
- specs: Specs,
18
- options: Options,
19
- depth: number,
20
- ): Result;
14
+ export declare function order(contents: ReadonlyDeep<PermittedContentPattern[]>, nodes: 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.order = void 0;
4
- const helpers_1 = require("../helpers");
5
- const complex_branch_1 = require("./complex-branch");
6
- const debug_1 = require("./debug");
7
- const utils_1 = require("./utils");
1
+ import { deepCopy } from '../helpers.js';
2
+ import { complexBranch } from './complex-branch.js';
3
+ import { cmLog } from './debug.js';
4
+ import { Collection, mergeHints, modelLog } from './utils.js';
8
5
  /**
9
6
  * Check ordered array
10
7
  *
@@ -15,22 +12,21 @@ const utils_1 = require("./utils");
15
12
  * @param depth
16
13
  * @returns
17
14
  */
18
- function order(contents,
15
+ export function order(contents,
19
16
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
17
  nodes, specs, options, depth) {
21
- var _a, _b, _c, _d, _e;
22
- const orderLog = debug_1.cmLog.extend(`order#${depth}`);
23
- const btLog = debug_1.cmLog.extend(`backtrack#${depth}`);
24
- const patterns = (0, helpers_1.deepCopy)(contents);
25
- const collection = new utils_1.Collection(nodes);
26
- orderLog('Model:\n RegEx: %s\n Schema: %o', (0, utils_1.modelLog)(patterns, ''), patterns);
18
+ const orderLog = cmLog.extend(`order#${depth}`);
19
+ const btLog = cmLog.extend(`backtrack#${depth}`);
20
+ const patterns = deepCopy(contents);
21
+ const collection = new Collection(nodes);
22
+ orderLog('Model:\n RegEx: %s\n Schema: %o', modelLog(patterns, ''), patterns);
27
23
  orderLog('Starts: %s', collection);
28
24
  let result = undefined;
29
25
  let backtrackMode = false;
30
26
  let afterBacktrack = false;
31
27
  const unmatchedResults = [];
32
28
  while (patterns.length > 0 && patterns[0]) {
33
- result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
29
+ result = complexBranch(patterns[0], collection.unmatched, specs, options, depth);
34
30
  collection.addMatched(result.matched);
35
31
  if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
36
32
  unmatchedResults.push(result);
@@ -45,16 +41,16 @@ nodes, specs, options, depth) {
45
41
  if (!barelyMatchedResult) {
46
42
  throw new Error('Unreachable code');
47
43
  }
48
- orderLog('Result (%s): %s%s', result.type, collection.toString(true), ((_a = barelyMatchedResult.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) != null
49
- ? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
50
- : '');
44
+ orderLog('Result (%s): %s%s', result.type, collection.toString(true), barelyMatchedResult.hint.missing?.barelyMatchedElements == null
45
+ ? ''
46
+ : `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`);
51
47
  return {
52
48
  type: barelyMatchedResult.type,
53
49
  matched: collection.matched,
54
50
  unmatched: collection.unmatched,
55
51
  zeroMatch: barelyMatchedResult.zeroMatch,
56
52
  query: barelyMatchedResult.query,
57
- hint: (0, utils_1.mergeHints)(barelyMatchedResult.hint, {
53
+ hint: mergeHints(barelyMatchedResult.hint, {
58
54
  missing: {
59
55
  barelyMatchedElements: collection.matched.length,
60
56
  need: barelyMatchedResult.query,
@@ -81,8 +77,8 @@ nodes, specs, options, depth) {
81
77
  matched: collection.matched,
82
78
  unmatched: collection.unmatched,
83
79
  zeroMatch: false,
84
- query: (_b = result === null || result === void 0 ? void 0 : result.query) !== null && _b !== void 0 ? _b : 'N/A',
85
- hint: (_c = result === null || result === void 0 ? void 0 : result.hint) !== null && _c !== void 0 ? _c : {},
80
+ query: result?.query ?? 'N/A',
81
+ hint: result?.hint ?? {},
86
82
  };
87
83
  }
88
84
  const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
@@ -92,8 +88,7 @@ nodes, specs, options, depth) {
92
88
  matched: collection.matched,
93
89
  unmatched: collection.unmatched,
94
90
  zeroMatch: false,
95
- query: (_d = result === null || result === void 0 ? void 0 : result.query) !== null && _d !== void 0 ? _d : 'N/A',
96
- hint: (_e = result === null || result === void 0 ? void 0 : result.hint) !== null && _e !== void 0 ? _e : {},
91
+ query: result?.query ?? 'N/A',
92
+ hint: result?.hint ?? {},
97
93
  };
98
94
  }
99
- exports.order = order;
@@ -1,11 +1,5 @@
1
- import type { SelectorResult } from './matches-selector';
2
- import type { ChildNode, Options, Specs } from './types';
1
+ import type { SelectorResult } from './matches-selector.js';
2
+ import type { ChildNode, Options, Specs } from './types.js';
3
3
  import type { PermittedContentPattern, Model } from '@markuplint/ml-spec';
4
4
  import type { ReadonlyDeep } from 'type-fest';
5
- export declare function recursiveBranch(
6
- model: ReadonlyDeep<Model | PermittedContentPattern[]>,
7
- nodes: readonly ChildNode[],
8
- specs: Specs,
9
- options: Options,
10
- depth: number,
11
- ): SelectorResult;
5
+ export declare function recursiveBranch(model: ReadonlyDeep<Model | PermittedContentPattern[]>, nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
@@ -1,22 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.recursiveBranch = void 0;
4
- const matches_selector_1 = require("./matches-selector");
5
- const order_1 = require("./order");
6
- const utils_1 = require("./utils");
7
- function recursiveBranch(model,
1
+ import { matchesSelector } from './matches-selector.js';
2
+ import { order } from './order.js';
3
+ import { Collection, isModel } from './utils.js';
4
+ export function recursiveBranch(model,
8
5
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
6
  nodes, specs, options, depth) {
10
- if (!(0, utils_1.isModel)(model)) {
11
- return (0, order_1.order)(model, nodes, specs, options, depth + 1);
7
+ if (!isModel(model)) {
8
+ return order(model, nodes, specs, options, depth + 1);
12
9
  }
13
10
  if (typeof model === 'string') {
14
- return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, depth);
11
+ return matchesSelector(model, nodes[0], specs, depth);
15
12
  }
16
- const collection = new utils_1.Collection(nodes);
13
+ const collection = new Collection(nodes);
17
14
  let lastUnmatched = null;
18
15
  for (const query of model) {
19
- const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, depth);
16
+ const result = matchesSelector(query, collection.unmatched[0], specs, depth);
20
17
  collection.addMatched(result.matched);
21
18
  if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
22
19
  return {
@@ -42,4 +39,3 @@ nodes, specs, options, depth) {
42
39
  }
43
40
  return lastUnmatched;
44
41
  }
45
- exports.recursiveBranch = recursiveBranch;
@@ -1,10 +1,6 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
1
+ import type { ChildNode, Options, Result, Specs } from './types.js';
2
2
  export declare const transparentMode: Map<ChildNode, true>;
3
- export declare function representTransparentNodes(
4
- nodes: ChildNode[],
5
- specs: Specs,
6
- options: Options,
7
- ): {
8
- nodes: ChildNode[];
9
- errors: Result[];
3
+ export declare function representTransparentNodes(nodes: ChildNode[], specs: Specs, options: Options): {
4
+ nodes: ChildNode[];
5
+ errors: Result[];
10
6
  };
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.representTransparentNodes = exports.transparentMode = void 0;
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const order_1 = require("./order");
6
- const utils_1 = require("./utils");
7
- exports.transparentMode = new Map();
8
- function representTransparentNodes(
1
+ import { getContentModel } from '@markuplint/ml-spec';
2
+ import { order } from './order.js';
3
+ import { Collection, getChildNodesWithoutWhitespaces, isTransparent, matches } from './utils.js';
4
+ export const transparentMode = new Map();
5
+ export function representTransparentNodes(
9
6
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
7
  nodes, specs, options) {
11
- var _a;
12
8
  const result = [];
13
9
  const errors = [];
14
- const parent = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement;
10
+ const parent = nodes[0]?.parentElement;
15
11
  if (parent) {
16
12
  const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
17
13
  errors.push(...parentErrors);
@@ -21,37 +17,37 @@ nodes, specs, options) {
21
17
  result.push(node);
22
18
  continue;
23
19
  }
24
- const models = (0, ml_spec_1.getContentModel)(node, specs.specs);
20
+ const models = getContentModel(node, specs.specs);
25
21
  if (models == null || typeof models === 'boolean') {
26
22
  result.push(node);
27
23
  continue;
28
24
  }
29
- const noTransparentModels = models.filter(m => !(0, utils_1.isTransparent)(m));
25
+ const noTransparentModels = models.filter(m => !isTransparent(m));
30
26
  if (noTransparentModels.length === models.length) {
31
27
  result.push(node);
32
28
  continue;
33
29
  }
34
- const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
30
+ const collection = new Collection(getChildNodesWithoutWhitespaces(node));
35
31
  let unmatched;
36
32
  if (noTransparentModels.length > 0) {
37
- const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
33
+ const result = order(noTransparentModels, collection.unmatched, specs, options, Number.POSITIVE_INFINITY);
38
34
  unmatched = result.unmatched;
39
35
  }
40
36
  else {
41
37
  unmatched = collection.unmatched;
42
38
  }
43
- const transparent = models.find(m => (0, utils_1.isTransparent)(m));
44
- if (!transparent || !(0, utils_1.isTransparent)(transparent)) {
39
+ const transparent = models.find(m => isTransparent(m));
40
+ if (!transparent || !isTransparent(transparent)) {
45
41
  throw new Error('Unreachable code');
46
42
  }
47
43
  for (const _child of unmatched) {
48
44
  const child = _child;
49
- if (exports.transparentMode.has(child)) {
45
+ if (transparentMode.has(child)) {
50
46
  continue;
51
47
  }
52
- exports.transparentMode.set(child, true);
48
+ transparentMode.set(child, true);
53
49
  if (child.is(child.ELEMENT_NODE)) {
54
- const transparentCondMatched = (0, utils_1.matches)(transparent.transparent, child, specs);
50
+ const transparentCondMatched = matches(transparent.transparent, child, specs);
55
51
  if (!transparentCondMatched.matched) {
56
52
  errors.push({
57
53
  type: 'TRANSPARENT_MODEL_DISALLOWS',
@@ -75,4 +71,3 @@ nodes, specs, options) {
75
71
  errors,
76
72
  };
77
73
  }
78
- exports.representTransparentNodes = representTransparentNodes;
@@ -1,4 +1,4 @@
1
- import type { ContentModelResult, Element, Options, Specs } from './types';
1
+ import type { ContentModelResult, Element, Options, Specs } from './types.js';
2
2
  import type { ContentModel } from '@markuplint/ml-spec';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
4
  /**
@@ -10,9 +10,4 @@ import type { ReadonlyDeep } from 'type-fest';
10
10
  * @param options
11
11
  * @returns
12
12
  */
13
- export declare function start(
14
- contents: ReadonlyDeep<ContentModel['contents']>,
15
- el: Element,
16
- specs: Specs,
17
- options: Options,
18
- ): ContentModelResult[];
13
+ export declare function start(contents: ReadonlyDeep<ContentModel['contents']>, el: Element, specs: Specs, options: Options): ContentModelResult[];
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.start = void 0;
4
- const order_1 = require("./order");
5
- const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
6
- const utils_1 = require("./utils");
1
+ import { order } from './order.js';
2
+ import { representTransparentNodes } from './represent-transparent-nodes.js';
3
+ import { getChildNodesWithoutWhitespaces } from './utils.js';
7
4
  /**
8
5
  * Check start
9
6
  *
@@ -13,10 +10,9 @@ const utils_1 = require("./utils");
13
10
  * @param options
14
11
  * @returns
15
12
  */
16
- function start(contents,
13
+ export function start(contents,
17
14
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
18
15
  el, specs, options) {
19
- var _a;
20
16
  if (contents === false) {
21
17
  if (el.childNodes.length > 0) {
22
18
  return [
@@ -48,26 +44,22 @@ el, specs, options) {
48
44
  },
49
45
  ];
50
46
  }
51
- const { nodes, errors } = (0, represent_transparent_nodes_1.representTransparentNodes)((0, utils_1.getChildNodesWithoutWhitespaces)(el), specs, options);
52
- const result = (0, order_1.order)(contents, nodes, specs, options, 0);
47
+ const { nodes, errors } = representTransparentNodes(getChildNodesWithoutWhitespaces(el), specs, options);
48
+ const result = order(contents, nodes, specs, options, 0);
53
49
  return [
54
50
  {
55
51
  type: result.type,
56
52
  scope: result.type === 'MISSING_NODE_REQUIRED' || result.type === 'MISSING_NODE_ONE_OR_MORE'
57
53
  ? el
58
- : (_a = result.unmatched[0]) !== null && _a !== void 0 ? _a : el,
54
+ : result.unmatched[0] ?? el,
59
55
  query: result.query,
60
56
  hint: result.hint,
61
57
  },
62
- ...errors.map(error => {
63
- var _a;
64
- return ({
65
- type: error.type,
66
- scope: (_a = error.unmatched[0]) !== null && _a !== void 0 ? _a : el,
67
- query: error.query,
68
- hint: error.hint,
69
- });
70
- }),
58
+ ...errors.map(error => ({
59
+ type: error.type,
60
+ scope: error.unmatched[0] ?? el,
61
+ query: error.query,
62
+ hint: error.hint,
63
+ })),
71
64
  ];
72
65
  }
73
- exports.start = start;
@@ -1,2 +1,2 @@
1
- import type { ChildNode, Result } from './types';
1
+ import type { ChildNode, Result } from './types.js';
2
2
  export declare function transparent(nodes: readonly ChildNode[]): Result;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transparent = void 0;
4
- const debug_1 = require("./debug");
5
- const transparentLog = debug_1.cmLog.extend('transparent');
6
- function transparent(
1
+ import { cmLog } from './debug.js';
2
+ const transparentLog = cmLog.extend('transparent');
3
+ export function transparent(
7
4
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
5
  nodes) {
9
- var _a, _b;
10
- if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
6
+ if (nodes.length === 0 || nodes[0]?.parentElement?.parentElement) {
11
7
  transparentLog('Skipped');
12
8
  return {
13
9
  type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
14
- matched: nodes.slice(),
10
+ matched: [...nodes],
15
11
  unmatched: [],
16
12
  zeroMatch: nodes.length === 0,
17
13
  query: 'transparent',
@@ -21,11 +17,10 @@ nodes) {
21
17
  transparentLog('Transparent model element is component root');
22
18
  return {
23
19
  type: 'MATCHED',
24
- matched: nodes.slice(),
20
+ matched: [...nodes],
25
21
  unmatched: [],
26
22
  zeroMatch: false,
27
23
  query: 'transparent',
28
24
  hint: {},
29
25
  };
30
26
  }
31
- exports.transparent = transparent;