@markuplint/ml-core 3.0.0-dev.25 → 3.0.0-dev.290
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/configs.browser.js +1 -5
- package/lib/configs.js +33 -31
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +3 -8
- package/lib/debug.js +9 -14
- package/lib/index.d.ts +13 -12
- package/lib/index.js +13 -29
- package/lib/ml-core.d.ts +7 -7
- package/lib/ml-core.js +60 -66
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +23 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -4
- package/lib/ml-dom/helper/create-node.js +13 -15
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +8 -8
- package/lib/ml-dom/helper/getIndent.d.ts +2 -2
- package/lib/ml-dom/helper/getIndent.js +30 -28
- package/lib/ml-dom/helper/walkers.d.ts +6 -6
- package/lib/ml-dom/helper/walkers.js +23 -22
- package/lib/ml-dom/index.d.ts +9 -9
- package/lib/ml-dom/index.js +1 -5
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +9 -9
- package/lib/ml-dom/manipulations/child-node-methods.js +31 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -4
- package/lib/ml-dom/manipulations/get-children.js +5 -7
- package/lib/ml-dom/node/attr.d.ts +7 -7
- package/lib/ml-dom/node/attr.js +33 -34
- package/lib/ml-dom/node/block.d.ts +6 -6
- package/lib/ml-dom/node/block.js +21 -15
- package/lib/ml-dom/node/character-data.d.ts +4 -4
- package/lib/ml-dom/node/character-data.js +20 -19
- package/lib/ml-dom/node/child-node.d.ts +9 -9
- package/lib/ml-dom/node/child-node.js +3 -5
- package/lib/ml-dom/node/comment.d.ts +4 -4
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +4 -4
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +6 -6
- package/lib/ml-dom/node/document-type.js +21 -15
- package/lib/ml-dom/node/document.d.ts +32 -29
- package/lib/ml-dom/node/document.js +329 -246
- package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
- package/lib/ml-dom/node/dom-token-list.js +29 -33
- package/lib/ml-dom/node/element.d.ts +65 -16
- package/lib/ml-dom/node/element.js +396 -306
- package/lib/ml-dom/node/named-node-map.d.ts +4 -4
- package/lib/ml-dom/node/named-node-map.js +18 -18
- package/lib/ml-dom/node/node-list.d.ts +6 -6
- package/lib/ml-dom/node/node-list.js +25 -13
- package/lib/ml-dom/node/node-store.d.ts +5 -5
- package/lib/ml-dom/node/node-store.js +25 -10
- package/lib/ml-dom/node/node.d.ts +12 -12
- package/lib/ml-dom/node/node.js +101 -76
- package/lib/ml-dom/node/parent-node.d.ts +6 -6
- package/lib/ml-dom/node/parent-node.js +31 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +5 -5
- package/lib/ml-dom/node/rule-mapper.js +20 -17
- package/lib/ml-dom/node/text.d.ts +4 -4
- package/lib/ml-dom/node/text.js +6 -11
- package/lib/ml-dom/node/types.d.ts +30 -16
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.js +19 -23
- package/lib/ml-rule/create-rule.d.ts +3 -3
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -5
- package/lib/ml-rule/create-test-rule.js +3 -7
- package/lib/ml-rule/index.d.ts +3 -3
- package/lib/ml-rule/index.js +3 -6
- package/lib/ml-rule/ml-rule-context.d.ts +4 -4
- package/lib/ml-rule/ml-rule-context.js +11 -13
- package/lib/ml-rule/ml-rule.d.ts +9 -9
- package/lib/ml-rule/ml-rule.js +48 -45
- package/lib/ml-rule/types.d.ts +12 -12
- package/lib/ml-rule/types.js +1 -2
- package/lib/plugin/index.d.ts +2 -2
- package/lib/plugin/index.js +2 -5
- package/lib/plugin/plugin.d.ts +2 -2
- package/lib/plugin/plugin.js +1 -5
- package/lib/plugin/types.d.ts +6 -6
- package/lib/plugin/types.js +1 -2
- package/lib/ruleset/index.d.ts +3 -3
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +9 -9
- package/lib/test/index.js +14 -24
- package/lib/types.d.ts +11 -10
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +1 -1
- package/lib/utils/get-location-from-chars.js +1 -5
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -5
- package/lib/utils/string-splice.js +1 -5
- package/package.json +25 -16
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLNode_childNodes, _MLNode_ownerDocument, _MLNode_prevToken;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { MLToken } from '../token/token.js';
|
|
4
|
+
import { isChildNode } from './child-node.js';
|
|
5
|
+
import { toNodeList } from './node-list.js';
|
|
6
|
+
import { nodeStore } from './node-store.js';
|
|
7
|
+
import UnexpectedCallError from './unexpected-call-error.js';
|
|
8
|
+
export class MLNode extends MLToken {
|
|
9
|
+
constructor(astNode,
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
|
+
document) {
|
|
13
12
|
super(astNode);
|
|
14
13
|
/**
|
|
15
14
|
* @implements DOM API: `Node`
|
|
@@ -128,8 +127,8 @@ class MLNode extends token_1.MLToken {
|
|
|
128
127
|
*/
|
|
129
128
|
this.rules = {};
|
|
130
129
|
this._astToken = astNode;
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
__classPrivateFieldSet(this, _MLNode_ownerDocument, document, "f");
|
|
131
|
+
nodeStore.setNode(astNode, this);
|
|
133
132
|
}
|
|
134
133
|
/**
|
|
135
134
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -139,7 +138,7 @@ class MLNode extends token_1.MLToken {
|
|
|
139
138
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-baseuri%E2%91%A0
|
|
140
139
|
*/
|
|
141
140
|
get baseURI() {
|
|
142
|
-
throw new
|
|
141
|
+
throw new UnexpectedCallError('Not supported "baseURI" property');
|
|
143
142
|
}
|
|
144
143
|
/**
|
|
145
144
|
* The list of child nodes that contains `Element`, `Text`, and `Comment`.
|
|
@@ -149,35 +148,35 @@ class MLNode extends token_1.MLToken {
|
|
|
149
148
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-childnodes%E2%91%A0
|
|
150
149
|
*/
|
|
151
150
|
get childNodes() {
|
|
152
|
-
if (
|
|
153
|
-
return
|
|
151
|
+
if (__classPrivateFieldGet(this, _MLNode_childNodes, "f") != null) {
|
|
152
|
+
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
154
153
|
}
|
|
155
154
|
if (this.is(this.DOCUMENT_NODE)) {
|
|
156
155
|
const childNodes = [];
|
|
157
156
|
for (const node of this.nodeList) {
|
|
158
|
-
if (
|
|
157
|
+
if (isChildNode(node) && (node.parentNode === this || node.parentNode === null)) {
|
|
159
158
|
childNodes.push(node);
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
161
|
// Cache
|
|
163
|
-
|
|
164
|
-
return
|
|
162
|
+
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList(childNodes), "f");
|
|
163
|
+
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
165
164
|
}
|
|
166
165
|
if (this.is(this.DOCUMENT_FRAGMENT_NODE) ||
|
|
167
166
|
this.is(this.ELEMENT_NODE) ||
|
|
168
167
|
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
169
168
|
// @ts-ignore
|
|
170
|
-
const astChildren = this._astToken.childNodes
|
|
169
|
+
const astChildren = this._astToken.childNodes ?? [];
|
|
171
170
|
const childNodes = astChildren
|
|
172
|
-
.map(node =>
|
|
173
|
-
.filter((node) =>
|
|
171
|
+
.map(node => nodeStore.getNode(node))
|
|
172
|
+
.filter((node) => isChildNode(node));
|
|
174
173
|
// Cache
|
|
175
|
-
|
|
176
|
-
return
|
|
174
|
+
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList(childNodes), "f");
|
|
175
|
+
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
177
176
|
}
|
|
178
177
|
// Cache
|
|
179
|
-
|
|
180
|
-
return
|
|
178
|
+
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList([]), "f");
|
|
179
|
+
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
181
180
|
}
|
|
182
181
|
/**
|
|
183
182
|
* The first node that may be `Element`, `Text`, and `CommentNode`.
|
|
@@ -187,7 +186,7 @@ class MLNode extends token_1.MLToken {
|
|
|
187
186
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-firstchild%E2%91%A0
|
|
188
187
|
*/
|
|
189
188
|
get firstChild() {
|
|
190
|
-
return this.childNodes[0]
|
|
189
|
+
return this.childNodes[0] ?? null;
|
|
191
190
|
}
|
|
192
191
|
/**
|
|
193
192
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -197,7 +196,7 @@ class MLNode extends token_1.MLToken {
|
|
|
197
196
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-isconnected%E2%91%A0
|
|
198
197
|
*/
|
|
199
198
|
get isConnected() {
|
|
200
|
-
throw new
|
|
199
|
+
throw new UnexpectedCallError('Not supported "isConnected" property');
|
|
201
200
|
}
|
|
202
201
|
/**
|
|
203
202
|
* The last node that may be `Element`, `Text`, and `CommentNode`.
|
|
@@ -207,7 +206,7 @@ class MLNode extends token_1.MLToken {
|
|
|
207
206
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
|
|
208
207
|
*/
|
|
209
208
|
get lastChild() {
|
|
210
|
-
return this.childNodes[this.childNodes.length - 1]
|
|
209
|
+
return this.childNodes[this.childNodes.length - 1] ?? null;
|
|
211
210
|
}
|
|
212
211
|
/**
|
|
213
212
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -216,7 +215,7 @@ class MLNode extends token_1.MLToken {
|
|
|
216
215
|
if (!this._astToken.nextNode) {
|
|
217
216
|
return null;
|
|
218
217
|
}
|
|
219
|
-
return
|
|
218
|
+
return nodeStore.getNode(this._astToken.nextNode);
|
|
220
219
|
}
|
|
221
220
|
/**
|
|
222
221
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -226,7 +225,7 @@ class MLNode extends token_1.MLToken {
|
|
|
226
225
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-nextsibling%E2%91%A0
|
|
227
226
|
*/
|
|
228
227
|
get nextSibling() {
|
|
229
|
-
throw new
|
|
228
|
+
throw new UnexpectedCallError('Not supported "nextSibling" property');
|
|
230
229
|
}
|
|
231
230
|
/**
|
|
232
231
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -267,10 +266,10 @@ class MLNode extends token_1.MLToken {
|
|
|
267
266
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-ownerdocument%E2%91%A0
|
|
268
267
|
*/
|
|
269
268
|
get ownerDocument() {
|
|
270
|
-
return
|
|
269
|
+
return __classPrivateFieldGet(this, _MLNode_ownerDocument, "f");
|
|
271
270
|
}
|
|
272
271
|
get ownerMLDocument() {
|
|
273
|
-
return
|
|
272
|
+
return __classPrivateFieldGet(this, _MLNode_ownerDocument, "f");
|
|
274
273
|
}
|
|
275
274
|
/**
|
|
276
275
|
* The parent element.
|
|
@@ -361,14 +360,14 @@ class MLNode extends token_1.MLToken {
|
|
|
361
360
|
if (!this._astToken.prevNode) {
|
|
362
361
|
return null;
|
|
363
362
|
}
|
|
364
|
-
return
|
|
363
|
+
return nodeStore.getNode(this._astToken.prevNode);
|
|
365
364
|
}
|
|
366
365
|
/**
|
|
367
366
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
368
367
|
*/
|
|
369
368
|
get prevToken() {
|
|
370
|
-
if (
|
|
371
|
-
return
|
|
369
|
+
if (__classPrivateFieldGet(this, _MLNode_prevToken, "f") !== undefined) {
|
|
370
|
+
return __classPrivateFieldGet(this, _MLNode_prevToken, "f");
|
|
372
371
|
}
|
|
373
372
|
let index = -1;
|
|
374
373
|
for (let i = 0; i < this.ownerMLDocument.nodeList.length; i++) {
|
|
@@ -385,11 +384,11 @@ class MLNode extends token_1.MLToken {
|
|
|
385
384
|
}
|
|
386
385
|
}
|
|
387
386
|
if (index === -1) {
|
|
388
|
-
|
|
389
|
-
return
|
|
387
|
+
__classPrivateFieldSet(this, _MLNode_prevToken, null, "f");
|
|
388
|
+
return __classPrivateFieldGet(this, _MLNode_prevToken, "f");
|
|
390
389
|
}
|
|
391
|
-
|
|
392
|
-
return
|
|
390
|
+
__classPrivateFieldSet(this, _MLNode_prevToken, this.ownerMLDocument.nodeList[index - 1] ?? null, "f");
|
|
391
|
+
return __classPrivateFieldGet(this, _MLNode_prevToken, "f") ?? null;
|
|
393
392
|
}
|
|
394
393
|
/**
|
|
395
394
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -399,7 +398,7 @@ class MLNode extends token_1.MLToken {
|
|
|
399
398
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-previoussibling%E2%91%A0
|
|
400
399
|
*/
|
|
401
400
|
get previousSibling() {
|
|
402
|
-
throw new
|
|
401
|
+
throw new UnexpectedCallError('Not supported "previousSibling" property');
|
|
403
402
|
}
|
|
404
403
|
/**
|
|
405
404
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -409,8 +408,13 @@ class MLNode extends token_1.MLToken {
|
|
|
409
408
|
throw new Error('Invalid call: Some rule evaluations may not be running asynchronously.');
|
|
410
409
|
}
|
|
411
410
|
const name = this.ownerMLDocument.currentRule.name;
|
|
412
|
-
const
|
|
413
|
-
|
|
411
|
+
const settingRule = this.rules[name];
|
|
412
|
+
const rule = this.ownerMLDocument.currentRule.optimizeOption(settingRule);
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
414
|
+
if (!rule) {
|
|
415
|
+
throw new Error(`Rule data "${name}" doesn't exist in rules ([${Object.keys(this.rules).map(name => `"${name}"`)}]) of ${this.nodeName}("${this.raw}")`);
|
|
416
|
+
}
|
|
417
|
+
return rule;
|
|
414
418
|
}
|
|
415
419
|
/**
|
|
416
420
|
* Returns a syntactical parent node
|
|
@@ -454,7 +458,7 @@ class MLNode extends token_1.MLToken {
|
|
|
454
458
|
if (!this._astToken.parentNode) {
|
|
455
459
|
return this.ownerMLDocument;
|
|
456
460
|
}
|
|
457
|
-
return
|
|
461
|
+
return nodeStore.getNode(this._astToken.parentNode);
|
|
458
462
|
}
|
|
459
463
|
/**
|
|
460
464
|
* Return the text content.
|
|
@@ -475,8 +479,10 @@ class MLNode extends token_1.MLToken {
|
|
|
475
479
|
* @implements DOM API: `EventTarget`
|
|
476
480
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-addeventlistener%E2%91%A2
|
|
477
481
|
*/
|
|
478
|
-
addEventListener(type,
|
|
479
|
-
|
|
482
|
+
addEventListener(type,
|
|
483
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
484
|
+
callback, options = {}) {
|
|
485
|
+
throw new UnexpectedCallError('Not supported "addEventListener" method');
|
|
480
486
|
}
|
|
481
487
|
/**
|
|
482
488
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -486,7 +492,7 @@ class MLNode extends token_1.MLToken {
|
|
|
486
492
|
* @see https://dom.spec.whatwg.org/#dom-node-appendchild
|
|
487
493
|
*/
|
|
488
494
|
appendChild(node) {
|
|
489
|
-
throw new
|
|
495
|
+
throw new UnexpectedCallError('Not supported "appendChild" method');
|
|
490
496
|
}
|
|
491
497
|
/**
|
|
492
498
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -496,7 +502,7 @@ class MLNode extends token_1.MLToken {
|
|
|
496
502
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-clonenode%E2%91%A0
|
|
497
503
|
*/
|
|
498
504
|
cloneNode(deep) {
|
|
499
|
-
throw new
|
|
505
|
+
throw new UnexpectedCallError('Not supported "appendChild" method');
|
|
500
506
|
}
|
|
501
507
|
/**
|
|
502
508
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -505,8 +511,10 @@ class MLNode extends token_1.MLToken {
|
|
|
505
511
|
* @implements DOM API: `Node`
|
|
506
512
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-comparedocumentposition%E2%91%A0
|
|
507
513
|
*/
|
|
508
|
-
compareDocumentPosition(
|
|
509
|
-
|
|
514
|
+
compareDocumentPosition(
|
|
515
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
516
|
+
other) {
|
|
517
|
+
throw new UnexpectedCallError('Not supported "compareDocumentPosition" method');
|
|
510
518
|
}
|
|
511
519
|
/**
|
|
512
520
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -515,8 +523,10 @@ class MLNode extends token_1.MLToken {
|
|
|
515
523
|
* @implements DOM API: `Node`
|
|
516
524
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-contains%E2%91%A0
|
|
517
525
|
*/
|
|
518
|
-
contains(
|
|
519
|
-
|
|
526
|
+
contains(
|
|
527
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
528
|
+
other) {
|
|
529
|
+
throw new UnexpectedCallError('Not supported "contains" method');
|
|
520
530
|
}
|
|
521
531
|
/**
|
|
522
532
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -525,8 +535,10 @@ class MLNode extends token_1.MLToken {
|
|
|
525
535
|
* @implements DOM API: `EventTarget`
|
|
526
536
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-dispatchevent%E2%91%A2
|
|
527
537
|
*/
|
|
528
|
-
dispatchEvent(
|
|
529
|
-
|
|
538
|
+
dispatchEvent(
|
|
539
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
540
|
+
event) {
|
|
541
|
+
throw new UnexpectedCallError('Not supported "dispatchEvent" method');
|
|
530
542
|
}
|
|
531
543
|
/**
|
|
532
544
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -535,12 +547,14 @@ class MLNode extends token_1.MLToken {
|
|
|
535
547
|
* @implements DOM API: `Node`
|
|
536
548
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-getrootnode%E2%91%A0
|
|
537
549
|
*/
|
|
538
|
-
getRootNode(
|
|
550
|
+
getRootNode(
|
|
551
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
552
|
+
options) {
|
|
539
553
|
if (options) {
|
|
540
|
-
throw new
|
|
554
|
+
throw new UnexpectedCallError('Not supported options');
|
|
541
555
|
}
|
|
542
556
|
// The original DOM API returns a document fragment if the element is a fragment.
|
|
543
|
-
return
|
|
557
|
+
return __classPrivateFieldGet(this, _MLNode_ownerDocument, "f");
|
|
544
558
|
}
|
|
545
559
|
/**
|
|
546
560
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -550,7 +564,7 @@ class MLNode extends token_1.MLToken {
|
|
|
550
564
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-haschildnodes%E2%91%A0
|
|
551
565
|
*/
|
|
552
566
|
hasChildNodes() {
|
|
553
|
-
throw new
|
|
567
|
+
throw new UnexpectedCallError('Not supported "hasChildNodes" method');
|
|
554
568
|
}
|
|
555
569
|
/**
|
|
556
570
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -559,8 +573,10 @@ class MLNode extends token_1.MLToken {
|
|
|
559
573
|
* @implements DOM API: `Node`
|
|
560
574
|
* @see https://dom.spec.whatwg.org/#dom-node-insertbefore
|
|
561
575
|
*/
|
|
562
|
-
insertBefore(node,
|
|
563
|
-
|
|
576
|
+
insertBefore(node,
|
|
577
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
578
|
+
child) {
|
|
579
|
+
throw new UnexpectedCallError('Not supported "insertBefore" method');
|
|
564
580
|
}
|
|
565
581
|
/**
|
|
566
582
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -576,7 +592,7 @@ class MLNode extends token_1.MLToken {
|
|
|
576
592
|
* @see https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
|
|
577
593
|
*/
|
|
578
594
|
isDefaultNamespace(namespace) {
|
|
579
|
-
throw new
|
|
595
|
+
throw new UnexpectedCallError('Not supported "isDefaultNamespace" method');
|
|
580
596
|
}
|
|
581
597
|
/**
|
|
582
598
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -585,8 +601,10 @@ class MLNode extends token_1.MLToken {
|
|
|
585
601
|
* @implements DOM API: `Node`
|
|
586
602
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-isequalnode%E2%91%A0
|
|
587
603
|
*/
|
|
588
|
-
isEqualNode(
|
|
589
|
-
|
|
604
|
+
isEqualNode(
|
|
605
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
606
|
+
otherNode) {
|
|
607
|
+
throw new UnexpectedCallError('Not supported "isEqualNode" method');
|
|
590
608
|
}
|
|
591
609
|
/**
|
|
592
610
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -601,8 +619,10 @@ class MLNode extends token_1.MLToken {
|
|
|
601
619
|
* @implements DOM API: `Node`
|
|
602
620
|
* @see https://dom.spec.whatwg.org/#dom-node-issamenode
|
|
603
621
|
*/
|
|
604
|
-
isSameNode(
|
|
605
|
-
|
|
622
|
+
isSameNode(
|
|
623
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
624
|
+
otherNode) {
|
|
625
|
+
throw new UnexpectedCallError('Not supported "isSameNode" method');
|
|
606
626
|
}
|
|
607
627
|
/**
|
|
608
628
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -612,7 +632,7 @@ class MLNode extends token_1.MLToken {
|
|
|
612
632
|
* @see https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri
|
|
613
633
|
*/
|
|
614
634
|
lookupNamespaceURI(prefix) {
|
|
615
|
-
throw new
|
|
635
|
+
throw new UnexpectedCallError('Not supported "lookupNamespaceURI" method');
|
|
616
636
|
}
|
|
617
637
|
/**
|
|
618
638
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -622,7 +642,7 @@ class MLNode extends token_1.MLToken {
|
|
|
622
642
|
* @see https://dom.spec.whatwg.org/#dom-node-lookupprefix
|
|
623
643
|
*/
|
|
624
644
|
lookupPrefix(namespace) {
|
|
625
|
-
throw new
|
|
645
|
+
throw new UnexpectedCallError('Not supported "lookupPrefix" method');
|
|
626
646
|
}
|
|
627
647
|
/**
|
|
628
648
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -632,7 +652,7 @@ class MLNode extends token_1.MLToken {
|
|
|
632
652
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-normalize%E2%91%A0
|
|
633
653
|
*/
|
|
634
654
|
normalize() {
|
|
635
|
-
throw new
|
|
655
|
+
throw new UnexpectedCallError('Not supported "normalize" method');
|
|
636
656
|
}
|
|
637
657
|
/**
|
|
638
658
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -642,7 +662,7 @@ class MLNode extends token_1.MLToken {
|
|
|
642
662
|
* @see https://dom.spec.whatwg.org/#dom-node-removechild
|
|
643
663
|
*/
|
|
644
664
|
removeChild(child) {
|
|
645
|
-
throw new
|
|
665
|
+
throw new UnexpectedCallError('Not supported "removeChild" method');
|
|
646
666
|
}
|
|
647
667
|
/**
|
|
648
668
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -651,8 +671,10 @@ class MLNode extends token_1.MLToken {
|
|
|
651
671
|
* @implements DOM API: `EventTarget`
|
|
652
672
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-removeeventlistener%E2%91%A1
|
|
653
673
|
*/
|
|
654
|
-
removeEventListener(type,
|
|
655
|
-
|
|
674
|
+
removeEventListener(type,
|
|
675
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
676
|
+
callback, options = {}) {
|
|
677
|
+
throw new UnexpectedCallError('Not supported "removeEventListener" method');
|
|
656
678
|
}
|
|
657
679
|
/**
|
|
658
680
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -661,15 +683,18 @@ class MLNode extends token_1.MLToken {
|
|
|
661
683
|
* @implements DOM API: `Node`
|
|
662
684
|
* @see https://dom.spec.whatwg.org/#dom-node-replacechild
|
|
663
685
|
*/
|
|
664
|
-
replaceChild(
|
|
665
|
-
|
|
686
|
+
replaceChild(
|
|
687
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
688
|
+
node, child) {
|
|
689
|
+
throw new UnexpectedCallError('Not supported "removeChild" method');
|
|
666
690
|
}
|
|
667
691
|
/**
|
|
668
692
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
669
693
|
*/
|
|
670
|
-
resetChildren(
|
|
671
|
-
|
|
694
|
+
resetChildren(
|
|
695
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
696
|
+
childNodes) {
|
|
697
|
+
__classPrivateFieldSet(this, _MLNode_childNodes, childNodes ?? __classPrivateFieldGet(this, _MLNode_childNodes, "f"), "f");
|
|
672
698
|
}
|
|
673
699
|
}
|
|
674
|
-
exports.MLNode = MLNode;
|
|
675
700
|
_MLNode_childNodes = new WeakMap(), _MLNode_ownerDocument = new WeakMap(), _MLNode_prevToken = new WeakMap();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { MLElement } from './element';
|
|
1
|
+
import type { MLElement } from './element.js';
|
|
2
2
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
3
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
-
import { MLNode } from './node';
|
|
3
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
+
import { MLNode } from './node.js';
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
7
|
* @see https://dom.spec.whatwg.org/#interface-parentnode
|
|
8
8
|
*/
|
|
9
|
-
export declare abstract class MLParentNode<T extends RuleConfigValue, O =
|
|
9
|
+
export declare abstract class MLParentNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLNode<T, O, A> implements ParentNode {
|
|
10
10
|
#private;
|
|
11
11
|
/**
|
|
12
12
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
@@ -22,12 +22,12 @@ export declare abstract class MLParentNode<T extends RuleConfigValue, O = null,
|
|
|
22
22
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
23
23
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
|
|
24
24
|
*/
|
|
25
|
-
get firstElementChild(): MLElement<T, O
|
|
25
|
+
get firstElementChild(): MLElement<T, O> | null;
|
|
26
26
|
/**
|
|
27
27
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
28
28
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
|
|
29
29
|
*/
|
|
30
|
-
get lastElementChild(): MLElement<T, O
|
|
30
|
+
get lastElementChild(): MLElement<T, O> | null;
|
|
31
31
|
/**
|
|
32
32
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
33
33
|
*
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLParentNode_children, _MLParentNode_selectedElements;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const node_list_1 = require("./node-list");
|
|
10
|
-
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { syncWalk } from '../helper/walkers.js';
|
|
4
|
+
import { getChildren } from '../manipulations/get-children.js';
|
|
5
|
+
import { toNodeList } from './node-list.js';
|
|
6
|
+
import { MLNode } from './node.js';
|
|
7
|
+
import UnexpectedCallError from './unexpected-call-error.js';
|
|
11
8
|
/**
|
|
12
9
|
*
|
|
13
10
|
* @see https://dom.spec.whatwg.org/#interface-parentnode
|
|
14
11
|
*/
|
|
15
|
-
class MLParentNode extends
|
|
12
|
+
export class MLParentNode extends MLNode {
|
|
16
13
|
constructor() {
|
|
17
14
|
super(...arguments);
|
|
18
15
|
/**
|
|
@@ -36,26 +33,26 @@ class MLParentNode extends node_1.MLNode {
|
|
|
36
33
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-children%E2%91%A0
|
|
37
34
|
*/
|
|
38
35
|
get children() {
|
|
39
|
-
if (
|
|
40
|
-
return
|
|
36
|
+
if (__classPrivateFieldGet(this, _MLParentNode_children, "f")) {
|
|
37
|
+
return __classPrivateFieldGet(this, _MLParentNode_children, "f");
|
|
41
38
|
}
|
|
42
|
-
const children =
|
|
43
|
-
|
|
44
|
-
return
|
|
39
|
+
const children = getChildren(this);
|
|
40
|
+
__classPrivateFieldSet(this, _MLParentNode_children, children, "f");
|
|
41
|
+
return __classPrivateFieldGet(this, _MLParentNode_children, "f");
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
44
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
48
45
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
|
|
49
46
|
*/
|
|
50
47
|
get firstElementChild() {
|
|
51
|
-
return this.children[0]
|
|
48
|
+
return this.children[0] ?? null;
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
51
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
55
52
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
|
|
56
53
|
*/
|
|
57
54
|
get lastElementChild() {
|
|
58
|
-
return this.children[0]
|
|
55
|
+
return this.children[0] ?? null;
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
61
58
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -64,8 +61,10 @@ class MLParentNode extends node_1.MLNode {
|
|
|
64
61
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
65
62
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-append%E2%91%A0
|
|
66
63
|
*/
|
|
67
|
-
append(
|
|
68
|
-
|
|
64
|
+
append(
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
66
|
+
...nodes) {
|
|
67
|
+
throw new UnexpectedCallError('Not supported "append" method');
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -74,8 +73,10 @@ class MLParentNode extends node_1.MLNode {
|
|
|
74
73
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
75
74
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-prepend%E2%91%A0
|
|
76
75
|
*/
|
|
77
|
-
prepend(
|
|
78
|
-
|
|
76
|
+
prepend(
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
78
|
+
...nodes) {
|
|
79
|
+
throw new UnexpectedCallError('Not supported "prepend" method');
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
@@ -83,23 +84,23 @@ class MLParentNode extends node_1.MLNode {
|
|
|
83
84
|
*/
|
|
84
85
|
querySelector(selectors) {
|
|
85
86
|
const selected = this.querySelectorAll(selectors);
|
|
86
|
-
return selected[0]
|
|
87
|
+
return selected[0] ?? null;
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
90
91
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselectorall%E2%91%A0
|
|
91
92
|
*/
|
|
92
93
|
querySelectorAll(selectors) {
|
|
93
|
-
const selected =
|
|
94
|
+
const selected = __classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").get(selectors);
|
|
94
95
|
if (selected) {
|
|
95
96
|
return selected;
|
|
96
97
|
}
|
|
97
|
-
const elements =
|
|
98
|
+
const elements = toNodeList(this._descendantsToArray(node => {
|
|
98
99
|
if (node.is(node.ELEMENT_NODE) && node.matches(selectors)) {
|
|
99
100
|
return node;
|
|
100
101
|
}
|
|
101
102
|
}));
|
|
102
|
-
|
|
103
|
+
__classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").set(selectors, elements);
|
|
103
104
|
return elements;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
@@ -109,12 +110,14 @@ class MLParentNode extends node_1.MLNode {
|
|
|
109
110
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
110
111
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-replacechildren%E2%91%A0
|
|
111
112
|
*/
|
|
112
|
-
replaceChildren(
|
|
113
|
-
|
|
113
|
+
replaceChildren(
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
115
|
+
...nodes) {
|
|
116
|
+
throw new UnexpectedCallError('Not supported "replaceChildren" method');
|
|
114
117
|
}
|
|
115
118
|
_descendantsToArray(filter) {
|
|
116
119
|
const nodeList = [];
|
|
117
|
-
|
|
120
|
+
syncWalk(Array.from(this.childNodes), node => {
|
|
118
121
|
if (filter) {
|
|
119
122
|
const filtered = filter(node);
|
|
120
123
|
if (filtered) {
|
|
@@ -127,5 +130,4 @@ class MLParentNode extends node_1.MLNode {
|
|
|
127
130
|
return Object.freeze(nodeList);
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
|
-
exports.MLParentNode = MLParentNode;
|
|
131
133
|
_MLParentNode_children = new WeakMap(), _MLParentNode_selectedElements = new WeakMap();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { MLDocument } from './document';
|
|
2
|
-
import type { MLNode } from './node';
|
|
1
|
+
import type { MLDocument } from './document.js';
|
|
2
|
+
import type { MLNode } from './node.js';
|
|
3
3
|
import type { AnyRule } from '@markuplint/ml-config';
|
|
4
4
|
import type { Specificity } from '@markuplint/selector';
|
|
5
5
|
type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
|
|
6
6
|
type MappingLayer = {
|
|
7
|
-
from: RuleType;
|
|
8
|
-
specificity: Specificity;
|
|
9
|
-
rule: AnyRule;
|
|
7
|
+
readonly from: RuleType;
|
|
8
|
+
readonly specificity: Specificity;
|
|
9
|
+
readonly rule: AnyRule;
|
|
10
10
|
};
|
|
11
11
|
export declare class RuleMapper {
|
|
12
12
|
#private;
|