@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,33 +1,33 @@
1
- import type { MLAttr } from './attr';
1
+ import type { MLAttr } from './attr.js';
2
2
  import type { RuleInfo } from '@markuplint/ml-config';
3
3
  type Scope = {
4
- raw: string;
5
- startOffset: number;
6
- startLine: number;
7
- startCol: number;
8
- rule: RuleInfo<any, any>;
4
+ raw: string;
5
+ startOffset: number;
6
+ startLine: number;
7
+ startCol: number;
8
+ rule: RuleInfo<any, any>;
9
9
  };
10
10
  export declare class MLDomTokenList extends Array<string> implements DOMTokenList {
11
- #private;
12
- constructor(tokens: string, ownerAttrs: MLAttr<any, any>[]);
13
- get value(): string;
14
- add(...tokens: readonly string[]): void;
15
- /**
16
- * @implements `@markuplint/ml-core` API: `MLDomTokenList`
17
- */
18
- allTokens(): Scope[];
19
- contains(token: string): boolean;
20
- forEach(callbackfn: (value: string, index: number, parent: any) => void, thisArg?: any): void;
21
- item(index: number): string | null;
22
- /**
23
- * @implements `@markuplint/ml-core` API: `MLDomTokenList`
24
- */
25
- pick(token: string): Scope | null;
26
- remove(...tokens: readonly string[]): void;
27
- replace(token: string, newToken: string): boolean;
28
- supports(token: string): boolean;
29
- toString(): string;
30
- toggle(token: string, force?: boolean): boolean;
31
- private _pick;
11
+ #private;
12
+ constructor(tokens: string, ownerAttrs: MLAttr<any, any>[]);
13
+ get value(): string;
14
+ add(...tokens: readonly string[]): void;
15
+ /**
16
+ * @implements `@markuplint/ml-core` API: `MLDomTokenList`
17
+ */
18
+ allTokens(): Scope[];
19
+ contains(token: string): boolean;
20
+ forEach(callbackfn: (value: string, index: number, parent: any) => void, thisArg?: any): void;
21
+ item(index: number): string | null;
22
+ /**
23
+ * @implements `@markuplint/ml-core` API: `MLDomTokenList`
24
+ */
25
+ pick(token: string): Scope | null;
26
+ remove(...tokens: readonly string[]): void;
27
+ replace(token: string, newToken: string): boolean;
28
+ supports(token: string): boolean;
29
+ toString(): string;
30
+ toggle(token: string, force?: boolean): boolean;
31
+ private _pick;
32
32
  }
33
33
  export {};
@@ -1,11 +1,18 @@
1
- "use strict";
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
2
12
  var _MLDomTokenList_origin, _MLDomTokenList_ownerAttrs, _MLDomTokenList_set;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLDomTokenList = void 0;
5
- const tslib_1 = require("tslib");
6
- const parser_utils_1 = require("@markuplint/parser-utils");
7
- const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
8
- class MLDomTokenList extends Array {
13
+ import { getCol, getLine } from '@markuplint/parser-utils/location';
14
+ import { UnexpectedCallError } from './unexpected-call-error.js';
15
+ export class MLDomTokenList extends Array {
9
16
  constructor(tokens,
10
17
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
18
  ownerAttrs) {
@@ -21,29 +28,29 @@ class MLDomTokenList extends Array {
21
28
  */
22
29
  _MLDomTokenList_ownerAttrs.set(this, void 0);
23
30
  _MLDomTokenList_set.set(this, void 0);
24
- tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_origin, tokens, "f");
25
- tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_ownerAttrs, ownerAttrs, "f");
26
- tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_set, new Set(list), "f");
31
+ __classPrivateFieldSet(this, _MLDomTokenList_origin, tokens, "f");
32
+ __classPrivateFieldSet(this, _MLDomTokenList_ownerAttrs, ownerAttrs, "f");
33
+ __classPrivateFieldSet(this, _MLDomTokenList_set, new Set(list), "f");
27
34
  }
28
35
  get value() {
29
36
  return this.join(' ');
30
37
  }
31
38
  add(...tokens) {
32
39
  for (const token of tokens) {
33
- if (tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_set, "f").has(token)) {
40
+ if (__classPrivateFieldGet(this, _MLDomTokenList_set, "f").has(token)) {
34
41
  continue;
35
42
  }
36
- tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_set, "f").add(token);
43
+ __classPrivateFieldGet(this, _MLDomTokenList_set, "f").add(token);
37
44
  this.push(token);
38
45
  }
39
- tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_origin, tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f") + tokens.join(' '), "f");
46
+ __classPrivateFieldSet(this, _MLDomTokenList_origin, __classPrivateFieldGet(this, _MLDomTokenList_origin, "f") + tokens.join(' '), "f");
40
47
  }
41
48
  /**
42
49
  * @implements `@markuplint/ml-core` API: `MLDomTokenList`
43
50
  */
44
51
  allTokens() {
45
52
  let offset = 0;
46
- const tokens = Array.from(this);
53
+ const tokens = [...this];
47
54
  const locs = [];
48
55
  while (tokens.length > 0) {
49
56
  const token = tokens.shift();
@@ -67,14 +74,13 @@ class MLDomTokenList extends Array {
67
74
  return locs;
68
75
  }
69
76
  contains(token) {
70
- return tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_set, "f").has(token);
77
+ return __classPrivateFieldGet(this, _MLDomTokenList_set, "f").has(token);
71
78
  }
72
79
  forEach(callbackfn, thisArg) {
73
- this.forEach.bind(this)((v, i) => callbackfn(v, i, thisArg !== null && thisArg !== void 0 ? thisArg : this));
80
+ this.forEach.bind(this)((v, i) => callbackfn(v, i, thisArg ?? this));
74
81
  }
75
82
  item(index) {
76
- var _a;
77
- return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
83
+ return this[index] ?? null;
78
84
  }
79
85
  /**
80
86
  * @implements `@markuplint/ml-core` API: `MLDomTokenList`
@@ -93,41 +99,40 @@ class MLDomTokenList extends Array {
93
99
  };
94
100
  }
95
101
  remove(...tokens) {
96
- throw new unexpected_call_error_1.default('Not supported "remove" method');
102
+ throw new UnexpectedCallError('Not supported "remove" method');
97
103
  }
98
104
  replace(token, newToken) {
99
- throw new unexpected_call_error_1.default('Not supported "replace" method');
105
+ throw new UnexpectedCallError('Not supported "replace" method');
100
106
  }
101
107
  supports(token) {
102
- throw new unexpected_call_error_1.default('Not supported "supports" method');
108
+ throw new UnexpectedCallError('Not supported "supports" method');
103
109
  }
104
110
  toString() {
105
111
  return this.value;
106
112
  }
107
113
  toggle(token, force) {
108
- throw new unexpected_call_error_1.default('Not supported "toggle" method');
114
+ throw new UnexpectedCallError('Not supported "toggle" method');
109
115
  }
110
116
  _pick(token, _offset = 0) {
111
- var _a, _b, _c, _d, _e, _f, _g;
112
- token = (_a = token.trim().split(/\s+/g)[0]) !== null && _a !== void 0 ? _a : '';
117
+ token = token.trim().split(/\s+/)[0] ?? '';
113
118
  if (!token) {
114
119
  return null;
115
120
  }
116
- for (const ownerAttr of tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_ownerAttrs, "f")) {
121
+ for (const ownerAttr of __classPrivateFieldGet(this, _MLDomTokenList_ownerAttrs, "f")) {
117
122
  if (ownerAttr.isDynamicValue) {
118
123
  continue;
119
124
  }
120
- const startOffset = tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f").indexOf(token, _offset);
125
+ const startOffset = __classPrivateFieldGet(this, _MLDomTokenList_origin, "f").indexOf(token, _offset);
121
126
  if (startOffset === -1) {
122
127
  continue;
123
128
  }
124
- const startLine = (0, parser_utils_1.getLine)(tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
125
- const startCol = (0, parser_utils_1.getCol)(tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
129
+ const startLine = getLine(__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
130
+ const startCol = getCol(__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
126
131
  return {
127
132
  raw: token,
128
- startOffset: ((_c = (_b = ownerAttr.valueNode) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : 0) + startOffset,
129
- startLine: ((_e = (_d = ownerAttr.valueNode) === null || _d === void 0 ? void 0 : _d.startLine) !== null && _e !== void 0 ? _e : 0) + (startLine - 1),
130
- startCol: ((_g = (_f = ownerAttr.valueNode) === null || _f === void 0 ? void 0 : _f.startCol) !== null && _g !== void 0 ? _g : 0) + (startCol - 1),
133
+ startOffset: (ownerAttr.valueNode?.startOffset ?? 0) + startOffset,
134
+ startLine: (ownerAttr.valueNode?.startLine ?? 0) + (startLine - 1),
135
+ startCol: (ownerAttr.valueNode?.startCol ?? 0) + (startCol - 1),
131
136
  rule: ownerAttr.rule,
132
137
  _searchedIndex: startOffset,
133
138
  };
@@ -135,5 +140,4 @@ class MLDomTokenList extends Array {
135
140
  return null;
136
141
  }
137
142
  }
138
- exports.MLDomTokenList = MLDomTokenList;
139
143
  _MLDomTokenList_origin = new WeakMap(), _MLDomTokenList_ownerAttrs = new WeakMap(), _MLDomTokenList_set = new WeakMap();
@@ -0,0 +1,20 @@
1
+ import type { MLDocument } from './document.js';
2
+ import type { MLElement } from './element.js';
3
+ import type { MLASTElementCloseTag } from '@markuplint/ml-ast';
4
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
5
+ import { MLNode } from './node.js';
6
+ export declare class MLElementCloseTag<T extends RuleConfigValue, O extends PlainData = undefined> extends MLNode<T, O, MLASTElementCloseTag> {
7
+ readonly pair: MLElement<T, O>;
8
+ constructor(astNode: MLASTElementCloseTag, document: MLDocument<T, O>, pair: MLElement<T, O>);
9
+ /**
10
+ * Returns a string appropriate for the type of node as `MLBlock`
11
+ *
12
+ * @implements `@markuplint/ml-core` API: `MLBlock`
13
+ */
14
+ get nodeName(): string;
15
+ /**
16
+ * @implements `@markuplint/ml-core` API: `MLElement`
17
+ */
18
+ get rawName(): string;
19
+ toString(fixed?: boolean): string;
20
+ }
@@ -0,0 +1,39 @@
1
+ import { MLNode } from './node.js';
2
+ export class MLElementCloseTag extends MLNode {
3
+ constructor(astNode,
4
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
5
+ document,
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ pair) {
8
+ super(astNode, document);
9
+ this.pair = pair;
10
+ }
11
+ /**
12
+ * Returns a string appropriate for the type of node as `MLBlock`
13
+ *
14
+ * @implements `@markuplint/ml-core` API: `MLBlock`
15
+ */
16
+ get nodeName() {
17
+ return this.pair.nodeName;
18
+ }
19
+ /**
20
+ * @implements `@markuplint/ml-core` API: `MLElement`
21
+ */
22
+ get rawName() {
23
+ return this._astToken.nodeName;
24
+ }
25
+ toString(fixed = false) {
26
+ if (!fixed) {
27
+ return this.raw;
28
+ }
29
+ if (this.pair.isOmitted) {
30
+ return this.raw;
31
+ }
32
+ return [
33
+ this.pair.tagOpenChar,
34
+ this.pair.tagOpenChar === '' ? '' : '/',
35
+ this.pair.fixedNodeName === this.pair.rawName ? this.rawName : this.pair.fixedNodeName,
36
+ this.pair.tagCloseChar,
37
+ ].join('');
38
+ }
39
+ }