@markuplint/ml-core 3.15.0 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +1 -1
  2. package/lib/configs.browser.js +11 -11
  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 +13 -23
  7. package/lib/index.js +12 -29
  8. package/lib/ml-core.d.ts +5 -5
  9. package/lib/ml-core.js +94 -76
  10. package/lib/ml-dom/helper/accname.d.ts +1 -1
  11. package/lib/ml-dom/helper/accname.js +12 -19
  12. package/lib/ml-dom/helper/create-node.d.ts +4 -8
  13. package/lib/ml-dom/helper/create-node.js +38 -17
  14. package/lib/ml-dom/helper/debug.d.ts +1 -1
  15. package/lib/ml-dom/helper/debug.js +13 -22
  16. package/lib/ml-dom/helper/get-indent.d.ts +18 -0
  17. package/lib/ml-dom/helper/get-indent.js +112 -0
  18. package/lib/ml-dom/helper/walkers.d.ts +5 -15
  19. package/lib/ml-dom/helper/walkers.js +3 -8
  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 +7 -20
  23. package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
  24. package/lib/ml-dom/manipulations/get-children.d.ts +3 -5
  25. package/lib/ml-dom/manipulations/get-children.js +3 -7
  26. package/lib/ml-dom/node/attr.d.ts +113 -98
  27. package/lib/ml-dom/node/attr.js +93 -50
  28. package/lib/ml-dom/node/block.d.ts +35 -39
  29. package/lib/ml-dom/node/block.js +8 -14
  30. package/lib/ml-dom/node/character-data.d.ts +55 -62
  31. package/lib/ml-dom/node/character-data.js +11 -16
  32. package/lib/ml-dom/node/child-node.d.ts +8 -15
  33. package/lib/ml-dom/node/child-node.js +1 -5
  34. package/lib/ml-dom/node/comment.d.ts +14 -17
  35. package/lib/ml-dom/node/comment.js +2 -6
  36. package/lib/ml-dom/node/document-fragment.d.ts +22 -25
  37. package/lib/ml-dom/node/document-fragment.js +4 -9
  38. package/lib/ml-dom/node/document-type.d.ts +35 -38
  39. package/lib/ml-dom/node/document-type.js +8 -14
  40. package/lib/ml-dom/node/document.d.ts +1598 -1614
  41. package/lib/ml-dom/node/document.js +330 -275
  42. package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
  43. package/lib/ml-dom/node/dom-token-list.js +36 -32
  44. package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
  45. package/lib/ml-dom/node/element-close-tag.js +39 -0
  46. package/lib/ml-dom/node/element.d.ts +1957 -1951
  47. package/lib/ml-dom/node/element.js +364 -348
  48. package/lib/ml-dom/node/named-node-map.d.ts +40 -45
  49. package/lib/ml-dom/node/named-node-map.js +10 -18
  50. package/lib/ml-dom/node/node-list.d.ts +5 -11
  51. package/lib/ml-dom/node/node-list.js +8 -16
  52. package/lib/ml-dom/node/node-store.d.ts +6 -11
  53. package/lib/ml-dom/node/node-store.js +14 -13
  54. package/lib/ml-dom/node/node.d.ts +480 -500
  55. package/lib/ml-dom/node/node.js +83 -73
  56. package/lib/ml-dom/node/parent-node.d.ts +60 -69
  57. package/lib/ml-dom/node/parent-node.js +32 -29
  58. package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
  59. package/lib/ml-dom/node/rule-mapper.js +26 -21
  60. package/lib/ml-dom/node/text.d.ts +48 -51
  61. package/lib/ml-dom/node/text.js +8 -13
  62. package/lib/ml-dom/node/types.d.ts +42 -90
  63. package/lib/ml-dom/node/types.js +1 -2
  64. package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
  65. package/lib/ml-dom/node/unexpected-call-error.js +1 -4
  66. package/lib/ml-dom/token/token.d.ts +45 -45
  67. package/lib/ml-dom/token/token.js +32 -26
  68. package/lib/ml-rule/create-rule.d.ts +2 -4
  69. package/lib/ml-rule/create-rule.js +1 -5
  70. package/lib/ml-rule/create-test-rule.d.ts +5 -7
  71. package/lib/ml-rule/create-test-rule.js +3 -7
  72. package/lib/ml-rule/index.d.ts +3 -3
  73. package/lib/ml-rule/index.js +3 -6
  74. package/lib/ml-rule/ml-rule-context.d.ts +49 -57
  75. package/lib/ml-rule/ml-rule-context.js +11 -11
  76. package/lib/ml-rule/ml-rule.d.ts +26 -36
  77. package/lib/ml-rule/ml-rule.js +34 -31
  78. package/lib/ml-rule/types.d.ts +18 -33
  79. package/lib/ml-rule/types.js +1 -2
  80. package/lib/plugin/index.d.ts +2 -2
  81. package/lib/plugin/index.js +2 -5
  82. package/lib/plugin/plugin.d.ts +2 -4
  83. package/lib/plugin/plugin.js +1 -5
  84. package/lib/plugin/types.d.ts +6 -6
  85. package/lib/plugin/types.js +1 -2
  86. package/lib/ruleset/index.d.ts +5 -5
  87. package/lib/ruleset/index.js +4 -8
  88. package/lib/test/index.d.ts +11 -21
  89. package/lib/test/index.js +18 -24
  90. package/lib/types.d.ts +11 -11
  91. package/lib/types.js +1 -2
  92. package/lib/utils/get-location-from-chars.d.ts +4 -9
  93. package/lib/utils/get-location-from-chars.js +4 -8
  94. package/lib/utils/index.d.ts +1 -1
  95. package/lib/utils/index.js +1 -5
  96. package/lib/utils/string-splice.js +1 -5
  97. package/package.json +19 -15
  98. package/lib/configs.d.ts +0 -2
  99. package/lib/configs.js +0 -34
  100. package/lib/ml-dom/helper/getIndent.d.ts +0 -18
  101. package/lib/ml-dom/helper/getIndent.js +0 -106
  102. package/test/ml-dom/helper/accname.spec.js +0 -85
  103. package/test/ml-dom/helper/create-node.spec.js +0 -18
  104. package/test/ml-dom/index.spec.js +0 -680
  105. package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
@@ -1,47 +1,42 @@
1
- import type { MLAttr } from './attr';
1
+ import type { MLAttr } from './attr.js';
2
2
  import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
- export declare class MLNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>
4
- extends Array<MLAttr<T, O>>
5
- implements NamedNodeMap
6
- {
7
- getNamedItem(qualifiedName: string): MLAttr<T, O> | null;
8
- /**
9
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
10
- *
11
- * @unsupported
12
- * @implements DOM API: `NamedNodeMap`
13
- */
14
- getNamedItemNS(namespace: string | null, localName: string): Attr | null;
15
- item(index: number): MLAttr<T, O> | null;
16
- /**
17
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
18
- *
19
- * @unsupported
20
- * @implements DOM API: `NamedNodeMap`
21
- */
22
- removeNamedItem(qualifiedName: string): MLAttr<T, O>;
23
- /**
24
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
25
- *
26
- * @unsupported
27
- * @implements DOM API: `NamedNodeMap`
28
- */
29
- removeNamedItemNS(namespace: string | null, localName: string): MLAttr<T, O>;
30
- /**
31
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
32
- *
33
- * @unsupported
34
- * @implements DOM API: `NamedNodeMap`
35
- */
36
- setNamedItem(attr: MLAttr<T, O>): MLAttr<T, O> | null;
37
- /**
38
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
39
- *
40
- * @unsupported
41
- * @implements DOM API: `NamedNodeMap`
42
- */
43
- setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
3
+ export declare class MLNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined> extends Array<MLAttr<T, O>> implements NamedNodeMap {
4
+ getNamedItem(qualifiedName: string): MLAttr<T, O> | null;
5
+ /**
6
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
7
+ *
8
+ * @unsupported
9
+ * @implements DOM API: `NamedNodeMap`
10
+ */
11
+ getNamedItemNS(namespace: string | null, localName: string): Attr | null;
12
+ item(index: number): MLAttr<T, O> | null;
13
+ /**
14
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
15
+ *
16
+ * @unsupported
17
+ * @implements DOM API: `NamedNodeMap`
18
+ */
19
+ removeNamedItem(qualifiedName: string): MLAttr<T, O>;
20
+ /**
21
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
22
+ *
23
+ * @unsupported
24
+ * @implements DOM API: `NamedNodeMap`
25
+ */
26
+ removeNamedItemNS(namespace: string | null, localName: string): MLAttr<T, O>;
27
+ /**
28
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
29
+ *
30
+ * @unsupported
31
+ * @implements DOM API: `NamedNodeMap`
32
+ */
33
+ setNamedItem(attr: MLAttr<T, O>): MLAttr<T, O> | null;
34
+ /**
35
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
36
+ *
37
+ * @unsupported
38
+ * @implements DOM API: `NamedNodeMap`
39
+ */
40
+ setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
44
41
  }
45
- export declare function toNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>(
46
- nodes: ReadonlyArray<MLAttr<T, O>>,
47
- ): MLNamedNodeMap<T, O>;
42
+ export declare function toNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>(nodes: ReadonlyArray<MLAttr<T, O>>): MLNamedNodeMap<T, O>;
@@ -1,12 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toNamedNodeMap = exports.MLNamedNodeMap = void 0;
4
- const tslib_1 = require("tslib");
5
- const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
6
- class MLNamedNodeMap extends Array {
1
+ import { UnexpectedCallError } from './unexpected-call-error.js';
2
+ export class MLNamedNodeMap extends Array {
7
3
  getNamedItem(qualifiedName) {
8
- var _a;
9
- return (_a = this.find(attr => attr.name === qualifiedName)) !== null && _a !== void 0 ? _a : null;
4
+ return this.find(attr => attr.name === qualifiedName) ?? null;
10
5
  }
11
6
  /**
12
7
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -15,11 +10,10 @@ class MLNamedNodeMap extends Array {
15
10
  * @implements DOM API: `NamedNodeMap`
16
11
  */
17
12
  getNamedItemNS(namespace, localName) {
18
- throw new unexpected_call_error_1.default('Not supported "getNamedItemNS" method');
13
+ throw new UnexpectedCallError('Not supported "getNamedItemNS" method');
19
14
  }
20
15
  item(index) {
21
- var _a;
22
- return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
16
+ return this[index] ?? null;
23
17
  }
24
18
  /**
25
19
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -28,7 +22,7 @@ class MLNamedNodeMap extends Array {
28
22
  * @implements DOM API: `NamedNodeMap`
29
23
  */
30
24
  removeNamedItem(qualifiedName) {
31
- throw new unexpected_call_error_1.default('Not supported "removeNamedItem" method');
25
+ throw new UnexpectedCallError('Not supported "removeNamedItem" method');
32
26
  }
33
27
  /**
34
28
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -37,7 +31,7 @@ class MLNamedNodeMap extends Array {
37
31
  * @implements DOM API: `NamedNodeMap`
38
32
  */
39
33
  removeNamedItemNS(namespace, localName) {
40
- throw new unexpected_call_error_1.default('Not supported "removeNamedItemNS" method');
34
+ throw new UnexpectedCallError('Not supported "removeNamedItemNS" method');
41
35
  }
42
36
  /**
43
37
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -48,7 +42,7 @@ class MLNamedNodeMap extends Array {
48
42
  setNamedItem(
49
43
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
50
44
  attr) {
51
- throw new unexpected_call_error_1.default('Not supported "setNamedItem" method');
45
+ throw new UnexpectedCallError('Not supported "setNamedItem" method');
52
46
  }
53
47
  /**
54
48
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -59,14 +53,12 @@ class MLNamedNodeMap extends Array {
59
53
  setNamedItemNS(
60
54
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
61
55
  attr) {
62
- throw new unexpected_call_error_1.default('Not supported "setNamedItemNS" method');
56
+ throw new UnexpectedCallError('Not supported "setNamedItemNS" method');
63
57
  }
64
58
  }
65
- exports.MLNamedNodeMap = MLNamedNodeMap;
66
- function toNamedNodeMap(
59
+ export function toNamedNodeMap(
67
60
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
68
61
  nodes) {
69
62
  const namedNodeMap = new MLNamedNodeMap(...nodes);
70
63
  return namedNodeMap;
71
64
  }
72
- exports.toNamedNodeMap = toNamedNodeMap;
@@ -1,12 +1,6 @@
1
- import type { MLChildNode } from './child-node';
2
- import type { MLElement } from './element';
1
+ import type { MLChildNode } from './child-node.js';
2
+ import type { MLElement } from './element.js';
3
3
  import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
4
- export declare function toNodeList<T extends RuleConfigValue, O extends PlainData, N extends MLChildNode<T, O>>(
5
- nodes: ReadonlyArray<N>,
6
- ): NodeListOf<N>;
7
- export declare function toHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
8
- nodes: ReadonlyArray<MLElement<T, O>>,
9
- ): HTMLCollectionOf<MLElement<T, O>>;
10
- export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
11
- nodeList: NodeListOf<MLChildNode<T, O>>,
12
- ): HTMLCollectionOf<MLElement<T, O>>;
4
+ export declare function toNodeList<T extends RuleConfigValue, O extends PlainData, N extends MLChildNode<T, O>>(nodes: ReadonlyArray<N>): NodeListOf<N>;
5
+ export declare function toHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(nodes: ReadonlyArray<MLElement<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
6
+ export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(nodeList: NodeListOf<MLChildNode<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodeListToHTMLCollection = exports.toHTMLCollection = exports.toNodeList = void 0;
4
1
  class MLNodeList extends Array {
5
2
  forEach(callbackfn, thisArg) {
6
- return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg !== null && thisArg !== void 0 ? thisArg : this));
3
+ return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg ?? this));
7
4
  }
8
5
  item(index) {
9
6
  const node = this[index];
@@ -23,37 +20,32 @@ class MLNodeList extends Array {
23
20
  return node;
24
21
  }
25
22
  }
26
- function toNodeList(nodes) {
23
+ export function toNodeList(nodes) {
27
24
  const nodeList = new MLNodeList(...nodes);
28
25
  return nodeList;
29
26
  }
30
- exports.toNodeList = toNodeList;
31
27
  class MLHTMLCollection extends Array {
32
28
  item(index) {
33
- var _a;
34
- return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
29
+ return this[index] ?? null;
35
30
  }
36
31
  namedItem(name) {
37
- var _a;
38
- return (_a = this.find(el => el.getAttribute('name') === name)) !== null && _a !== void 0 ? _a : null;
32
+ return this.find(el => el.getAttribute('name') === name) ?? null;
39
33
  }
40
34
  }
41
- function toHTMLCollection(
35
+ export function toHTMLCollection(
42
36
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
43
37
  nodes) {
44
38
  const collection = new MLHTMLCollection(...nodes);
45
39
  return collection;
46
40
  }
47
- exports.toHTMLCollection = toHTMLCollection;
48
- function nodeListToHTMLCollection(
41
+ export function nodeListToHTMLCollection(
49
42
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
50
43
  nodeList) {
51
44
  const collection = new MLHTMLCollection();
52
- nodeList.forEach(node => {
45
+ for (const node of nodeList) {
53
46
  if (node.is(node.ELEMENT_NODE)) {
54
47
  collection.push(node);
55
48
  }
56
- });
49
+ }
57
50
  return collection;
58
51
  }
59
- exports.nodeListToHTMLCollection = nodeListToHTMLCollection;
@@ -1,16 +1,11 @@
1
- import type { MLNode } from './node';
2
- import type { MappedNode } from './types';
3
- import type { MLASTAbstractNode } from '@markuplint/ml-ast';
1
+ import type { MLNode } from './node.js';
2
+ import type { MappedNode } from './types.js';
3
+ import type { MLASTNode } from '@markuplint/ml-ast';
4
4
  import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
5
5
  declare class NodeStore {
6
- #private;
7
- getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
8
- astNode: N,
9
- ): MappedNode<N, T, O>;
10
- setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
11
- astNode: A,
12
- node: MLNode<T, O, A>,
13
- ): void;
6
+ #private;
7
+ getNode<N extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N): MappedNode<N, T, O>;
8
+ setNode<A extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: A, node: MLNode<T, O, A>): void;
14
9
  }
15
10
  /**
16
11
  * `NodeStore` Singleton
@@ -1,11 +1,12 @@
1
- "use strict";
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
2
6
  var _NodeStore_store;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.nodeStore = void 0;
5
- const tslib_1 = require("tslib");
6
- const parser_utils_1 = require("@markuplint/parser-utils");
7
- const debug_1 = require("../../debug");
8
- const nodeStoreLog = debug_1.log.extend('node-store');
7
+ import { TargetParserError } from '@markuplint/parser-utils';
8
+ import { log } from '../../debug.js';
9
+ const nodeStoreLog = log.extend('node-store');
9
10
  const nodeStoreError = nodeStoreLog.extend('error');
10
11
  class NodeStore {
11
12
  constructor() {
@@ -13,14 +14,14 @@ class NodeStore {
13
14
  }
14
15
  getNode(astNode) {
15
16
  // console.log(`Get: ${astNode.uuid} -> ${astNode.raw.trim()}(${astNode.type})`);
16
- const node = tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
17
+ const node = __classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
17
18
  if (!node) {
18
19
  nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
19
- nodeStoreError('Map: %O', Array.from(tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").entries()).map(([id, node]) => ({
20
+ nodeStoreError('Map: %O', [...__classPrivateFieldGet(this, _NodeStore_store, "f").entries()].map(([id, node]) => ({
20
21
  id,
21
22
  name: node.nodeName,
22
23
  })));
23
- throw new parser_utils_1.TargetParserError('Broke mapping nodes.', {
24
+ throw new TargetParserError('Broke mapping nodes.', {
24
25
  line: astNode.startLine,
25
26
  col: astNode.startCol,
26
27
  raw: astNode.raw,
@@ -39,12 +40,12 @@ class NodeStore {
39
40
  nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
40
41
  nodeStoreError('Invalid node: %O', node);
41
42
  }
42
- nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replace(/\n/g, '⏎').replace(/\t/g, '→'));
43
- tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
43
+ nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replaceAll('\n', '⏎').replaceAll('\t', '→'));
44
+ __classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
44
45
  }
45
46
  }
46
47
  _NodeStore_store = new WeakMap();
47
48
  /**
48
49
  * `NodeStore` Singleton
49
50
  */
50
- exports.nodeStore = new NodeStore();
51
+ export const nodeStore = new NodeStore();