@markuplint/rules 3.0.0-alpha.66 → 3.0.0-dev.24

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 (129) hide show
  1. package/README.md +10 -44
  2. package/lib/attr-check.d.ts +2 -2
  3. package/lib/attr-check.js +1 -1
  4. package/lib/attr-duplication/index.js +1 -1
  5. package/lib/attr-value-quotes/index.d.ts +3 -3
  6. package/lib/attr-value-quotes/index.js +1 -1
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  8. package/lib/case-sensitive-attr-name/index.js +3 -3
  9. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  10. package/lib/case-sensitive-tag-name/index.js +3 -3
  11. package/lib/character-reference/index.js +1 -1
  12. package/lib/class-naming/index.d.ts +1 -1
  13. package/lib/class-naming/index.js +2 -2
  14. package/lib/create-message.d.ts +1 -1
  15. package/lib/create-message.js +5 -5
  16. package/lib/debug.d.ts +1 -1
  17. package/lib/deprecated-element/index.js +2 -2
  18. package/lib/doctype/index.d.ts +2 -2
  19. package/lib/doctype/index.js +2 -2
  20. package/lib/end-tag/index.js +3 -18
  21. package/lib/helpers.d.ts +8 -32
  22. package/lib/helpers.js +17 -81
  23. package/lib/index.d.ts +2 -62
  24. package/lib/index.js +4 -0
  25. package/lib/ineffective-attr/index.js +1 -1
  26. package/lib/invalid-attr/index.d.ts +3 -2
  27. package/lib/invalid-attr/index.js +19 -14
  28. package/lib/label-has-control/index.d.ts +2 -0
  29. package/lib/label-has-control/index.js +28 -0
  30. package/lib/landmark-roles/index.d.ts +3 -3
  31. package/lib/landmark-roles/index.js +3 -3
  32. package/lib/no-boolean-attr-value/index.js +1 -1
  33. package/lib/no-default-value/index.js +1 -1
  34. package/lib/no-empty-palpable-content/index.d.ts +6 -0
  35. package/lib/no-empty-palpable-content/index.js +34 -0
  36. package/lib/no-hard-code-id/index.js +1 -1
  37. package/lib/no-refer-to-non-existent-id/index.js +1 -1
  38. package/lib/no-use-event-handler-attr/index.d.ts +1 -1
  39. package/lib/no-use-event-handler-attr/index.js +6 -6
  40. package/lib/permitted-contents/choice.d.ts +3 -0
  41. package/lib/permitted-contents/choice.js +37 -0
  42. package/lib/permitted-contents/complex-branch.d.ts +13 -0
  43. package/lib/permitted-contents/complex-branch.js +27 -0
  44. package/lib/permitted-contents/content-model.d.ts +2 -0
  45. package/lib/permitted-contents/content-model.js +49 -0
  46. package/lib/permitted-contents/count-pattern.d.ts +13 -0
  47. package/lib/permitted-contents/count-pattern.js +155 -0
  48. package/lib/permitted-contents/debug.browser.d.ts +30 -0
  49. package/lib/permitted-contents/debug.browser.js +14 -0
  50. package/lib/permitted-contents/debug.d.ts +3 -0
  51. package/lib/permitted-contents/debug.js +13 -0
  52. package/lib/permitted-contents/index.d.ts +1 -7
  53. package/lib/permitted-contents/index.js +76 -246
  54. package/lib/permitted-contents/matches-selector.d.ts +3 -0
  55. package/lib/permitted-contents/matches-selector.js +185 -0
  56. package/lib/permitted-contents/order.d.ts +13 -0
  57. package/lib/permitted-contents/order.js +89 -0
  58. package/lib/permitted-contents/recursive-branch.d.ts +4 -0
  59. package/lib/permitted-contents/recursive-branch.js +43 -0
  60. package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
  61. package/lib/permitted-contents/represent-transparent-nodes.js +76 -0
  62. package/lib/permitted-contents/start.d.ts +12 -0
  63. package/lib/permitted-contents/start.js +71 -0
  64. package/lib/permitted-contents/transparent.d.ts +2 -0
  65. package/lib/permitted-contents/transparent.js +29 -0
  66. package/lib/permitted-contents/types.d.ts +45 -0
  67. package/lib/permitted-contents/types.js +2 -0
  68. package/lib/permitted-contents/utils.d.ts +32 -0
  69. package/lib/permitted-contents/utils.js +184 -0
  70. package/lib/require-accessible-name/index.d.ts +1 -1
  71. package/lib/require-accessible-name/index.js +11 -3
  72. package/lib/required-attr/index.d.ts +2 -2
  73. package/lib/required-attr/index.js +1 -1
  74. package/lib/required-element/index.d.ts +1 -1
  75. package/lib/required-element/index.js +1 -1
  76. package/lib/required-h1/index.js +2 -2
  77. package/lib/use-list/index.d.ts +2 -2
  78. package/lib/use-list/index.js +3 -3
  79. package/lib/wai-aria/checkings/abstract-role.js +1 -1
  80. package/lib/wai-aria/checkings/implicit-role.js +2 -2
  81. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
  82. package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
  83. package/lib/wai-aria/checkings/{non-existant-role.d.ts → non-existent-role.d.ts} +1 -1
  84. package/lib/wai-aria/checkings/{non-existant-role.js → non-existent-role.js} +4 -4
  85. package/lib/wai-aria/checkings/permitted-roles.js +1 -1
  86. package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
  87. package/lib/wai-aria/checkings/presentational-children.js +60 -0
  88. package/lib/wai-aria/checkings/{checking-required-owned-elements.d.ts → required-owned-elements.d.ts} +0 -0
  89. package/lib/wai-aria/checkings/required-owned-elements.js +101 -0
  90. package/lib/wai-aria/checkings/value.d.ts +6 -0
  91. package/lib/wai-aria/checkings/value.js +74 -4
  92. package/lib/wai-aria/index.js +25 -15
  93. package/lib/wai-aria/types.d.ts +3 -1
  94. package/package.json +12 -8
  95. package/schema.json +6 -0
  96. package/tsconfig.tsbuildinfo +1 -1
  97. package/lib/__foo/index.d.ts +0 -2
  98. package/lib/__foo/index.js +0 -46
  99. package/lib/attr-equal-space-after/index.d.ts +0 -3
  100. package/lib/attr-equal-space-after/index.js +0 -90
  101. package/lib/attr-equal-space-before/index.d.ts +0 -3
  102. package/lib/attr-equal-space-before/index.js +0 -90
  103. package/lib/attr-spacing/index.d.ts +0 -6
  104. package/lib/attr-spacing/index.js +0 -100
  105. package/lib/helper/aria/get-aria.d.ts +0 -7
  106. package/lib/helper/aria/get-aria.js +0 -53
  107. package/lib/helper/aria/get-computed-role.d.ts +0 -10
  108. package/lib/helper/aria/get-computed-role.js +0 -24
  109. package/lib/helper/aria/get-implicit-role.d.ts +0 -7
  110. package/lib/helper/aria/get-implicit-role.js +0 -12
  111. package/lib/helper/aria/get-permitted-roles.d.ts +0 -14
  112. package/lib/helper/aria/get-permitted-roles.js +0 -26
  113. package/lib/helper/aria/resolve-version.d.ts +0 -2
  114. package/lib/helper/aria/resolve-version.js +0 -21
  115. package/lib/helper/spec/aria-spec.d.ts +0 -5
  116. package/lib/helper/spec/aria-spec.js +0 -12
  117. package/lib/helper/spec/get-role-spec.d.ts +0 -11
  118. package/lib/helper/spec/get-role-spec.js +0 -39
  119. package/lib/helper/spec/html-spec.d.ts +0 -2
  120. package/lib/helper/spec/html-spec.js +0 -14
  121. package/lib/indentation/index.d.ts +0 -7
  122. package/lib/indentation/index.js +0 -208
  123. package/lib/permitted-contents/array.combination.d.ts +0 -1
  124. package/lib/permitted-contents/array.combination.js +0 -33
  125. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
  126. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -230
  127. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
  128. package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
  129. package/lib/wai-aria/checkings/checking-required-owned-elements.js +0 -63
@@ -1,9 +1,10 @@
1
1
  import type { AttributeType } from '@markuplint/ml-spec';
2
- declare type Option = {
2
+ type Option = {
3
3
  attrs?: Record<string, Rule>;
4
4
  ignoreAttrNamePrefix?: string | string[];
5
+ allowToAddPropertiesForPretender?: boolean;
5
6
  };
6
- declare type Rule = {
7
+ type Rule = {
7
8
  enum: [string, ...string[]];
8
9
  } | {
9
10
  pattern: string;
@@ -9,14 +9,16 @@ exports.default = (0, ml_core_1.createRule)({
9
9
  defaultOptions: {},
10
10
  async verify({ document, report, t }) {
11
11
  await document.walkOn('Attr', attr => {
12
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
13
+ // Default
14
+ const allowToAddPropertiesForPretender = (_a = attr.rule.options.allowToAddPropertiesForPretender) !== null && _a !== void 0 ? _a : true;
13
15
  if (attr.isDirective) {
14
16
  return;
15
17
  }
16
18
  const attrSpecs = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
17
19
  const attrName = attr.nameNode;
18
20
  const name = attr.name;
19
- if (!attr.ownerElement.isCustomElement && attr.candidate) {
21
+ if (attr.ownerElement.elementType === 'html' && attr.candidate) {
20
22
  const message = t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'disallowed') +
21
23
  t('. ') +
22
24
  t('Did you mean "{0}"?', attr.candidate);
@@ -31,16 +33,16 @@ exports.default = (0, ml_core_1.createRule)({
31
33
  }
32
34
  const valueNode = attr.valueNode;
33
35
  const value = attr.value;
34
- if (attr.rule.option.ignoreAttrNamePrefix) {
35
- const ignoreAttrNamePrefixes = Array.isArray(attr.rule.option.ignoreAttrNamePrefix)
36
- ? attr.rule.option.ignoreAttrNamePrefix
37
- : [attr.rule.option.ignoreAttrNamePrefix];
36
+ if (attr.rule.options.ignoreAttrNamePrefix) {
37
+ const ignoreAttrNamePrefixes = Array.isArray(attr.rule.options.ignoreAttrNamePrefix)
38
+ ? attr.rule.options.ignoreAttrNamePrefix
39
+ : [attr.rule.options.ignoreAttrNamePrefix];
38
40
  if (ignoreAttrNamePrefixes.some(prefix => name.indexOf(prefix) === 0)) {
39
41
  return;
40
42
  }
41
43
  }
42
44
  let invalid = false;
43
- const customRule = attr.rule.option.attrs ? attr.rule.option.attrs[name] : null;
45
+ const customRule = attr.rule.options.attrs ? attr.rule.options.attrs[name] : null;
44
46
  if (customRule) {
45
47
  if ('enum' in customRule) {
46
48
  invalid = (0, attr_check_1.attrCheck)(t, name.toLowerCase(), value, true, {
@@ -69,7 +71,7 @@ exports.default = (0, ml_core_1.createRule)({
69
71
  };
70
72
  }
71
73
  }
72
- else if (!attr.ownerElement.isCustomElement && attrSpecs) {
74
+ else if (attr.ownerElement.elementType === 'html' && attrSpecs) {
73
75
  log('Checking %s[%s="%s"]', attr.nodeName, name, value);
74
76
  invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
75
77
  }
@@ -82,16 +84,19 @@ exports.default = (0, ml_core_1.createRule)({
82
84
  report({
83
85
  scope: attr,
84
86
  message: invalid.message,
85
- line: ((_a = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _a !== void 0 ? _a : 0) + ((_c = (_b = invalid.loc) === null || _b === void 0 ? void 0 : _b.line) !== null && _c !== void 0 ? _c : 0),
86
- col: ((_d = invalid.loc) === null || _d === void 0 ? void 0 : _d.line)
87
- ? ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.col) + 1
88
- : ((_f = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _f !== void 0 ? _f : 0) + ((_h = (_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.col) !== null && _h !== void 0 ? _h : 0),
89
- raw: (_k = (_j = invalid.loc) === null || _j === void 0 ? void 0 : _j.raw) !== null && _k !== void 0 ? _k : value,
87
+ line: ((_b = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = invalid.loc) === null || _c === void 0 ? void 0 : _c.line) !== null && _d !== void 0 ? _d : 0),
88
+ col: ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.line)
89
+ ? ((_f = invalid.loc) === null || _f === void 0 ? void 0 : _f.col) + 1
90
+ : ((_g = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _g !== void 0 ? _g : 0) + ((_j = (_h = invalid.loc) === null || _h === void 0 ? void 0 : _h.col) !== null && _j !== void 0 ? _j : 0),
91
+ raw: (_l = (_k = invalid.loc) === null || _k === void 0 ? void 0 : _k.raw) !== null && _l !== void 0 ? _l : value,
90
92
  });
91
93
  break;
92
94
  }
93
95
  case 'non-existent': {
94
- const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs);
96
+ if (allowToAddPropertiesForPretender && ((_m = attr.ownerElement.pretenderContext) === null || _m === void 0 ? void 0 : _m.type) === 'origin') {
97
+ return;
98
+ }
99
+ const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs.specs);
95
100
  if (spec === null || spec === void 0 ? void 0 : spec.possibleToAddProperties) {
96
101
  return;
97
102
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
2
+ export default _default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ml_core_1 = require("@markuplint/ml-core");
4
+ const controlSelector = ["input:not([type='hidden' i])", 'select', 'textarea'].join(',');
5
+ exports.default = (0, ml_core_1.createRule)({
6
+ defaultSeverity: 'warning',
7
+ async verify({ document, report, t }) {
8
+ await document.walkOn('Element', el => {
9
+ if (el.localName !== 'label') {
10
+ return;
11
+ }
12
+ if (el.children.length === 0 && !el.hasAttribute('for')) {
13
+ report({
14
+ scope: el,
15
+ message: t('{0} should associate with {1}', t('The "{0*}" {1}', 'label', 'element'), t('a {0}', 'control')),
16
+ });
17
+ }
18
+ const controls = el.querySelectorAll(controlSelector);
19
+ const secondControl = controls[1];
20
+ if (secondControl) {
21
+ report({
22
+ scope: secondControl,
23
+ message: t('{0} associates only {1}', t('The "{0*}" {1}', 'label', 'element'), t('first {0}', 'control')),
24
+ });
25
+ }
26
+ });
27
+ },
28
+ });
@@ -1,8 +1,8 @@
1
- declare type Options = {
1
+ type Options = {
2
2
  ignoreRoles: Roles[];
3
3
  labelEachArea: boolean;
4
4
  };
5
- declare type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
6
- declare type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
5
+ type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
6
+ type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
7
7
  declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Options>;
8
8
  export default _default;
@@ -12,7 +12,7 @@ const selectors = {
12
12
  };
13
13
  const topLevelRoles = ['banner', 'main', 'complementary', 'contentinfo'];
14
14
  exports.default = (0, ml_core_1.createRule)({
15
- defaultServerity: 'warning',
15
+ defaultSeverity: 'warning',
16
16
  defaultOptions: {
17
17
  ignoreRoles: [],
18
18
  labelEachArea: true,
@@ -72,7 +72,7 @@ exports.default = (0, ml_core_1.createRule)({
72
72
  if (el.rule.disabled) {
73
73
  continue;
74
74
  }
75
- if ((_a = el.rule.option.ignoreRoles) === null || _a === void 0 ? void 0 : _a.includes(role)) {
75
+ if ((_a = el.rule.options.ignoreRoles) === null || _a === void 0 ? void 0 : _a.includes(role)) {
76
76
  continue;
77
77
  }
78
78
  if (el.isDescendantByUUIDList(uuidList)) {
@@ -93,7 +93,7 @@ exports.default = (0, ml_core_1.createRule)({
93
93
  if (el.rule.disabled) {
94
94
  continue;
95
95
  }
96
- if (!el.rule.option.labelEachArea) {
96
+ if (!el.rule.options.labelEachArea) {
97
97
  continue;
98
98
  }
99
99
  if (!hasLabel(el)) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  exports.default = (0, ml_core_1.createRule)({
5
- defaultServerity: 'warning',
5
+ defaultSeverity: 'warning',
6
6
  async verify({ document, report, t }) {
7
7
  await document.walkOn('Attr', attr => {
8
8
  var _a, _b;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
5
  exports.default = (0, ml_core_1.createRule)({
6
- defaultServerity: 'warning',
6
+ defaultSeverity: 'warning',
7
7
  async verify({ document, report, t }) {
8
8
  await document.walkOn('Attr', attr => {
9
9
  var _a, _b, _c;
@@ -0,0 +1,6 @@
1
+ type Options = {
2
+ extendsExposableElements?: boolean;
3
+ ignoreIfAriaBusy?: boolean;
4
+ };
5
+ declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Options>;
6
+ export default _default;
@@ -0,0 +1,34 @@
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
+ exports.default = (0, ml_core_1.createRule)({
6
+ defaultSeverity: 'warning',
7
+ defaultOptions: {
8
+ extendsExposableElements: true,
9
+ ignoreIfAriaBusy: true,
10
+ },
11
+ async verify({ document, report, t }) {
12
+ await document.walkOn('Element', el => {
13
+ if (!(0, ml_spec_1.isPalpableElement)(el, el.ownerMLDocument.specs, {
14
+ extendsSvg: false,
15
+ extendsExposableElements: el.rule.options.extendsExposableElements,
16
+ })) {
17
+ return;
18
+ }
19
+ if ((0, ml_spec_1.isNothingContentModel)(el)) {
20
+ return;
21
+ }
22
+ if (el.rule.options.ignoreIfAriaBusy && el.getAttribute('aria-busy') === 'true') {
23
+ return;
24
+ }
25
+ const isEmpty = Array.from(el.childNodes).every(node => node.is(node.TEXT_NODE) && node.isWhitespace());
26
+ if (isEmpty) {
27
+ report({
28
+ scope: el,
29
+ message: t('{0} should not {1}', t('the {0}', 'element'), 'empty'),
30
+ });
31
+ }
32
+ });
33
+ },
34
+ });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  exports.default = (0, ml_core_1.createRule)({
5
- defaultServerity: 'warning',
5
+ defaultSeverity: 'warning',
6
6
  async verify({ document, report, t }) {
7
7
  if (!document.isFragment) {
8
8
  return;
@@ -69,7 +69,7 @@ exports.default = (0, ml_core_1.createRule)({
69
69
  }
70
70
  }
71
71
  }
72
- const { props } = (0, ml_core_1.ariaSpecs)(document.specs, attr.rule.option.ariaVersion);
72
+ const { props } = (0, ml_core_1.ariaSpecs)(document.specs, attr.rule.options.ariaVersion);
73
73
  const aria = props.find(prop => prop.name === name);
74
74
  if (aria) {
75
75
  if (aria.value === 'ID reference' && !idList.has(value)) {
@@ -1,4 +1,4 @@
1
- declare type Options = {
1
+ type Options = {
2
2
  ignore?: string | string[];
3
3
  };
4
4
  declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Options>;
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
5
  exports.default = (0, ml_core_1.createRule)({
6
- defaultServerity: 'warning',
6
+ defaultSeverity: 'warning',
7
7
  defaultOptions: {},
8
8
  async verify({ document, report, t }) {
9
9
  await document.walkOn('Attr', attr => {
10
- if (attr.ownerElement.isCustomElement) {
10
+ if (attr.ownerElement.elementType !== 'html') {
11
11
  return;
12
12
  }
13
- const ignoreList = Array.isArray(attr.rule.option.ignore)
14
- ? attr.rule.option.ignore
15
- : attr.rule.option.ignore
16
- ? [attr.rule.option.ignore]
13
+ const ignoreList = Array.isArray(attr.rule.options.ignore)
14
+ ? attr.rule.options.ignore
15
+ : attr.rule.options.ignore
16
+ ? [attr.rule.options.ignore]
17
17
  : [];
18
18
  const name = attr.name;
19
19
  for (const ignore of ignoreList) {
@@ -0,0 +1,3 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentChoice } from '@markuplint/ml-spec';
3
+ export declare function choice(pattern: PermittedContentChoice, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.choice = void 0;
4
+ const order_1 = require("./order");
5
+ const utils_1 = require("./utils");
6
+ function choice(pattern, elements, specs, options, depth) {
7
+ const collection = new utils_1.Collection(elements);
8
+ const unmatchedResults = [];
9
+ for (const some of pattern.choice) {
10
+ const result = (0, order_1.order)(some, collection.unmatched, specs, options, depth + 1);
11
+ if (result.type === 'UNEXPECTED_EXTRA_NODE' || result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
12
+ collection.addMatched(result.matched);
13
+ return {
14
+ type: result.type,
15
+ matched: collection.matched,
16
+ unmatched: collection.unmatched,
17
+ zeroMatch: result.zeroMatch,
18
+ query: result.query,
19
+ hint: result.hint,
20
+ };
21
+ }
22
+ unmatchedResults.push(result);
23
+ }
24
+ const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
25
+ if (!barelyMatchedResult) {
26
+ throw new Error('Unreachable code');
27
+ }
28
+ return {
29
+ type: barelyMatchedResult.type,
30
+ matched: collection.matched,
31
+ unmatched: collection.unmatched,
32
+ zeroMatch: barelyMatchedResult.zeroMatch,
33
+ query: barelyMatchedResult.query,
34
+ hint: barelyMatchedResult.hint,
35
+ };
36
+ }
37
+ exports.choice = choice;
@@ -0,0 +1,13 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentPattern } from '@markuplint/ml-spec';
3
+ /**
4
+ * Check content condition
5
+ *
6
+ * @param pattern
7
+ * @param elements
8
+ * @param specs
9
+ * @param options
10
+ * @param depth
11
+ * @returns
12
+ */
13
+ export declare function complexBranch(pattern: PermittedContentPattern, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,27 @@
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");
8
+ /**
9
+ * Check content condition
10
+ *
11
+ * @param pattern
12
+ * @param elements
13
+ * @param specs
14
+ * @param options
15
+ * @param depth
16
+ * @returns
17
+ */
18
+ function complexBranch(pattern, elements, specs, options, depth) {
19
+ if ((0, utils_1.isChoice)(pattern)) {
20
+ return (0, choice_1.choice)(pattern, elements, specs, options, depth);
21
+ }
22
+ if ((0, utils_1.isTransparent)(pattern)) {
23
+ return (0, transparent_1.transparent)(elements, specs, options, depth);
24
+ }
25
+ return (0, count_pattern_1.countPattern)(pattern, elements, specs, options, depth);
26
+ }
27
+ exports.complexBranch = complexBranch;
@@ -0,0 +1,2 @@
1
+ import type { ContentModelResult, Element, Options, TagRule } from './types';
2
+ export declare function contentModel(el: Element, rules: TagRule[], options: Options): ContentModelResult[];
@@ -0,0 +1,49 @@
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(el, rules, options) {
7
+ const model = createModel(el, rules);
8
+ if (model == null) {
9
+ return [
10
+ {
11
+ type: 'MATCHED',
12
+ scope: el,
13
+ query: '*',
14
+ hint: {},
15
+ },
16
+ ];
17
+ }
18
+ const result = (0, start_1.start)(model, el, el.ownerMLDocument.specs, options);
19
+ return result;
20
+ }
21
+ exports.contentModel = contentModel;
22
+ function createModel(el, rules) {
23
+ const specs = cachedSpecs(el.ownerMLDocument.specs, rules);
24
+ const model = (0, ml_spec_1.getContentModel)(el, specs.specs);
25
+ return model;
26
+ }
27
+ const caches = new Map();
28
+ function cachedSpecs(specs, rules) {
29
+ if (!rules.length) {
30
+ return specs;
31
+ }
32
+ const key = JSON.stringify(rules);
33
+ const cached = caches.get(key);
34
+ if (cached) {
35
+ return cached;
36
+ }
37
+ const merged = {
38
+ ...specs,
39
+ specs: [
40
+ ...specs.specs,
41
+ ...rules.map(tag => ({
42
+ name: tag.tag,
43
+ contentModel: tag,
44
+ })),
45
+ ],
46
+ };
47
+ caches.set(key, merged);
48
+ return merged;
49
+ }
@@ -0,0 +1,13 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentZeroOrMore } from '@markuplint/ml-spec';
3
+ /**
4
+ * Check count
5
+ *
6
+ * @param pattern
7
+ * @param elements
8
+ * @param specs
9
+ * @param options
10
+ * @param depth
11
+ * @returns
12
+ */
13
+ export declare function countPattern(pattern: PermittedContentOneOrMore | PermittedContentOptional | PermittedContentRequire | PermittedContentZeroOrMore, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,155 @@
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
+ /**
8
+ * Check count
9
+ *
10
+ * @param pattern
11
+ * @param elements
12
+ * @param specs
13
+ * @param options
14
+ * @param depth
15
+ * @returns
16
+ */
17
+ function countPattern(pattern, elements, specs, options, depth) {
18
+ var _a, _b, _c, _d, _e;
19
+ const ptLog = debug_1.cmLog.extend(`countPattern#${depth}`);
20
+ const collection = new utils_1.Collection(elements);
21
+ let min;
22
+ let max;
23
+ let model;
24
+ let type;
25
+ let _type;
26
+ if ((0, utils_1.isRequire)(pattern)) {
27
+ min = (_a = pattern.min) !== null && _a !== void 0 ? _a : 1;
28
+ max = Math.max((_b = pattern.max) !== null && _b !== void 0 ? _b : 1, min);
29
+ model = pattern.require;
30
+ type = 'MISSING_NODE_REQUIRED';
31
+ _type = 'require';
32
+ }
33
+ else if ((0, utils_1.isOptional)(pattern)) {
34
+ min = 0;
35
+ max = Math.max((_c = pattern.max) !== null && _c !== void 0 ? _c : 1, 1);
36
+ model = pattern.optional;
37
+ _type = 'optional';
38
+ }
39
+ else if ((0, utils_1.isOneOrMore)(pattern)) {
40
+ min = 1;
41
+ max = Math.max((_d = pattern.max) !== null && _d !== void 0 ? _d : Infinity, 1);
42
+ model = pattern.oneOrMore;
43
+ type = 'MISSING_NODE_ONE_OR_MORE';
44
+ _type = 'one or more';
45
+ }
46
+ else if ((0, utils_1.isZeroOrMore)(pattern)) {
47
+ min = 0;
48
+ max = Math.max((_e = pattern.max) !== null && _e !== void 0 ? _e : Infinity, 1);
49
+ model = pattern.zeroOrMore;
50
+ _type = 'zero or more';
51
+ }
52
+ else {
53
+ throw new Error('Unreachable code');
54
+ }
55
+ ptLog('%s: %o', _type, model);
56
+ let prevResult = null;
57
+ // eslint-disable-next-line no-constant-condition
58
+ while (true) {
59
+ ptLog('%s', collection);
60
+ const result = (0, recursive_branch_1.recursiveBranch)(model, collection.unmatched, specs, options, depth);
61
+ const added = collection.addMatched(result.matched);
62
+ if (result.type === 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY') {
63
+ ptLog('MATCHED_ZERO: %s', result.query);
64
+ return {
65
+ type: 'MATCHED_ZERO',
66
+ matched: collection.matched,
67
+ unmatched: collection.unmatched,
68
+ zeroMatch: true,
69
+ query: result.query,
70
+ hint: result.hint,
71
+ };
72
+ }
73
+ if (max < collection.matchedCount) {
74
+ collection.max(max);
75
+ ptLog('UNEXPECTED_EXTRA_NODE (max: %s): %s', max, result.query);
76
+ return {
77
+ type: 'UNEXPECTED_EXTRA_NODE',
78
+ matched: collection.matched,
79
+ unmatched: collection.unmatched,
80
+ zeroMatch: result.zeroMatch,
81
+ query: result.query,
82
+ hint: {
83
+ ...result.hint,
84
+ max,
85
+ },
86
+ };
87
+ }
88
+ if (prevResult) {
89
+ if (result.type === 'MISSING_NODE_ONE_OR_MORE' ||
90
+ result.type === 'MISSING_NODE_REQUIRED' ||
91
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
92
+ ptLog('%s(continued): %s', result.type, collection);
93
+ return {
94
+ type: result.type,
95
+ matched: collection.matched,
96
+ unmatched: collection.unmatched,
97
+ zeroMatch: result.zeroMatch,
98
+ query: result.query,
99
+ hint: result.hint,
100
+ };
101
+ }
102
+ ptLog('%s(continued): %s', prevResult.type, collection);
103
+ return prevResult;
104
+ }
105
+ if (added && collection.unmatched.length > 0) {
106
+ continue;
107
+ }
108
+ if (collection.matchedCount + (result.zeroMatch ? 1 : 0) < min) {
109
+ const resultType = result.type === 'MISSING_NODE_REQUIRED' ||
110
+ result.type === 'MISSING_NODE_ONE_OR_MORE' ||
111
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS'
112
+ ? result.type
113
+ : type !== null && type !== void 0 ? type : 'MISSING_NODE_REQUIRED';
114
+ ptLog('%s(in %s): %s', resultType, type, result.query);
115
+ return {
116
+ type: resultType,
117
+ matched: collection.matched,
118
+ unmatched: collection.unmatched,
119
+ zeroMatch: result.zeroMatch,
120
+ query: result.query,
121
+ hint: result.hint,
122
+ };
123
+ }
124
+ const resultType = collection.matched.length === 0 ? 'MATCHED_ZERO' : 'MATCHED';
125
+ const zeroMatch = result.zeroMatch || min === 0 || resultType === 'MATCHED_ZERO';
126
+ const matchedResult = {
127
+ type: resultType,
128
+ matched: collection.matched,
129
+ unmatched: collection.unmatched,
130
+ zeroMatch,
131
+ query: result.query,
132
+ hint: result.hint,
133
+ };
134
+ if (!prevResult && collection.unmatched.length) {
135
+ ptLog('continue checking');
136
+ prevResult = matchedResult;
137
+ continue;
138
+ }
139
+ ptLog('%s: %s', resultType, collection);
140
+ if (result.type === 'MISSING_NODE_REQUIRED' ||
141
+ result.type === 'MISSING_NODE_ONE_OR_MORE' ||
142
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
143
+ return {
144
+ type: result.type,
145
+ matched: collection.matched,
146
+ unmatched: collection.unmatched,
147
+ zeroMatch: result.zeroMatch,
148
+ query: result.query,
149
+ hint: result.hint,
150
+ };
151
+ }
152
+ return matchedResult;
153
+ }
154
+ }
155
+ exports.countPattern = countPattern;
@@ -0,0 +1,30 @@
1
+ /// <reference types="debug" />
2
+ export declare const cmLog: import("debug").Debugger;
3
+ export declare const bgGreen: {
4
+ (): void;
5
+ bold(): void;
6
+ };
7
+ export declare const green: {
8
+ (): void;
9
+ bold(): void;
10
+ };
11
+ export declare const bgRed: {
12
+ (): void;
13
+ bold(): void;
14
+ };
15
+ export declare const bgBlue: {
16
+ (): void;
17
+ bold(): void;
18
+ };
19
+ export declare const blue: {
20
+ (): void;
21
+ bold(): void;
22
+ };
23
+ export declare const bgMagenta: {
24
+ (): void;
25
+ bold(): void;
26
+ };
27
+ export declare const cyan: {
28
+ (): void;
29
+ bold(): void;
30
+ };
@@ -0,0 +1,14 @@
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
+ const fn = () => { };
7
+ 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;
@@ -0,0 +1,3 @@
1
+ /// <reference types="debug" />
2
+ export declare const cmLog: import("debug").Debugger;
3
+ export { bgGreen, green, bgRed, bgBlue, blue, bgMagenta, cyan } from 'ansi-colors';
@@ -0,0 +1,13 @@
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; } });