@markuplint/ml-core 3.11.0 → 4.0.0-alpha.1

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 (95) hide show
  1. package/lib/configs.browser.js +1 -5
  2. package/lib/configs.js +33 -30
  3. package/lib/convert-ruleset.d.ts +1 -1
  4. package/lib/convert-ruleset.js +3 -8
  5. package/lib/debug.js +9 -14
  6. package/lib/index.d.ts +12 -12
  7. package/lib/index.js +13 -29
  8. package/lib/ml-core.d.ts +2 -2
  9. package/lib/ml-core.js +60 -66
  10. package/lib/ml-dom/helper/accname.d.ts +1 -1
  11. package/lib/ml-dom/helper/accname.js +9 -16
  12. package/lib/ml-dom/helper/create-node.d.ts +2 -2
  13. package/lib/ml-dom/helper/create-node.js +11 -15
  14. package/lib/ml-dom/helper/debug.d.ts +1 -1
  15. package/lib/ml-dom/helper/debug.js +2 -7
  16. package/lib/ml-dom/helper/getIndent.d.ts +2 -2
  17. package/lib/ml-dom/helper/getIndent.js +15 -19
  18. package/lib/ml-dom/helper/walkers.d.ts +1 -1
  19. package/lib/ml-dom/helper/walkers.js +2 -7
  20. package/lib/ml-dom/index.d.ts +9 -9
  21. package/lib/ml-dom/index.js +1 -5
  22. package/lib/ml-dom/manipulations/child-node-methods.d.ts +2 -2
  23. package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
  24. package/lib/ml-dom/manipulations/get-children.d.ts +2 -2
  25. package/lib/ml-dom/manipulations/get-children.js +3 -7
  26. package/lib/ml-dom/node/attr.d.ts +5 -5
  27. package/lib/ml-dom/node/attr.js +28 -33
  28. package/lib/ml-dom/node/block.d.ts +4 -4
  29. package/lib/ml-dom/node/block.js +7 -11
  30. package/lib/ml-dom/node/character-data.d.ts +2 -2
  31. package/lib/ml-dom/node/character-data.js +11 -16
  32. package/lib/ml-dom/node/child-node.d.ts +6 -6
  33. package/lib/ml-dom/node/child-node.js +1 -5
  34. package/lib/ml-dom/node/comment.d.ts +2 -2
  35. package/lib/ml-dom/node/comment.js +2 -6
  36. package/lib/ml-dom/node/document-fragment.d.ts +2 -2
  37. package/lib/ml-dom/node/document-fragment.js +4 -9
  38. package/lib/ml-dom/node/document-type.d.ts +4 -4
  39. package/lib/ml-dom/node/document-type.js +7 -11
  40. package/lib/ml-dom/node/document.d.ts +13 -13
  41. package/lib/ml-dom/node/document.js +233 -241
  42. package/lib/ml-dom/node/dom-token-list.d.ts +1 -1
  43. package/lib/ml-dom/node/dom-token-list.js +25 -31
  44. package/lib/ml-dom/node/element.d.ts +8 -8
  45. package/lib/ml-dom/node/element.js +278 -296
  46. package/lib/ml-dom/node/named-node-map.d.ts +1 -1
  47. package/lib/ml-dom/node/named-node-map.js +10 -18
  48. package/lib/ml-dom/node/node-list.d.ts +2 -2
  49. package/lib/ml-dom/node/node-list.js +6 -14
  50. package/lib/ml-dom/node/node-store.d.ts +2 -2
  51. package/lib/ml-dom/node/node-store.js +9 -12
  52. package/lib/ml-dom/node/node.d.ts +8 -8
  53. package/lib/ml-dom/node/node.js +58 -66
  54. package/lib/ml-dom/node/parent-node.d.ts +2 -2
  55. package/lib/ml-dom/node/parent-node.js +22 -29
  56. package/lib/ml-dom/node/rule-mapper.d.ts +2 -2
  57. package/lib/ml-dom/node/rule-mapper.js +11 -16
  58. package/lib/ml-dom/node/text.d.ts +2 -2
  59. package/lib/ml-dom/node/text.js +6 -11
  60. package/lib/ml-dom/node/types.d.ts +10 -10
  61. package/lib/ml-dom/node/types.js +1 -2
  62. package/lib/ml-dom/node/unexpected-call-error.js +1 -4
  63. package/lib/ml-dom/token/token.js +19 -23
  64. package/lib/ml-rule/create-rule.d.ts +1 -1
  65. package/lib/ml-rule/create-rule.js +1 -5
  66. package/lib/ml-rule/create-test-rule.d.ts +2 -2
  67. package/lib/ml-rule/create-test-rule.js +3 -7
  68. package/lib/ml-rule/index.d.ts +3 -3
  69. package/lib/ml-rule/index.js +3 -6
  70. package/lib/ml-rule/ml-rule-context.d.ts +2 -2
  71. package/lib/ml-rule/ml-rule-context.js +7 -11
  72. package/lib/ml-rule/ml-rule.d.ts +3 -3
  73. package/lib/ml-rule/ml-rule.js +23 -30
  74. package/lib/ml-rule/types.d.ts +2 -2
  75. package/lib/ml-rule/types.js +1 -2
  76. package/lib/plugin/index.d.ts +2 -2
  77. package/lib/plugin/index.js +2 -5
  78. package/lib/plugin/plugin.d.ts +1 -1
  79. package/lib/plugin/plugin.js +1 -5
  80. package/lib/plugin/types.d.ts +1 -1
  81. package/lib/plugin/types.js +1 -2
  82. package/lib/ruleset/index.js +4 -8
  83. package/lib/test/index.d.ts +4 -4
  84. package/lib/test/index.js +13 -23
  85. package/lib/types.d.ts +2 -2
  86. package/lib/types.js +1 -2
  87. package/lib/utils/get-location-from-chars.js +1 -5
  88. package/lib/utils/index.d.ts +1 -1
  89. package/lib/utils/index.js +1 -5
  90. package/lib/utils/string-splice.js +1 -5
  91. package/package.json +20 -15
  92. package/test/ml-dom/helper/accname.spec.js +0 -85
  93. package/test/ml-dom/helper/create-node.spec.js +0 -18
  94. package/test/ml-dom/index.spec.js +0 -680
  95. package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
@@ -1,37 +1,34 @@
1
- "use strict";
2
1
  var _MLRule_f, _MLRule_v;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLRule = void 0;
5
- const tslib_1 = require("tslib");
6
- const ml_config_1 = require("@markuplint/ml-config");
7
- const is_plain_object_1 = require("is-plain-object");
8
- const ml_rule_context_1 = require("./ml-rule-context");
9
- class MLRule {
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { deleteUndefProp } from '@markuplint/ml-config';
4
+ // @ts-ignore
5
+ import { isPlainObject } from 'is-plain-object';
6
+ import { MLRuleContext } from './ml-rule-context.js';
7
+ export class MLRule {
10
8
  constructor(o) {
11
- var _a;
12
9
  _MLRule_f.set(this, void 0);
13
10
  _MLRule_v.set(this, void 0);
14
11
  this.name = o.name;
15
- this.defaultSeverity = (_a = o.defaultSeverity) !== null && _a !== void 0 ? _a : 'error';
12
+ this.defaultSeverity = o.defaultSeverity ?? 'error';
16
13
  // TODO: https://github.com/markuplint/markuplint/issues/808
17
14
  this.defaultValue = (o.defaultValue !== undefined ? o.defaultValue : true);
18
15
  this.defaultOptions = o.defaultOptions;
19
- tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
20
- tslib_1.__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
16
+ __classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
17
+ __classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
21
18
  }
22
19
  /**
23
20
  * The following getter is unused internally,
24
21
  * only for extending from 3rd party library
25
22
  */
26
23
  get f() {
27
- return tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f");
24
+ return __classPrivateFieldGet(this, _MLRule_f, "f");
28
25
  }
29
26
  /**
30
27
  * The following getter is unused internally,
31
28
  * only for extending from 3rd party library
32
29
  */
33
30
  get v() {
34
- return tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f");
31
+ return __classPrivateFieldGet(this, _MLRule_v, "f");
35
32
  }
36
33
  getRuleInfo(ruleSet, ruleName) {
37
34
  const info = this._optimize(ruleSet.rules, ruleName);
@@ -42,7 +39,6 @@ class MLRule {
42
39
  };
43
40
  }
44
41
  optimizeOption(configSettings) {
45
- var _a;
46
42
  if (configSettings === undefined || typeof configSettings === 'boolean') {
47
43
  return {
48
44
  disabled: !configSettings,
@@ -55,7 +51,7 @@ class MLRule {
55
51
  if (isRuleConfig(configSettings)) {
56
52
  return {
57
53
  disabled: false,
58
- severity: (_a = configSettings.severity) !== null && _a !== void 0 ? _a : this.defaultSeverity,
54
+ severity: configSettings.severity ?? this.defaultSeverity,
59
55
  value: configSettings.value === undefined ||
60
56
  // @ts-ignore
61
57
  configSettings.value === true
@@ -77,14 +73,13 @@ class MLRule {
77
73
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
78
74
  document, locale, fix) {
79
75
  document.setRule(this);
80
- const context = new ml_rule_context_1.MLRuleContext(document, locale);
76
+ const context = new MLRuleContext(document, locale);
81
77
  const providableContext = context.provide();
82
- await tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
83
- if (tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
84
- await tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
78
+ await __classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
79
+ if (__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
80
+ await __classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
85
81
  }
86
82
  const violation = context.reports.map(report => {
87
- var _a;
88
83
  if ('scope' in report) {
89
84
  let line = report.scope.startLine;
90
85
  let col = report.scope.startCol;
@@ -101,9 +96,9 @@ class MLRule {
101
96
  col,
102
97
  raw,
103
98
  ruleId: this.name,
104
- reason: (_a = report.scope.rule.reason) !== null && _a !== void 0 ? _a : document.rule.reason,
99
+ reason: report.scope.rule.reason ?? document.rule.reason,
105
100
  };
106
- (0, ml_config_1.deleteUndefProp)(violation);
101
+ deleteUndefProp(violation);
107
102
  return violation;
108
103
  }
109
104
  const violation = {
@@ -115,32 +110,30 @@ class MLRule {
115
110
  ruleId: this.name,
116
111
  reason: document.rule.reason,
117
112
  };
118
- (0, ml_config_1.deleteUndefProp)(violation);
113
+ deleteUndefProp(violation);
119
114
  return violation;
120
115
  });
121
116
  document.setRule(null);
122
117
  return violation;
123
118
  }
124
119
  _optimize(rules, ruleName) {
125
- var _a;
126
- const rule = ((_a = rules === null || rules === void 0 ? void 0 : rules[ruleName]) !== null && _a !== void 0 ? _a : false);
120
+ const rule = (rules?.[ruleName] ?? false);
127
121
  const info = this.optimizeOption(rule);
128
122
  return info;
129
123
  }
130
124
  }
131
- exports.MLRule = MLRule;
132
125
  _MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
133
126
  function isRuleConfig(data) {
134
- return (0, is_plain_object_1.isPlainObject)(data);
127
+ return isPlainObject(data);
135
128
  }
136
129
  function mergeOptions(a, b) {
137
130
  if (Array.isArray(a) && Array.isArray(b)) {
138
131
  // @ts-ignore
139
132
  return [...a, ...b];
140
133
  }
141
- if ((0, is_plain_object_1.isPlainObject)(a) && (0, is_plain_object_1.isPlainObject)(b)) {
134
+ if (isPlainObject(a) && isPlainObject(b)) {
142
135
  // @ts-ignore
143
136
  return { ...a, ...b };
144
137
  }
145
- return b !== null && b !== void 0 ? b : a;
138
+ return b ?? a;
146
139
  }
@@ -1,5 +1,5 @@
1
- import type { MLRuleContext } from './ml-rule-context';
2
- import type { Attr, Element } from '../ml-dom';
1
+ import type { MLRuleContext } from './ml-rule-context.js';
2
+ import type { Attr, Element } from '../ml-dom/index.js';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
5
  export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1,2 @@
1
- export * from './plugin';
2
- export * from './types';
1
+ export * from './plugin.js';
2
+ export * from './types.js';
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./plugin"), exports);
5
- tslib_1.__exportStar(require("./types"), exports);
1
+ export * from './plugin.js';
2
+ export * from './types.js';
@@ -1,2 +1,2 @@
1
- import type { PluginCreator, CreatePluginSettings } from './types';
1
+ import type { PluginCreator, CreatePluginSettings } from './types.js';
2
2
  export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): Readonly<PluginCreator<S>>;
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPlugin = void 0;
4
- function createPlugin(fn) {
1
+ export function createPlugin(fn) {
5
2
  return fn;
6
3
  }
7
- exports.createPlugin = createPlugin;
@@ -1,4 +1,4 @@
1
- import type { RuleSeed } from '../ml-rule';
1
+ import type { RuleSeed } from '../ml-rule/index.js';
2
2
  import type { Config } from '@markuplint/ml-config';
3
3
  export type Plugin = {
4
4
  readonly name: string;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Ruleset {
1
+ export default class Ruleset {
4
2
  constructor(config) {
5
- var _a, _b, _c;
6
- this.rules = (_a = config.rules) !== null && _a !== void 0 ? _a : {};
7
- this.nodeRules = (_b = config.nodeRules) !== null && _b !== void 0 ? _b : [];
8
- this.childNodeRules = (_c = config.childNodeRules) !== null && _c !== void 0 ? _c : [];
3
+ this.rules = config.rules ?? {};
4
+ this.nodeRules = config.nodeRules ?? [];
5
+ this.childNodeRules = config.childNodeRules ?? [];
9
6
  }
10
7
  }
11
- exports.default = Ruleset;
@@ -1,16 +1,16 @@
1
1
  import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
2
2
  import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
4
- import { Document } from '../ml-dom';
4
+ import { Document } from '../ml-dom/index.js';
5
5
  export type CreateTestOptions = {
6
6
  readonly config?: Config;
7
7
  readonly parser?: Readonly<MLMarkupLanguageParser>;
8
8
  readonly specs?: MLMLSpec;
9
9
  };
10
10
  export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
11
- export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[];
12
- export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token").MLToken<import("@markuplint/ml-ast").MLToken>[];
13
- export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom").Element<any, any>;
11
+ export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[];
12
+ export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLToken>[];
13
+ export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom/index.js").Element<any, any>;
14
14
  /**
15
15
  * for test suite
16
16
  */
package/lib/test/index.js CHANGED
@@ -1,30 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dummySchemas = exports.createTestElement = exports.createTestTokenList = exports.createTestNodeList = exports.createTestDocument = void 0;
4
- const tslib_1 = require("tslib");
5
- const html_parser_1 = require("@markuplint/html-parser");
6
- const html_spec_1 = tslib_1.__importDefault(require("@markuplint/html-spec"));
7
- const convert_ruleset_1 = require("../convert-ruleset");
8
- const ml_dom_1 = require("../ml-dom");
9
- function createTestDocument(sourceCode, options) {
10
- var _a;
11
- const ast = (options === null || options === void 0 ? void 0 : options.parser) ? options.parser.parse(sourceCode) : (0, html_parser_1.parse)(sourceCode);
12
- const ruleset = (0, convert_ruleset_1.convertRuleset)(options === null || options === void 0 ? void 0 : options.config);
13
- const document = new ml_dom_1.Document(ast, ruleset, [(_a = options === null || options === void 0 ? void 0 : options.specs) !== null && _a !== void 0 ? _a : {}, {}]);
1
+ import { parse } from '@markuplint/html-parser';
2
+ import spec from '@markuplint/html-spec';
3
+ import { convertRuleset } from '../convert-ruleset.js';
4
+ import { Document } from '../ml-dom/index.js';
5
+ export function createTestDocument(sourceCode, options) {
6
+ const ast = options?.parser ? options.parser.parse(sourceCode) : parse(sourceCode);
7
+ const ruleset = convertRuleset(options?.config);
8
+ const document = new Document(ast, ruleset, [options?.specs ?? {}, {}]);
14
9
  return document;
15
10
  }
16
- exports.createTestDocument = createTestDocument;
17
- function createTestNodeList(sourceCode, options) {
11
+ export function createTestNodeList(sourceCode, options) {
18
12
  const document = createTestDocument(sourceCode, options);
19
13
  return document.nodeList;
20
14
  }
21
- exports.createTestNodeList = createTestNodeList;
22
- function createTestTokenList(sourceCode, options) {
15
+ export function createTestTokenList(sourceCode, options) {
23
16
  const document = createTestDocument(sourceCode, options);
24
17
  return document.getTokenList();
25
18
  }
26
- exports.createTestTokenList = createTestTokenList;
27
- function createTestElement(sourceCode, options) {
19
+ export function createTestElement(sourceCode, options) {
28
20
  const document = createTestDocument(sourceCode, options);
29
21
  const el = document.nodeList[0];
30
22
  if (el && el.is(el.ELEMENT_NODE)) {
@@ -32,11 +24,9 @@ function createTestElement(sourceCode, options) {
32
24
  }
33
25
  throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
34
26
  }
35
- exports.createTestElement = createTestElement;
36
27
  /**
37
28
  * for test suite
38
29
  */
39
- function dummySchemas() {
40
- return [html_spec_1.default];
30
+ export function dummySchemas() {
31
+ return [spec];
41
32
  }
42
- exports.dummySchemas = dummySchemas;
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AnyMLRule } from './ml-rule';
2
- import type Ruleset from './ruleset';
1
+ import type { AnyMLRule } from './ml-rule/index.js';
2
+ import type Ruleset from './ruleset/index.js';
3
3
  import type { LocaleSet } from '@markuplint/i18n';
4
4
  import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
5
5
  import type { Pretender } from '@markuplint/ml-config';
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocationFromChars = void 0;
4
- function getLocationFromChars(searches, text, currentLine, currentCol) {
1
+ export function getLocationFromChars(searches, text, currentLine, currentCol) {
5
2
  const lines = text.split(/\r?\n/g);
6
3
  const foundLocations = [];
7
4
  lines.forEach((lineText, i) => {
@@ -25,4 +22,3 @@ function getLocationFromChars(searches, text, currentLine, currentCol) {
25
22
  });
26
23
  return foundLocations;
27
24
  }
28
- exports.getLocationFromChars = getLocationFromChars;
@@ -1 +1 @@
1
- export { getLocationFromChars } from './get-location-from-chars';
1
+ export { getLocationFromChars } from './get-location-from-chars.js';
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocationFromChars = void 0;
4
- var get_location_from_chars_1 = require("./get-location-from-chars");
5
- Object.defineProperty(exports, "getLocationFromChars", { enumerable: true, get: function () { return get_location_from_chars_1.getLocationFromChars; } });
1
+ export { getLocationFromChars } from './get-location-from-chars.js';
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringSplice = void 0;
4
- function stringSplice(str, start, count, add = '') {
1
+ export function stringSplice(str, start, count, add = '') {
5
2
  if (start < 0) {
6
3
  start = str.length + start;
7
4
  if (start < 0) {
@@ -10,4 +7,3 @@ function stringSplice(str, start, count, add = '') {
10
7
  }
11
8
  return str.slice(0, start) + add + str.slice(start + count);
12
9
  }
13
- exports.stringSplice = stringSplice;
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "3.11.0",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
10
- "types": "lib/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
13
18
  },
@@ -23,20 +28,20 @@
23
28
  "./lib/configs.js": "./lib/configs.browser.js"
24
29
  },
25
30
  "dependencies": {
26
- "@markuplint/config-presets": "3.7.0",
27
- "@markuplint/html-parser": "3.9.0",
28
- "@markuplint/html-spec": "3.10.0",
29
- "@markuplint/i18n": "3.9.0",
30
- "@markuplint/ml-ast": "3.2.0",
31
- "@markuplint/ml-config": "3.10.0",
32
- "@markuplint/ml-spec": "3.10.0",
33
- "@markuplint/parser-utils": "3.9.0",
34
- "@markuplint/selector": "3.10.0",
31
+ "@markuplint/config-presets": "4.0.0-alpha.1",
32
+ "@markuplint/html-parser": "4.0.0-alpha.1",
33
+ "@markuplint/html-spec": "4.0.0-alpha.1",
34
+ "@markuplint/i18n": "4.0.0-alpha.1",
35
+ "@markuplint/ml-ast": "4.0.0-alpha.1",
36
+ "@markuplint/ml-config": "4.0.0-alpha.1",
37
+ "@markuplint/ml-spec": "4.0.0-alpha.1",
38
+ "@markuplint/parser-utils": "4.0.0-alpha.1",
39
+ "@markuplint/selector": "4.0.0-alpha.1",
35
40
  "@types/debug": "^4.1.8",
36
41
  "debug": "^4.3.4",
37
42
  "is-plain-object": "^5.0.0",
38
- "tslib": "^2.5.3",
39
- "type-fest": "^3.11.1"
43
+ "tslib": "^2.6.1",
44
+ "type-fest": "^4.1.0"
40
45
  },
41
- "gitHead": "9547b8dca20736a93e4d01af2d61bee314ba5718"
46
+ "gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
42
47
  }
@@ -1,85 +0,0 @@
1
- const { parse } = require('@markuplint/html-parser');
2
-
3
- const { convertRuleset } = require('../../../');
4
- const { getAccname } = require('../../../lib/ml-dom/helper/accname');
5
- const { createNode } = require('../../../lib/ml-dom/helper/create-node');
6
- const { MLDocument } = require('../../../lib/ml-dom/node/document');
7
- const { dummySchemas } = require('../../../lib/test');
8
-
9
- function c(sourceCode) {
10
- const ast = parse(sourceCode);
11
- const astNode = ast.nodeList[0];
12
- const ruleset = convertRuleset({});
13
- const document = new MLDocument(ast, ruleset, dummySchemas());
14
- const node = createNode(astNode, document);
15
- if (node.is(node.ELEMENT_NODE)) {
16
- return node;
17
- }
18
- throw new Error();
19
- }
20
-
21
- test('Get accessible name', () => {
22
- expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
23
- expect(getAccname(c('<div>text</div>'), '1.2')).toBe('');
24
- expect(getAccname(c('<div aria-label="label">text</div>'), '1.2')).toBe('label');
25
- expect(getAccname(c('<span aria-label="label">text</span>'), '1.2')).toBe('label');
26
- expect(getAccname(c('<img alt="alternative-text" />'), '1.2')).toBe('alternative-text');
27
- expect(getAccname(c('<img title="title" />'), '1.2')).toBe('title');
28
- expect(getAccname(c('<div><label for="a">label</label><input id="a" /></div>').children[1], '1.2')).toBe('label');
29
- });
30
-
31
- test('Invisible element', () => {
32
- expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
33
- expect(getAccname(c('<button aria-disabled="true">label</button>'), '1.2')).toBe('label');
34
- expect(getAccname(c('<button aria-hidden="true">label</button>'), '1.2')).toBe('');
35
- expect(getAccname(c('<button hidden>label</button>'), '1.2')).toBe('');
36
- expect(getAccname(c('<button style="display: none">label</button>'), '1.2')).toBe('label'); // Do not support the style attribute yet.
37
- });
38
-
39
- /**
40
- * @see https://www.w3.org/TR/accname-1.1/#ex-1-example-1-element1-id-el1-aria-labelledby-el3-element2-id-el2-aria-labelledby-el1-element3-id-el3-hello-element3
41
- */
42
- test('accname-1.1 Example 1', () => {
43
- const complex = c(`<div>
44
- <input id="el1" aria-labelledby="el3" />
45
- <input id="el2" aria-labelledby="el1" />
46
- <h1 id="el3"> hello </h1>
47
- </div>`);
48
- expect(getAccname(complex.children[0], '1.2')).toBe('hello');
49
- expect(getAccname(complex.children[1], '1.2')).toBe('');
50
- expect(getAccname(complex.children[2], '1.2')).toBe('hello');
51
- });
52
-
53
- /**
54
- * https://www.w3.org/TR/accname-1.1/#ex-2-example-2-h1-files-h1-ul-li-a-id-file_row1-href-files-documentation-pdf-documentation-pdf-a-span-role-button-tabindex-0-id-del_row1-aria-label-delete-aria-labelledby-del_row1-file_row1-span-li-li-a-id-file_row2-href-files-holidayletter-pdf-holidayletter-pdf-a-span-role-button-tabindex-0-id-del_row2-aria-label-delete-aria-labelledby-del_row2-file_row2-span-li-ul
55
- */
56
- test('accname-1.1 Example 2', () => {
57
- const complex = c(`<ul>
58
- <li>
59
- <a id="file_row1" href="./files/Documentation.pdf">Documentation.pdf</a>
60
- <span role="button" tabindex="0" id="del_row1" aria-label="Delete" aria-labelledby="del_row1 file_row1"></span>
61
- </li>
62
- <li>
63
- <a id="file_row2" href="./files/HolidayLetter.pdf">HolidayLetter.pdf</a>
64
- <span role="button" tabindex="0" id="del_row2" aria-label="Delete" aria-labelledby="del_row2 file_row2"></span>
65
- </li>
66
- </ul>`);
67
- const spans = complex.querySelectorAll('span');
68
- expect(getAccname(spans[0], '1.2')).toBe('Delete Documentation.pdf');
69
- expect(getAccname(spans[1], '1.2')).toBe('Delete HolidayLetter.pdf');
70
- });
71
-
72
- /**
73
- * https://www.w3.org/TR/accname-1.1/#ex-3-example-3-div-role-checkbox-aria-checked-false-flash-the-screen-span-role-textbox-aria-multiline-false-5-span-times-div
74
- */
75
- test('accname-1.1 Example 3', () => {
76
- const complex = c(
77
- '<div role="checkbox" aria-checked="false">Flash the screen <span role="textbox" aria-multiline="false"> 5 </span> times</div>',
78
- );
79
- expect(getAccname(complex, '1.2')).toBe('Flash the screen 5 times');
80
- });
81
-
82
- test('with comment', () => {
83
- expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
84
- expect(getAccname(c('<button>label<!-- comment --></button>'), '1.2')).toBe('label');
85
- });
@@ -1,18 +0,0 @@
1
- const { parse } = require('@markuplint/html-parser');
2
-
3
- const { convertRuleset } = require('../../../');
4
- const { Document } = require('../../../lib/ml-dom/');
5
- const { createNode } = require('../../../lib/ml-dom/helper/create-node');
6
- const { dummySchemas } = require('../../../lib/test');
7
-
8
- describe('create Node', () => {
9
- it('Element', () => {
10
- const sourceCode = '<div>text</div>';
11
- const ast = parse(sourceCode);
12
- const astNode = ast.nodeList[0];
13
- const ruleset = convertRuleset({});
14
- const document = new Document(ast, ruleset, dummySchemas());
15
- const node = createNode(astNode, document);
16
- expect(node.raw).toBe('<div>');
17
- });
18
- });