@markuplint/rules 3.0.0-dev.24 → 3.0.0-dev.290

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 (135) hide show
  1. package/lib/attr-check.d.ts +3 -2
  2. package/lib/attr-check.js +42 -38
  3. package/lib/attr-duplication/index.d.ts +1 -1
  4. package/lib/attr-duplication/index.js +3 -5
  5. package/lib/attr-value-quotes/index.d.ts +1 -1
  6. package/lib/attr-value-quotes/index.js +5 -9
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  8. package/lib/case-sensitive-attr-name/index.js +9 -13
  9. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  10. package/lib/case-sensitive-tag-name/index.js +2 -4
  11. package/lib/character-reference/index.d.ts +1 -1
  12. package/lib/character-reference/index.js +7 -9
  13. package/lib/class-naming/index.d.ts +1 -1
  14. package/lib/class-naming/index.js +9 -13
  15. package/lib/create-message.d.ts +3 -2
  16. package/lib/create-message.js +15 -17
  17. package/lib/debug.js +2 -6
  18. package/lib/deprecated-attr/index.d.ts +1 -1
  19. package/lib/deprecated-attr/index.js +6 -9
  20. package/lib/deprecated-element/index.d.ts +1 -1
  21. package/lib/deprecated-element/index.js +5 -7
  22. package/lib/disallowed-element/index.d.ts +1 -1
  23. package/lib/disallowed-element/index.js +2 -4
  24. package/lib/doctype/index.d.ts +1 -1
  25. package/lib/doctype/index.js +2 -4
  26. package/lib/end-tag/index.d.ts +1 -1
  27. package/lib/end-tag/index.js +5 -8
  28. package/lib/helpers.d.ts +10 -13
  29. package/lib/helpers.js +39 -37
  30. package/lib/id-duplication/index.d.ts +1 -1
  31. package/lib/id-duplication/index.js +2 -4
  32. package/lib/index.d.ts +102 -3
  33. package/lib/index.js +64 -62
  34. package/lib/ineffective-attr/index.d.ts +1 -1
  35. package/lib/ineffective-attr/index.js +5 -10
  36. package/lib/invalid-attr/index.d.ts +25 -5
  37. package/lib/invalid-attr/index.js +166 -43
  38. package/lib/label-has-control/index.d.ts +1 -1
  39. package/lib/label-has-control/index.js +2 -4
  40. package/lib/landmark-roles/index.d.ts +1 -1
  41. package/lib/landmark-roles/index.js +10 -9
  42. package/lib/no-boolean-attr-value/index.d.ts +1 -1
  43. package/lib/no-boolean-attr-value/index.js +6 -9
  44. package/lib/no-default-value/index.d.ts +1 -1
  45. package/lib/no-default-value/index.js +9 -12
  46. package/lib/no-empty-palpable-content/index.d.ts +1 -1
  47. package/lib/no-empty-palpable-content/index.js +13 -7
  48. package/lib/no-hard-code-id/index.d.ts +1 -1
  49. package/lib/no-hard-code-id/index.js +2 -4
  50. package/lib/no-refer-to-non-existent-id/index.d.ts +4 -4
  51. package/lib/no-refer-to-non-existent-id/index.js +79 -23
  52. package/lib/no-use-event-handler-attr/index.d.ts +1 -1
  53. package/lib/no-use-event-handler-attr/index.js +4 -6
  54. package/lib/permitted-contents/choice.d.ts +3 -2
  55. package/lib/permitted-contents/choice.js +54 -14
  56. package/lib/permitted-contents/complex-branch.d.ts +3 -2
  57. package/lib/permitted-contents/complex-branch.js +12 -14
  58. package/lib/permitted-contents/content-model.d.ts +2 -2
  59. package/lib/permitted-contents/content-model.js +11 -11
  60. package/lib/permitted-contents/count-pattern.d.ts +3 -2
  61. package/lib/permitted-contents/count-pattern.js +76 -74
  62. package/lib/permitted-contents/debug.browser.js +9 -12
  63. package/lib/permitted-contents/debug.d.ts +8 -1
  64. package/lib/permitted-contents/debug.js +12 -13
  65. package/lib/permitted-contents/index.d.ts +2 -2
  66. package/lib/permitted-contents/index.js +18 -24
  67. package/lib/permitted-contents/matches-selector.d.ts +2 -2
  68. package/lib/permitted-contents/matches-selector.js +17 -20
  69. package/lib/permitted-contents/order.d.ts +3 -2
  70. package/lib/permitted-contents/order.js +33 -28
  71. package/lib/permitted-contents/recursive-branch.d.ts +4 -3
  72. package/lib/permitted-contents/recursive-branch.js +11 -13
  73. package/lib/permitted-contents/represent-transparent-nodes.d.ts +1 -1
  74. package/lib/permitted-contents/represent-transparent-nodes.js +18 -21
  75. package/lib/permitted-contents/start.d.ts +3 -2
  76. package/lib/permitted-contents/start.js +16 -22
  77. package/lib/permitted-contents/transparent.d.ts +2 -2
  78. package/lib/permitted-contents/transparent.js +6 -9
  79. package/lib/permitted-contents/types.d.ts +20 -13
  80. package/lib/permitted-contents/types.js +1 -2
  81. package/lib/permitted-contents/utils.d.ts +27 -8
  82. package/lib/permitted-contents/utils.js +164 -65
  83. package/lib/placeholder-label-option/index.d.ts +2 -0
  84. package/lib/placeholder-label-option/index.js +84 -0
  85. package/lib/require-accessible-name/index.d.ts +1 -1
  86. package/lib/require-accessible-name/index.js +10 -13
  87. package/lib/require-datetime/index.d.ts +6 -0
  88. package/lib/require-datetime/index.js +32 -0
  89. package/lib/require-datetime/types.d.ts +10 -0
  90. package/lib/require-datetime/types.js +1 -0
  91. package/lib/require-datetime/utils.d.ts +11 -0
  92. package/lib/require-datetime/utils.js +130 -0
  93. package/lib/required-attr/index.d.ts +2 -2
  94. package/lib/required-attr/index.js +24 -24
  95. package/lib/required-element/index.d.ts +1 -1
  96. package/lib/required-element/index.js +3 -5
  97. package/lib/required-h1/index.d.ts +1 -1
  98. package/lib/required-h1/index.js +4 -6
  99. package/lib/use-list/index.d.ts +2 -2
  100. package/lib/use-list/index.js +7 -9
  101. package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
  102. package/lib/wai-aria/checkings/abstract-role.js +5 -10
  103. package/lib/wai-aria/checkings/default-value.d.ts +2 -2
  104. package/lib/wai-aria/checkings/default-value.js +2 -6
  105. package/lib/wai-aria/checkings/deprecated-props.d.ts +2 -2
  106. package/lib/wai-aria/checkings/deprecated-props.js +3 -8
  107. package/lib/wai-aria/checkings/disallowed-prop.d.ts +2 -2
  108. package/lib/wai-aria/checkings/disallowed-prop.js +27 -8
  109. package/lib/wai-aria/checkings/implicit-props.d.ts +3 -3
  110. package/lib/wai-aria/checkings/implicit-props.js +7 -11
  111. package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
  112. package/lib/wai-aria/checkings/implicit-role.js +4 -9
  113. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
  114. package/lib/wai-aria/checkings/interaction-in-hidden.js +7 -9
  115. package/lib/wai-aria/checkings/no-global-prop.d.ts +2 -2
  116. package/lib/wai-aria/checkings/no-global-prop.js +2 -7
  117. package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
  118. package/lib/wai-aria/checkings/non-existent-role.js +4 -9
  119. package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
  120. package/lib/wai-aria/checkings/permitted-roles.js +4 -9
  121. package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
  122. package/lib/wai-aria/checkings/presentational-children.js +7 -10
  123. package/lib/wai-aria/checkings/required-owned-elements.d.ts +1 -1
  124. package/lib/wai-aria/checkings/required-owned-elements.js +10 -12
  125. package/lib/wai-aria/checkings/required-prop.d.ts +2 -2
  126. package/lib/wai-aria/checkings/required-prop.js +2 -7
  127. package/lib/wai-aria/checkings/value.d.ts +3 -3
  128. package/lib/wai-aria/checkings/value.js +7 -11
  129. package/lib/wai-aria/index.d.ts +2 -2
  130. package/lib/wai-aria/index.js +38 -39
  131. package/lib/wai-aria/types.js +1 -2
  132. package/package.json +21 -14
  133. package/schema.json +6 -0
  134. package/tsconfig.test.json +0 -3
  135. package/tsconfig.tsbuildinfo +0 -1
@@ -1,3 +1,10 @@
1
1
  /// <reference types="debug" />
2
+ import color from 'ansi-colors';
2
3
  export declare const cmLog: import("debug").Debugger;
3
- export { bgGreen, green, bgRed, bgBlue, blue, bgMagenta, cyan } from 'ansi-colors';
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;
@@ -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: 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,32 +1,24 @@
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({
7
5
  defaultValue: [],
8
6
  defaultOptions: {
9
7
  ignoreHasMutableChildren: true,
10
8
  },
11
9
  async verify({ document, report, t }) {
12
10
  await document.walkOn('Element', el => {
13
- var _a, _b, _c;
14
- if (!el.rule.value) {
15
- return;
16
- }
17
11
  if (el.rule.options.ignoreHasMutableChildren && el.hasMutableChildren()) {
18
12
  return;
19
13
  }
20
- const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.options);
14
+ const results = contentModel(el, el.rule.value, el.rule.options);
21
15
  for (const { type, scope, query, hint } of results) {
22
16
  let message = '';
23
- if (hint) {
24
- if (hint.max != null) {
25
- message =
26
- t('there is more content than it needs') +
27
- t('. ') +
28
- t('the max number of elements required is {0}', `${hint.max}`);
29
- }
17
+ if (hint.max != null) {
18
+ message =
19
+ t('there is more content than it needs') +
20
+ t('. ') +
21
+ t('the max number of elements required is {0}', `${hint.max}`);
30
22
  }
31
23
  switch (type) {
32
24
  case 'MATCHED':
@@ -54,10 +46,10 @@ exports.default = (0, ml_core_1.createRule)({
54
46
  break;
55
47
  }
56
48
  case 'UNEXPECTED_EXTRA_NODE': {
57
- const not = (_a = hint.not) !== null && _a !== void 0 ? _a : scope;
49
+ const not = hint.not ?? scope;
58
50
  message =
59
51
  message ||
60
- (represent_transparent_nodes_1.transparentMode.has(scope)
52
+ (transparentMode.has(scope)
61
53
  ? t('{0} is not allowed in {1} through the transparent model in this context', name(not, t), name(el, t))
62
54
  : t('{0} is not allowed in {1} in this context', name(not, t), name(el, t)));
63
55
  report({
@@ -67,8 +59,8 @@ exports.default = (0, ml_core_1.createRule)({
67
59
  break;
68
60
  }
69
61
  case 'TRANSPARENT_MODEL_DISALLOWS': {
70
- const not = (_b = hint.not) !== null && _b !== void 0 ? _b : scope;
71
- const tp = (_c = hint.transparent) !== null && _c !== void 0 ? _c : el;
62
+ const not = hint.not ?? scope;
63
+ const tp = hint.transparent ?? el;
72
64
  report({
73
65
  scope: not,
74
66
  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))),
@@ -87,11 +79,13 @@ exports.default = (0, ml_core_1.createRule)({
87
79
  }
88
80
  }
89
81
  }
90
- represent_transparent_nodes_1.transparentMode.clear();
82
+ transparentMode.clear();
91
83
  });
92
84
  },
93
85
  });
94
- function name(scope, t) {
86
+ function name(
87
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
88
+ scope, t) {
95
89
  if (scope.is(scope.ELEMENT_NODE)) {
96
90
  return t('the "{0}" {1}', scope.localName, 'element');
97
91
  }
@@ -1,3 +1,3 @@
1
- import type { ChildNode, Options, 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(query: string, node: ChildNode | undefined, specs: Specs, options: Options, depth: number): SelectorResult;
3
+ export declare function matchesSelector(query: string, node: ChildNode | undefined, specs: Specs, depth: number): SelectorResult;
@@ -1,18 +1,17 @@
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, node, specs, options, depth) {
8
- const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
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,
5
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
+ node, specs, depth) {
7
+ const nodeLog = cmLog.extend(`node#${depth}`);
9
8
  const { selector, hasText, hasCustom } = optCondition(query, specs);
10
9
  if (node == null) {
11
10
  if (hasText) {
12
11
  nodeLog('<#text>.matches(%s) => ""', query);
13
12
  return {
14
13
  type: 'MATCHED_ZERO',
15
- matched: node ? [node] : [],
14
+ matched: [],
16
15
  unmatched: [],
17
16
  zeroMatch: true,
18
17
  query,
@@ -84,7 +83,7 @@ function matchesSelector(query, node, specs, options, depth) {
84
83
  hint: {},
85
84
  };
86
85
  }
87
- const result = (0, utils_1.matches)(selector, node, specs);
86
+ const result = matches(selector, node, specs);
88
87
  nodeLog('%s.matches(%s) => %s', node.raw, query, result.matched);
89
88
  if (result.matched) {
90
89
  return {
@@ -103,9 +102,9 @@ function matchesSelector(query, node, specs, options, depth) {
103
102
  unmatched: [node],
104
103
  zeroMatch: true,
105
104
  query,
106
- hint: {
105
+ hint: cleanObject({
107
106
  not: result.not,
108
- },
107
+ }),
109
108
  };
110
109
  }
111
110
  return {
@@ -114,9 +113,9 @@ function matchesSelector(query, node, specs, options, depth) {
114
113
  unmatched: [node],
115
114
  zeroMatch: false,
116
115
  query,
117
- hint: {
116
+ hint: cleanObject({
118
117
  not: result.not,
119
- },
118
+ }),
120
119
  };
121
120
  }
122
121
  return {
@@ -128,7 +127,6 @@ function matchesSelector(query, node, specs, options, depth) {
128
127
  hint: {},
129
128
  };
130
129
  }
131
- exports.matchesSelector = matchesSelector;
132
130
  const conditionWithoutSpecs = {
133
131
  '#custom': {
134
132
  selector: '#custom',
@@ -143,12 +141,11 @@ const conditionWithoutSpecs = {
143
141
  };
144
142
  const optConditionSpecsBaseCaches = new Map();
145
143
  function optCondition(query, specs) {
146
- var _a;
147
144
  const condWithoutSpecs = conditionWithoutSpecs[query];
148
145
  if (condWithoutSpecs) {
149
146
  return condWithoutSpecs;
150
147
  }
151
- const queryCaches = (_a = optConditionSpecsBaseCaches.get(specs)) !== null && _a !== void 0 ? _a : new Map();
148
+ const queryCaches = optConditionSpecsBaseCaches.get(specs) ?? new Map();
152
149
  const cached = queryCaches.get(query);
153
150
  if (cached) {
154
151
  return cached;
@@ -156,9 +153,9 @@ function optCondition(query, specs) {
156
153
  let hasCustom = false;
157
154
  let hasText = false;
158
155
  const selector = query.replace(/^(?::model\(([^)]+)\)|#([a-z-]+))(.*)$/, (_, $model, _model, $last) => {
159
- const _selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${$model !== null && $model !== void 0 ? $model : _model}`, specs.def);
156
+ const _selectors = contentModelCategoryToTagNames(`#${$model ?? _model}`, specs.def);
160
157
  if (_selectors.length === 0) {
161
- throw new Error(`${$model !== null && $model !== void 0 ? $model : _model} is empty`);
158
+ throw new Error(`${$model ?? _model} is empty`);
162
159
  }
163
160
  const selectors = [];
164
161
  for (const selector of _selectors) {
@@ -172,7 +169,7 @@ function optCondition(query, specs) {
172
169
  }
173
170
  selectors.push(selector);
174
171
  }
175
- return `:is(${selectors.join(',')})${$last !== null && $last !== void 0 ? $last : ''}`;
172
+ return `:is(${selectors.join(',')})${$last ?? ''}`;
176
173
  });
177
174
  const result = {
178
175
  selector,
@@ -1,5 +1,6 @@
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
+ import type { ReadonlyDeep } from 'type-fest';
3
4
  /**
4
5
  * Check ordered array
5
6
  *
@@ -10,4 +11,4 @@ import type { PermittedContentPattern } from '@markuplint/ml-spec';
10
11
  * @param depth
11
12
  * @returns
12
13
  */
13
- export declare function order(contents: ReadonlyArray<PermittedContentPattern>, nodes: ReadonlyArray<ChildNode>, specs: Specs, options: Options, depth: number): 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,42 +12,50 @@ const utils_1 = require("./utils");
15
12
  * @param depth
16
13
  * @returns
17
14
  */
18
- function order(contents, nodes, specs, options, depth) {
19
- var _a, _b, _c, _d;
20
- const orderLog = debug_1.cmLog.extend(`order#${depth}`);
21
- const btLog = debug_1.cmLog.extend(`backtrack#${depth}`);
22
- const patterns = (0, helpers_1.deepCopy)(contents);
23
- const collection = new utils_1.Collection(nodes);
15
+ export function order(contents,
16
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
17
+ nodes, specs, options, depth) {
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);
24
23
  orderLog('Starts: %s', collection);
25
24
  let result = undefined;
26
25
  let backtrackMode = false;
27
26
  let afterBacktrack = false;
28
27
  const unmatchedResults = [];
29
- while (patterns.length) {
30
- result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
28
+ while (patterns.length > 0 && patterns[0]) {
29
+ result = complexBranch(patterns[0], collection.unmatched, specs, options, depth);
31
30
  collection.addMatched(result.matched);
32
- orderLog('stack: %s', collection);
33
31
  if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
34
32
  unmatchedResults.push(result);
35
33
  if (backtrackMode) {
36
34
  collection.back();
37
- btLog('🔙');
35
+ btLog('🔙◀BACK');
38
36
  backtrackMode = false;
39
37
  afterBacktrack = true;
40
38
  continue;
41
39
  }
42
- orderLog('conformed (%s): %s', result.type, collection.toString(true));
43
40
  const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
44
41
  if (!barelyMatchedResult) {
45
42
  throw new Error('Unreachable code');
46
43
  }
44
+ orderLog('Result (%s): %s%s', result.type, collection.toString(true), barelyMatchedResult.hint.missing?.barelyMatchedElements != null
45
+ ? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
46
+ : '');
47
47
  return {
48
48
  type: barelyMatchedResult.type,
49
49
  matched: collection.matched,
50
50
  unmatched: collection.unmatched,
51
51
  zeroMatch: barelyMatchedResult.zeroMatch,
52
52
  query: barelyMatchedResult.query,
53
- hint: barelyMatchedResult.hint,
53
+ hint: mergeHints(barelyMatchedResult.hint, {
54
+ missing: {
55
+ barelyMatchedElements: collection.matched.length,
56
+ need: barelyMatchedResult.query,
57
+ },
58
+ }),
54
59
  };
55
60
  }
56
61
  if (afterBacktrack) {
@@ -65,25 +70,25 @@ function order(contents, nodes, specs, options, depth) {
65
70
  }
66
71
  patterns.shift();
67
72
  }
68
- if (collection.unmatched.length) {
69
- orderLog('Conformed (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
73
+ if (collection.unmatched.length > 0) {
74
+ orderLog('Result (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
70
75
  return {
71
76
  type: 'UNEXPECTED_EXTRA_NODE',
72
77
  matched: collection.matched,
73
78
  unmatched: collection.unmatched,
74
79
  zeroMatch: false,
75
- query: (_a = result === null || result === void 0 ? void 0 : result.query) !== null && _a !== void 0 ? _a : 'N/A',
76
- hint: (_b = result === null || result === void 0 ? void 0 : result.hint) !== null && _b !== void 0 ? _b : {},
80
+ query: result?.query ?? 'N/A',
81
+ hint: result?.hint ?? {},
77
82
  };
78
83
  }
79
- orderLog('Conformed: %s', collection);
84
+ const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
85
+ orderLog('Result (%s): %s', resultType, collection.toString(true));
80
86
  return {
81
- type: collection.matched.length ? 'MATCHED' : 'MATCHED_ZERO',
87
+ type: resultType,
82
88
  matched: collection.matched,
83
89
  unmatched: collection.unmatched,
84
90
  zeroMatch: false,
85
- query: (_c = result === null || result === void 0 ? void 0 : result.query) !== null && _c !== void 0 ? _c : 'N/A',
86
- hint: (_d = result === null || result === void 0 ? void 0 : result.hint) !== null && _d !== void 0 ? _d : {},
91
+ query: result?.query ?? 'N/A',
92
+ hint: result?.hint ?? {},
87
93
  };
88
94
  }
89
- exports.order = order;
@@ -1,4 +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
- export declare function recursiveBranch(model: Model | PermittedContentPattern[], nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
4
+ import type { ReadonlyDeep } from 'type-fest';
5
+ export declare function recursiveBranch(model: ReadonlyDeep<Model | PermittedContentPattern[]>, nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
@@ -1,20 +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, nodes, specs, options, depth) {
8
- if (!(0, utils_1.isModel)(model)) {
9
- return (0, order_1.order)(model, nodes, specs, options, depth + 1);
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,
5
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
+ nodes, specs, options, depth) {
7
+ if (!isModel(model)) {
8
+ return order(model, nodes, specs, options, depth + 1);
10
9
  }
11
10
  if (typeof model === 'string') {
12
- return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, options, depth);
11
+ return matchesSelector(model, nodes[0], specs, depth);
13
12
  }
14
- const collection = new utils_1.Collection(nodes);
13
+ const collection = new Collection(nodes);
15
14
  let lastUnmatched = null;
16
15
  for (const query of model) {
17
- const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, options, depth);
16
+ const result = matchesSelector(query, collection.unmatched[0], specs, depth);
18
17
  collection.addMatched(result.matched);
19
18
  if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
20
19
  return {
@@ -40,4 +39,3 @@ function recursiveBranch(model, nodes, specs, options, depth) {
40
39
  }
41
40
  return lastUnmatched;
42
41
  }
43
- exports.recursiveBranch = recursiveBranch;
@@ -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
  export declare const transparentMode: Map<ChildNode, true>;
3
3
  export declare function representTransparentNodes(nodes: ChildNode[], specs: Specs, options: Options): {
4
4
  nodes: ChildNode[];
@@ -1,15 +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(nodes, specs, options) {
9
- var _a;
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(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ nodes, specs, options) {
10
8
  const result = [];
11
9
  const errors = [];
12
- const parent = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement;
10
+ const parent = nodes[0]?.parentElement;
13
11
  if (parent) {
14
12
  const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
15
13
  errors.push(...parentErrors);
@@ -19,37 +17,37 @@ function representTransparentNodes(nodes, specs, options) {
19
17
  result.push(node);
20
18
  continue;
21
19
  }
22
- const models = (0, ml_spec_1.getContentModel)(node, specs.specs);
20
+ const models = getContentModel(node, specs.specs);
23
21
  if (models == null || typeof models === 'boolean') {
24
22
  result.push(node);
25
23
  continue;
26
24
  }
27
- const noTransparentModels = models.filter(m => !(0, utils_1.isTransparent)(m));
25
+ const noTransparentModels = models.filter(m => !isTransparent(m));
28
26
  if (noTransparentModels.length === models.length) {
29
27
  result.push(node);
30
28
  continue;
31
29
  }
32
- const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
30
+ const collection = new Collection(getChildNodesWithoutWhitespaces(node));
33
31
  let unmatched;
34
- if (noTransparentModels.length) {
35
- const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
32
+ if (noTransparentModels.length > 0) {
33
+ const result = order(noTransparentModels, collection.unmatched, specs, options, Infinity);
36
34
  unmatched = result.unmatched;
37
35
  }
38
36
  else {
39
37
  unmatched = collection.unmatched;
40
38
  }
41
- const transparent = models.find(m => (0, utils_1.isTransparent)(m));
42
- if (!transparent || !(0, utils_1.isTransparent)(transparent)) {
39
+ const transparent = models.find(m => isTransparent(m));
40
+ if (!transparent || !isTransparent(transparent)) {
43
41
  throw new Error('Unreachable code');
44
42
  }
45
43
  for (const _child of unmatched) {
46
44
  const child = _child;
47
- if (exports.transparentMode.has(child)) {
45
+ if (transparentMode.has(child)) {
48
46
  continue;
49
47
  }
50
- exports.transparentMode.set(child, true);
48
+ transparentMode.set(child, true);
51
49
  if (child.is(child.ELEMENT_NODE)) {
52
- const transparentCondMatched = (0, utils_1.matches)(transparent.transparent, child, specs);
50
+ const transparentCondMatched = matches(transparent.transparent, child, specs);
53
51
  if (!transparentCondMatched.matched) {
54
52
  errors.push({
55
53
  type: 'TRANSPARENT_MODEL_DISALLOWS',
@@ -73,4 +71,3 @@ function representTransparentNodes(nodes, specs, options) {
73
71
  errors,
74
72
  };
75
73
  }
76
- exports.representTransparentNodes = representTransparentNodes;
@@ -1,5 +1,6 @@
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
+ import type { ReadonlyDeep } from 'type-fest';
3
4
  /**
4
5
  * Check start
5
6
  *
@@ -9,4 +10,4 @@ import type { ContentModel } from '@markuplint/ml-spec';
9
10
  * @param options
10
11
  * @returns
11
12
  */
12
- export declare function start(contents: ContentModel['contents'], el: Element, specs: Specs, options: Options): 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,11 @@ const utils_1 = require("./utils");
13
10
  * @param options
14
11
  * @returns
15
12
  */
16
- function start(contents, el, specs, options) {
17
- var _a;
13
+ export function start(contents,
14
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
15
+ el, specs, options) {
18
16
  if (contents === false) {
19
- if (el.childNodes.length) {
17
+ if (el.childNodes.length > 0) {
20
18
  return [
21
19
  {
22
20
  type: 'NOTHING',
@@ -46,26 +44,22 @@ function start(contents, el, specs, options) {
46
44
  },
47
45
  ];
48
46
  }
49
- const { nodes, errors } = (0, represent_transparent_nodes_1.representTransparentNodes)((0, utils_1.getChildNodesWithoutWhitespaces)(el), specs, options);
50
- 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);
51
49
  return [
52
50
  {
53
51
  type: result.type,
54
52
  scope: result.type === 'MISSING_NODE_REQUIRED' || result.type === 'MISSING_NODE_ONE_OR_MORE'
55
53
  ? el
56
- : (_a = result.unmatched[0]) !== null && _a !== void 0 ? _a : el,
54
+ : result.unmatched[0] ?? el,
57
55
  query: result.query,
58
56
  hint: result.hint,
59
57
  },
60
- ...errors.map(error => {
61
- var _a;
62
- return ({
63
- type: error.type,
64
- scope: (_a = error.unmatched[0]) !== null && _a !== void 0 ? _a : el,
65
- query: error.query,
66
- hint: error.hint,
67
- });
68
- }),
58
+ ...errors.map(error => ({
59
+ type: error.type,
60
+ scope: error.unmatched[0] ?? el,
61
+ query: error.query,
62
+ hint: error.hint,
63
+ })),
69
64
  ];
70
65
  }
71
- exports.start = start;
@@ -1,2 +1,2 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
2
- export declare function transparent(nodes: ChildNode[], specs: Specs, options: Options, depth: number): Result;
1
+ import type { ChildNode, Result } from './types.js';
2
+ export declare function transparent(nodes: readonly ChildNode[]): Result;
@@ -1,11 +1,9 @@
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(nodes, specs, options, depth) {
7
- var _a;
8
- if (nodes.length === 0 || ((_a = nodes[0].parentElement) === null || _a === void 0 ? void 0 : _a.parentElement)) {
1
+ import { cmLog } from './debug.js';
2
+ const transparentLog = cmLog.extend('transparent');
3
+ export function transparent(
4
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
5
+ nodes) {
6
+ if (nodes.length === 0 || nodes[0]?.parentElement?.parentElement) {
9
7
  transparentLog('Skipped');
10
8
  return {
11
9
  type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
@@ -26,4 +24,3 @@ function transparent(nodes, specs, options, depth) {
26
24
  hint: {},
27
25
  };
28
26
  }
29
- exports.transparent = transparent;