@markuplint/ml-core 4.0.0-alpha.1 → 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.
- package/LICENSE +1 -1
- package/lib/configs.browser.js +10 -6
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -3
- package/lib/ml-core.d.ts +2 -2
- package/lib/ml-core.js +44 -20
- package/lib/ml-dom/helper/accname.js +3 -3
- package/lib/ml-dom/helper/create-node.d.ts +2 -2
- package/lib/ml-dom/helper/create-node.js +32 -7
- package/lib/ml-dom/helper/debug.js +11 -15
- package/lib/ml-dom/helper/{getIndent.js → get-indent.js} +14 -4
- package/lib/ml-dom/helper/walkers.js +1 -1
- package/lib/ml-dom/manipulations/child-node-methods.js +1 -1
- package/lib/ml-dom/manipulations/get-children.js +1 -1
- package/lib/ml-dom/node/attr.d.ts +18 -0
- package/lib/ml-dom/node/attr.js +80 -32
- package/lib/ml-dom/node/block.js +1 -3
- package/lib/ml-dom/node/character-data.d.ts +2 -2
- package/lib/ml-dom/node/character-data.js +1 -1
- package/lib/ml-dom/node/child-node.d.ts +2 -2
- package/lib/ml-dom/node/document-fragment.d.ts +2 -2
- package/lib/ml-dom/node/document-fragment.js +1 -1
- package/lib/ml-dom/node/document-type.js +1 -3
- package/lib/ml-dom/node/document.d.ts +7 -5
- package/lib/ml-dom/node/document.js +105 -39
- package/lib/ml-dom/node/dom-token-list.js +15 -5
- package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
- package/lib/ml-dom/node/element-close-tag.js +39 -0
- package/lib/ml-dom/node/element.d.ts +51 -6
- package/lib/ml-dom/node/element.js +139 -62
- package/lib/ml-dom/node/named-node-map.js +1 -1
- package/lib/ml-dom/node/node-list.js +2 -2
- package/lib/ml-dom/node/node-store.d.ts +3 -3
- package/lib/ml-dom/node/node-store.js +7 -3
- package/lib/ml-dom/node/node.d.ts +2 -2
- package/lib/ml-dom/node/node.js +31 -13
- package/lib/ml-dom/node/parent-node.d.ts +2 -2
- package/lib/ml-dom/node/parent-node.js +13 -3
- package/lib/ml-dom/node/rule-mapper.js +17 -7
- package/lib/ml-dom/node/text.js +3 -3
- package/lib/ml-dom/node/types.d.ts +23 -3
- package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -1
- package/lib/ml-dom/node/unexpected-call-error.js +1 -1
- package/lib/ml-dom/token/token.d.ts +3 -3
- package/lib/ml-dom/token/token.js +16 -6
- package/lib/ml-rule/ml-rule-context.js +6 -2
- package/lib/ml-rule/ml-rule.d.ts +1 -1
- package/lib/ml-rule/ml-rule.js +12 -2
- package/lib/ml-rule/types.d.ts +3 -0
- package/lib/ruleset/index.d.ts +1 -1
- package/lib/ruleset/index.js +1 -1
- package/lib/test/index.d.ts +6 -4
- package/lib/test/index.js +7 -3
- package/lib/types.d.ts +3 -3
- package/lib/utils/get-location-from-chars.js +3 -3
- package/package.json +13 -14
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -37
- /package/lib/ml-dom/helper/{getIndent.d.ts → get-indent.d.ts} +0 -0
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
/* global StylePropertyMap, StylePropertyMapReadOnly */
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MLElement_attributes, _MLElement_fixedNodeName, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, _MLElement_localName, _MLElement_normalizedAttrs, _MLElement_normalizedString;
|
|
4
14
|
import { resolveNamespace } from '@markuplint/ml-spec';
|
|
5
15
|
import { createSelector } from '@markuplint/selector';
|
|
6
|
-
import { stringSplice } from '../../utils/string-splice.js';
|
|
7
16
|
import { getAccname } from '../helper/accname.js';
|
|
8
17
|
import { after, before, nextElementSibling, previousElementSibling, remove, replaceWith, } from '../manipulations/child-node-methods.js';
|
|
9
18
|
import { MLToken } from '../token/token.js';
|
|
10
19
|
import { MLAttr } from './attr.js';
|
|
11
20
|
import { MLDomTokenList } from './dom-token-list.js';
|
|
21
|
+
import { MLElementCloseTag } from './element-close-tag.js';
|
|
12
22
|
import { toNamedNodeMap } from './named-node-map.js';
|
|
13
23
|
import { toHTMLCollection } from './node-list.js';
|
|
14
24
|
import { MLParentNode } from './parent-node.js';
|
|
15
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
25
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
16
26
|
const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
17
27
|
export class MLElement extends MLParentNode {
|
|
18
|
-
constructor(
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
20
|
-
astNode,
|
|
28
|
+
constructor(astNode,
|
|
21
29
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
22
30
|
document) {
|
|
23
31
|
super(astNode, document);
|
|
@@ -28,12 +36,9 @@ export class MLElement extends MLParentNode {
|
|
|
28
36
|
_MLElement_normalizedAttrs.set(this, new Map());
|
|
29
37
|
_MLElement_normalizedString.set(this, null);
|
|
30
38
|
this.pretenderContext = null;
|
|
31
|
-
_MLElement_tagOpenChar.set(this, void 0);
|
|
32
39
|
__classPrivateFieldSet(this, _MLElement_attributes, astNode.attributes.map(attr => new MLAttr(attr, this)), "f");
|
|
33
|
-
this.hasSpreadAttr = astNode.hasSpreadAttr;
|
|
34
40
|
this.selfClosingSolidus = astNode.selfClosingSolidus ? new MLToken(astNode.selfClosingSolidus) : null;
|
|
35
|
-
this.
|
|
36
|
-
this.closeTag = astNode.pearNode ? new MLToken(astNode.pearNode) : null;
|
|
41
|
+
this.closeTag = astNode.pairNode ? new MLElementCloseTag(astNode.pairNode, document, this) : null;
|
|
37
42
|
const ns = resolveNamespace(astNode.nodeName, astNode.namespace);
|
|
38
43
|
this.namespaceURI = ns.namespaceURI;
|
|
39
44
|
this.elementType = astNode.elementType;
|
|
@@ -41,7 +46,8 @@ export class MLElement extends MLParentNode {
|
|
|
41
46
|
this.isForeignElement = this.namespaceURI !== HTML_NAMESPACE;
|
|
42
47
|
__classPrivateFieldSet(this, _MLElement_fixedNodeName, astNode.nodeName, "f");
|
|
43
48
|
this.isOmitted = astNode.isGhost;
|
|
44
|
-
|
|
49
|
+
this.tagOpenChar = astNode.tagOpenChar;
|
|
50
|
+
this.tagCloseChar = astNode.tagCloseChar;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -624,6 +630,9 @@ export class MLElement extends MLParentNode {
|
|
|
624
630
|
get fixedNodeName() {
|
|
625
631
|
return __classPrivateFieldGet(this, _MLElement_fixedNodeName, "f");
|
|
626
632
|
}
|
|
633
|
+
get hasSpreadAttr() {
|
|
634
|
+
return __classPrivateFieldGet(this, _MLElement_attributes, "f").some(attr => attr.localName === '#spread');
|
|
635
|
+
}
|
|
627
636
|
/**
|
|
628
637
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
629
638
|
*
|
|
@@ -1506,6 +1515,9 @@ export class MLElement extends MLParentNode {
|
|
|
1506
1515
|
get onscroll() {
|
|
1507
1516
|
throw new UnexpectedCallError('Not supported "onscroll" property');
|
|
1508
1517
|
}
|
|
1518
|
+
get onscrollend() {
|
|
1519
|
+
throw new UnexpectedCallError('Not supported "onscrollend" property');
|
|
1520
|
+
}
|
|
1509
1521
|
/**
|
|
1510
1522
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1511
1523
|
*
|
|
@@ -1766,6 +1778,16 @@ export class MLElement extends MLParentNode {
|
|
|
1766
1778
|
get part() {
|
|
1767
1779
|
throw new UnexpectedCallError('Not supported "part" property');
|
|
1768
1780
|
}
|
|
1781
|
+
/**
|
|
1782
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1783
|
+
*
|
|
1784
|
+
* @unsupported
|
|
1785
|
+
* @implements DOM API: `Element`
|
|
1786
|
+
* @see https://html.spec.whatwg.org/multipage/popover.html#dom-popover
|
|
1787
|
+
*/
|
|
1788
|
+
get popover() {
|
|
1789
|
+
throw new UnexpectedCallError('Not supported "popover" property');
|
|
1790
|
+
}
|
|
1769
1791
|
/**
|
|
1770
1792
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1771
1793
|
*
|
|
@@ -1786,26 +1808,6 @@ export class MLElement extends MLParentNode {
|
|
|
1786
1808
|
get previousElementSibling() {
|
|
1787
1809
|
return previousElementSibling(this);
|
|
1788
1810
|
}
|
|
1789
|
-
get raw() {
|
|
1790
|
-
if (this.pretenderContext?.type === 'pretender') {
|
|
1791
|
-
return this.originRaw;
|
|
1792
|
-
}
|
|
1793
|
-
let fixed = this.originRaw;
|
|
1794
|
-
let gap = 0;
|
|
1795
|
-
if (this.nodeName !== this.fixedNodeName) {
|
|
1796
|
-
fixed = stringSplice(fixed, __classPrivateFieldGet(this, _MLElement_tagOpenChar, "f").length, this.nodeName.length, this.fixedNodeName);
|
|
1797
|
-
gap = gap + this.fixedNodeName.length - this.nodeName.length;
|
|
1798
|
-
}
|
|
1799
|
-
for (const attr of Array.from(this.attributes)) {
|
|
1800
|
-
const startOffset = (attr.spacesBeforeName?.startOffset ?? attr.startOffset) - this.startOffset;
|
|
1801
|
-
const fixedAttr = attr.toString();
|
|
1802
|
-
if (attr.originRaw !== fixedAttr) {
|
|
1803
|
-
fixed = stringSplice(fixed, startOffset + gap, attr.originRaw.length, fixedAttr);
|
|
1804
|
-
gap = gap + fixedAttr.length - attr.originRaw.length;
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
return fixed;
|
|
1808
|
-
}
|
|
1809
1811
|
/**
|
|
1810
1812
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
1811
1813
|
*/
|
|
@@ -1941,9 +1943,7 @@ export class MLElement extends MLParentNode {
|
|
|
1941
1943
|
return this.nodeName;
|
|
1942
1944
|
}
|
|
1943
1945
|
get textContent() {
|
|
1944
|
-
return
|
|
1945
|
-
.map(child => child.textContent ?? '')
|
|
1946
|
-
.join('');
|
|
1946
|
+
return [...this.childNodes].map(child => child.textContent ?? '').join('');
|
|
1947
1947
|
}
|
|
1948
1948
|
/**
|
|
1949
1949
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -1987,6 +1987,15 @@ export class MLElement extends MLParentNode {
|
|
|
1987
1987
|
options) {
|
|
1988
1988
|
throw new UnexpectedCallError('Not supported "animate" method');
|
|
1989
1989
|
}
|
|
1990
|
+
/**
|
|
1991
|
+
* @see https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignednodes
|
|
1992
|
+
*/
|
|
1993
|
+
assignedNodes() {
|
|
1994
|
+
if (this.localName !== 'slot') {
|
|
1995
|
+
throw new TypeError('assignedNodes is not a function');
|
|
1996
|
+
}
|
|
1997
|
+
return [];
|
|
1998
|
+
}
|
|
1990
1999
|
/**
|
|
1991
2000
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1992
2001
|
*
|
|
@@ -2054,6 +2063,7 @@ export class MLElement extends MLParentNode {
|
|
|
2054
2063
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-closest%E2%91%A0
|
|
2055
2064
|
*/
|
|
2056
2065
|
closest(selectors) {
|
|
2066
|
+
// eslint-disable-next-line unicorn/no-this-assignment
|
|
2057
2067
|
let el = this;
|
|
2058
2068
|
do {
|
|
2059
2069
|
if (el.matches(selectors)) {
|
|
@@ -2110,7 +2120,7 @@ export class MLElement extends MLParentNode {
|
|
|
2110
2120
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-getattribute%E2%91%A0
|
|
2111
2121
|
*/
|
|
2112
2122
|
getAttribute(attrName) {
|
|
2113
|
-
for (const attr of
|
|
2123
|
+
for (const attr of this.attributes) {
|
|
2114
2124
|
if (attr.name.toLowerCase() === attrName.toLowerCase()) {
|
|
2115
2125
|
return attr.value;
|
|
2116
2126
|
}
|
|
@@ -2132,7 +2142,7 @@ export class MLElement extends MLParentNode {
|
|
|
2132
2142
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-getattributenames%E2%91%A0
|
|
2133
2143
|
*/
|
|
2134
2144
|
getAttributeNames() {
|
|
2135
|
-
return
|
|
2145
|
+
return [...this.attributes].map(attr => attr.name);
|
|
2136
2146
|
}
|
|
2137
2147
|
/**
|
|
2138
2148
|
* @implements DOM API: `Element`
|
|
@@ -2155,7 +2165,7 @@ export class MLElement extends MLParentNode {
|
|
|
2155
2165
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2156
2166
|
*/
|
|
2157
2167
|
getAttributePretended(attrName) {
|
|
2158
|
-
for (const attr of
|
|
2168
|
+
for (const attr of __classPrivateFieldGet(this, _MLElement_attributes, "f")) {
|
|
2159
2169
|
if (attr.name.toLowerCase() === attrName.toLowerCase()) {
|
|
2160
2170
|
return attr.value;
|
|
2161
2171
|
}
|
|
@@ -2196,7 +2206,7 @@ export class MLElement extends MLParentNode {
|
|
|
2196
2206
|
return __classPrivateFieldGet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, "f");
|
|
2197
2207
|
}
|
|
2198
2208
|
const filteredNodes = [];
|
|
2199
|
-
this.childNodes
|
|
2209
|
+
for (const node of this.childNodes) {
|
|
2200
2210
|
if (node.is(node.ELEMENT_NODE)) {
|
|
2201
2211
|
if (node.isOmitted) {
|
|
2202
2212
|
const children = node.getChildElementsAndTextNodeWithoutWhitespaces();
|
|
@@ -2209,7 +2219,7 @@ export class MLElement extends MLParentNode {
|
|
|
2209
2219
|
if (node.is(node.TEXT_NODE) && !node.isWhitespace()) {
|
|
2210
2220
|
filteredNodes.push(node);
|
|
2211
2221
|
}
|
|
2212
|
-
}
|
|
2222
|
+
}
|
|
2213
2223
|
__classPrivateFieldSet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, filteredNodes, "f");
|
|
2214
2224
|
return filteredNodes;
|
|
2215
2225
|
}
|
|
@@ -2262,7 +2272,7 @@ export class MLElement extends MLParentNode {
|
|
|
2262
2272
|
return {
|
|
2263
2273
|
offset: this.startOffset,
|
|
2264
2274
|
line: this.startLine,
|
|
2265
|
-
col: this.startCol +
|
|
2275
|
+
col: this.startCol + this.tagOpenChar.length,
|
|
2266
2276
|
};
|
|
2267
2277
|
}
|
|
2268
2278
|
/**
|
|
@@ -2293,7 +2303,7 @@ export class MLElement extends MLParentNode {
|
|
|
2293
2303
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2294
2304
|
*/
|
|
2295
2305
|
hasMutableAttributes() {
|
|
2296
|
-
for (const attr of
|
|
2306
|
+
for (const attr of this.attributes) {
|
|
2297
2307
|
if (!attr.nameNode) {
|
|
2298
2308
|
return true;
|
|
2299
2309
|
}
|
|
@@ -2309,7 +2319,7 @@ export class MLElement extends MLParentNode {
|
|
|
2309
2319
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2310
2320
|
*/
|
|
2311
2321
|
hasMutableChildren(attr = false) {
|
|
2312
|
-
for (const child of
|
|
2322
|
+
for (const child of this.childNodes) {
|
|
2313
2323
|
if (child.is(child.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
2314
2324
|
return true;
|
|
2315
2325
|
}
|
|
@@ -2337,6 +2347,16 @@ export class MLElement extends MLParentNode {
|
|
|
2337
2347
|
hasPointerCapture(pointerId) {
|
|
2338
2348
|
throw new UnexpectedCallError('Not supported "hasPointerCapture" method');
|
|
2339
2349
|
}
|
|
2350
|
+
/**
|
|
2351
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2352
|
+
*
|
|
2353
|
+
* @unsupported
|
|
2354
|
+
* @implements DOM API: `Element`
|
|
2355
|
+
* @see https://html.spec.whatwg.org/multipage/popover.html#dom-hidepopover
|
|
2356
|
+
*/
|
|
2357
|
+
hidePopover() {
|
|
2358
|
+
throw new UnexpectedCallError('Not supported "hidePopover" method');
|
|
2359
|
+
}
|
|
2340
2360
|
/**
|
|
2341
2361
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2342
2362
|
*
|
|
@@ -2392,7 +2412,7 @@ export class MLElement extends MLParentNode {
|
|
|
2392
2412
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2393
2413
|
*/
|
|
2394
2414
|
isEmpty() {
|
|
2395
|
-
for (const childNode of
|
|
2415
|
+
for (const childNode of this.childNodes) {
|
|
2396
2416
|
if (!(childNode.is(childNode.TEXT_NODE) && childNode.textContent?.trim() === '')) {
|
|
2397
2417
|
return false;
|
|
2398
2418
|
}
|
|
@@ -2413,33 +2433,41 @@ export class MLElement extends MLParentNode {
|
|
|
2413
2433
|
*/
|
|
2414
2434
|
pretending(pretenders) {
|
|
2415
2435
|
const pretenderConfig = pretenders?.find(option => this.matches(option.selector));
|
|
2416
|
-
|
|
2436
|
+
const asAttrValue = this.getAttribute('as');
|
|
2437
|
+
const pretenderElement = pretenderConfig?.as ??
|
|
2438
|
+
(this.elementType === 'html' || !asAttrValue
|
|
2439
|
+
? null
|
|
2440
|
+
: {
|
|
2441
|
+
element: asAttrValue,
|
|
2442
|
+
inheritAttrs: true,
|
|
2443
|
+
});
|
|
2444
|
+
if (pretenderElement == null) {
|
|
2417
2445
|
return;
|
|
2418
2446
|
}
|
|
2419
2447
|
let nodeName;
|
|
2420
2448
|
let namespace = 'html';
|
|
2421
2449
|
const attributes = [];
|
|
2422
2450
|
let aria;
|
|
2423
|
-
if (typeof
|
|
2424
|
-
nodeName =
|
|
2451
|
+
if (typeof pretenderElement === 'string') {
|
|
2452
|
+
nodeName = pretenderElement;
|
|
2425
2453
|
}
|
|
2426
2454
|
else {
|
|
2427
|
-
nodeName =
|
|
2428
|
-
namespace =
|
|
2429
|
-
if (
|
|
2455
|
+
nodeName = pretenderElement.element;
|
|
2456
|
+
namespace = pretenderElement.namespace ?? namespace;
|
|
2457
|
+
if (pretenderElement.inheritAttrs) {
|
|
2430
2458
|
attributes.push(...this._astToken.attributes);
|
|
2431
2459
|
}
|
|
2432
|
-
if (
|
|
2433
|
-
attributes.push(...
|
|
2434
|
-
const _value = value
|
|
2435
|
-
?
|
|
2460
|
+
if (pretenderElement.attrs) {
|
|
2461
|
+
attributes.push(...pretenderElement.attrs.map(({ name, value }, i) => {
|
|
2462
|
+
const _value = value == null
|
|
2463
|
+
? ''
|
|
2464
|
+
: typeof value === 'string'
|
|
2436
2465
|
? value
|
|
2437
|
-
: this.getAttribute(value.fromAttr) ?? ''
|
|
2438
|
-
: '';
|
|
2466
|
+
: this.getAttribute(value.fromAttr) ?? '';
|
|
2439
2467
|
return {
|
|
2440
2468
|
...this._astToken,
|
|
2441
2469
|
uuid: `${this.uuid}_attr_${i}`,
|
|
2442
|
-
type: '
|
|
2470
|
+
type: 'attr',
|
|
2443
2471
|
nodeName: name,
|
|
2444
2472
|
spacesBeforeName: {
|
|
2445
2473
|
...this._astToken,
|
|
@@ -2482,7 +2510,7 @@ export class MLElement extends MLParentNode {
|
|
|
2482
2510
|
};
|
|
2483
2511
|
}));
|
|
2484
2512
|
}
|
|
2485
|
-
aria =
|
|
2513
|
+
aria = pretenderElement.aria;
|
|
2486
2514
|
}
|
|
2487
2515
|
const as = new MLElement({
|
|
2488
2516
|
...this._astToken,
|
|
@@ -2678,6 +2706,16 @@ export class MLElement extends MLParentNode {
|
|
|
2678
2706
|
setPointerCapture(pointerId) {
|
|
2679
2707
|
throw new UnexpectedCallError('Not supported "setPointerCapture" method');
|
|
2680
2708
|
}
|
|
2709
|
+
/**
|
|
2710
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2711
|
+
*
|
|
2712
|
+
* @unsupported
|
|
2713
|
+
* @implements DOM API: `Element`
|
|
2714
|
+
* @see https://html.spec.whatwg.org/multipage/popover.html#dom-showpopover
|
|
2715
|
+
*/
|
|
2716
|
+
showPopover() {
|
|
2717
|
+
throw new UnexpectedCallError('Not supported "showPopover" method');
|
|
2718
|
+
}
|
|
2681
2719
|
/**
|
|
2682
2720
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2683
2721
|
*/
|
|
@@ -2693,7 +2731,7 @@ export class MLElement extends MLParentNode {
|
|
|
2693
2731
|
if (node.is(node.ELEMENT_NODE)) {
|
|
2694
2732
|
return node.toNormalizeString();
|
|
2695
2733
|
}
|
|
2696
|
-
return node.
|
|
2734
|
+
return node.raw;
|
|
2697
2735
|
});
|
|
2698
2736
|
const endTag = `</${this.nodeName}>`;
|
|
2699
2737
|
const normalizedString = `${startTag}${childNodes.join('')}${endTag}`;
|
|
@@ -2703,8 +2741,37 @@ export class MLElement extends MLParentNode {
|
|
|
2703
2741
|
/**
|
|
2704
2742
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2705
2743
|
*/
|
|
2706
|
-
toString() {
|
|
2707
|
-
|
|
2744
|
+
toString(fixed = false) {
|
|
2745
|
+
if (!fixed) {
|
|
2746
|
+
return this.raw;
|
|
2747
|
+
}
|
|
2748
|
+
if (this.pretenderContext?.type === 'pretender') {
|
|
2749
|
+
return this.raw;
|
|
2750
|
+
}
|
|
2751
|
+
if (this.nodeName.startsWith('#')) {
|
|
2752
|
+
return this.raw;
|
|
2753
|
+
}
|
|
2754
|
+
if (this.isOmitted) {
|
|
2755
|
+
return this.raw;
|
|
2756
|
+
}
|
|
2757
|
+
let raw = this.raw;
|
|
2758
|
+
let offset = 0;
|
|
2759
|
+
const nodes = [
|
|
2760
|
+
{
|
|
2761
|
+
toString: () => this.tagOpenChar + this.fixedNodeName,
|
|
2762
|
+
startOffset: this.startOffset,
|
|
2763
|
+
endOffset: this.startOffset + this.tagOpenChar.length + this.nodeName.length,
|
|
2764
|
+
},
|
|
2765
|
+
...this.attributes,
|
|
2766
|
+
];
|
|
2767
|
+
for (const node of nodes) {
|
|
2768
|
+
const before = raw.slice(0, node.startOffset + offset - this.startOffset);
|
|
2769
|
+
const rawCode = node.toString(true);
|
|
2770
|
+
const after = raw.slice(node.endOffset + offset - this.startOffset);
|
|
2771
|
+
raw = before + rawCode + after;
|
|
2772
|
+
offset += rawCode.length - (node.endOffset - node.startOffset);
|
|
2773
|
+
}
|
|
2774
|
+
return raw;
|
|
2708
2775
|
}
|
|
2709
2776
|
/**
|
|
2710
2777
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -2716,6 +2783,16 @@ export class MLElement extends MLParentNode {
|
|
|
2716
2783
|
toggleAttribute(qualifiedName, force) {
|
|
2717
2784
|
throw new UnexpectedCallError('Not supported "toggleAttribute" method');
|
|
2718
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2788
|
+
*
|
|
2789
|
+
* @unsupported
|
|
2790
|
+
* @implements DOM API: `Element`
|
|
2791
|
+
* @see https://html.spec.whatwg.org/multipage/popover.html#dom-togglepopover
|
|
2792
|
+
*/
|
|
2793
|
+
togglePopover(force) {
|
|
2794
|
+
throw new UnexpectedCallError('Not supported "togglePopover" method');
|
|
2795
|
+
}
|
|
2719
2796
|
/**
|
|
2720
2797
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2721
2798
|
*
|
|
@@ -2727,4 +2804,4 @@ export class MLElement extends MLParentNode {
|
|
|
2727
2804
|
throw new UnexpectedCallError('Not supported "webkitMatchesSelector" method');
|
|
2728
2805
|
}
|
|
2729
2806
|
}
|
|
2730
|
-
_MLElement_attributes = new WeakMap(), _MLElement_fixedNodeName = new WeakMap(), _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache = new WeakMap(), _MLElement_localName = new WeakMap(), _MLElement_normalizedAttrs = new WeakMap(), _MLElement_normalizedString = new WeakMap()
|
|
2807
|
+
_MLElement_attributes = new WeakMap(), _MLElement_fixedNodeName = new WeakMap(), _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache = new WeakMap(), _MLElement_localName = new WeakMap(), _MLElement_normalizedAttrs = new WeakMap(), _MLElement_normalizedString = new WeakMap();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
1
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
2
2
|
export class MLNamedNodeMap extends Array {
|
|
3
3
|
getNamedItem(qualifiedName) {
|
|
4
4
|
return this.find(attr => attr.name === qualifiedName) ?? null;
|
|
@@ -42,10 +42,10 @@ export function nodeListToHTMLCollection(
|
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
43
|
nodeList) {
|
|
44
44
|
const collection = new MLHTMLCollection();
|
|
45
|
-
|
|
45
|
+
for (const node of nodeList) {
|
|
46
46
|
if (node.is(node.ELEMENT_NODE)) {
|
|
47
47
|
collection.push(node);
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
50
50
|
return collection;
|
|
51
51
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { MLNode } from './node.js';
|
|
2
2
|
import type { MappedNode } from './types.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
4
4
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
declare class NodeStore {
|
|
6
6
|
#private;
|
|
7
|
-
getNode<N extends
|
|
8
|
-
setNode<A extends
|
|
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;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* `NodeStore` Singleton
|
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
};
|
|
1
6
|
var _NodeStore_store;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
7
|
import { TargetParserError } from '@markuplint/parser-utils';
|
|
4
8
|
import { log } from '../../debug.js';
|
|
5
9
|
const nodeStoreLog = log.extend('node-store');
|
|
@@ -13,7 +17,7 @@ class NodeStore {
|
|
|
13
17
|
const node = __classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
|
|
14
18
|
if (!node) {
|
|
15
19
|
nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
16
|
-
nodeStoreError('Map: %O',
|
|
20
|
+
nodeStoreError('Map: %O', [...__classPrivateFieldGet(this, _NodeStore_store, "f").entries()].map(([id, node]) => ({
|
|
17
21
|
id,
|
|
18
22
|
name: node.nodeName,
|
|
19
23
|
})));
|
|
@@ -36,7 +40,7 @@ class NodeStore {
|
|
|
36
40
|
nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
37
41
|
nodeStoreError('Invalid node: %O', node);
|
|
38
42
|
}
|
|
39
|
-
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.
|
|
43
|
+
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replaceAll('\n', '⏎').replaceAll('\t', '→'));
|
|
40
44
|
__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -5,10 +5,10 @@ import type { MLDocument } from './document.js';
|
|
|
5
5
|
import type { MLElement } from './element.js';
|
|
6
6
|
import type { MarkuplintPreprocessorBlockType, NodeType, NodeTypeOf } from './types.js';
|
|
7
7
|
import type { RuleInfo } from '../../index.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
9
9
|
import type { AnyRule, PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
10
10
|
import { MLToken } from '../token/token.js';
|
|
11
|
-
export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends
|
|
11
|
+
export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLToken<A> implements Node {
|
|
12
12
|
#private;
|
|
13
13
|
/**
|
|
14
14
|
* @implements DOM API: `Node`
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLNode_childNodes, _MLNode_ownerDocument, _MLNode_prevToken;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { MLToken } from '../token/token.js';
|
|
4
14
|
import { isChildNode } from './child-node.js';
|
|
5
15
|
import { toNodeList } from './node-list.js';
|
|
6
16
|
import { nodeStore } from './node-store.js';
|
|
7
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
8
18
|
export class MLNode extends MLToken {
|
|
9
19
|
constructor(astNode,
|
|
10
20
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
@@ -44,7 +54,7 @@ export class MLNode extends MLToken {
|
|
|
44
54
|
* @implements DOM API: `Node`
|
|
45
55
|
* @see https://dom.spec.whatwg.org/#dom-node-document_position_contains
|
|
46
56
|
*/
|
|
47
|
-
this.DOCUMENT_POSITION_CONTAINS =
|
|
57
|
+
this.DOCUMENT_POSITION_CONTAINS = 0b1000;
|
|
48
58
|
/**
|
|
49
59
|
* @implements DOM API: `Node`
|
|
50
60
|
* @see https://dom.spec.whatwg.org/#dom-node-document_position_disconnected
|
|
@@ -165,11 +175,17 @@ export class MLNode extends MLToken {
|
|
|
165
175
|
if (this.is(this.DOCUMENT_FRAGMENT_NODE) ||
|
|
166
176
|
this.is(this.ELEMENT_NODE) ||
|
|
167
177
|
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
178
|
+
const astChildren =
|
|
168
179
|
// @ts-ignore
|
|
169
|
-
|
|
180
|
+
this._astToken?.childNodes?.filter(node => {
|
|
181
|
+
if (node.type === 'endtag' || node.type === 'invalid') {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return node;
|
|
185
|
+
}) ?? [];
|
|
170
186
|
const childNodes = astChildren
|
|
171
187
|
.map(node => nodeStore.getNode(node))
|
|
172
|
-
.filter(
|
|
188
|
+
.filter(node => isChildNode(node));
|
|
173
189
|
// Cache
|
|
174
190
|
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList(childNodes), "f");
|
|
175
191
|
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
@@ -206,16 +222,16 @@ export class MLNode extends MLToken {
|
|
|
206
222
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
|
|
207
223
|
*/
|
|
208
224
|
get lastChild() {
|
|
225
|
+
// eslint-disable-next-line unicorn/prefer-at
|
|
209
226
|
return this.childNodes[this.childNodes.length - 1] ?? null;
|
|
210
227
|
}
|
|
211
228
|
/**
|
|
212
229
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
213
230
|
*/
|
|
214
231
|
get nextNode() {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return nodeStore.getNode(this._astToken.nextNode);
|
|
232
|
+
const siblings = [...(this.syntacticalParentNode?.childNodes ?? __classPrivateFieldGet(this, _MLNode_ownerDocument, "f").nodeList)];
|
|
233
|
+
const index = siblings.findIndex(node => node.uuid === this.uuid);
|
|
234
|
+
return siblings[index + 1] ?? null;
|
|
219
235
|
}
|
|
220
236
|
/**
|
|
221
237
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -357,10 +373,9 @@ export class MLNode extends MLToken {
|
|
|
357
373
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
358
374
|
*/
|
|
359
375
|
get prevNode() {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return nodeStore.getNode(this._astToken.prevNode);
|
|
376
|
+
const siblings = [...(this.syntacticalParentNode?.childNodes ?? __classPrivateFieldGet(this, _MLNode_ownerDocument, "f").nodeList)];
|
|
377
|
+
const index = siblings.findIndex(node => node.uuid === this.uuid);
|
|
378
|
+
return siblings[index - 1] ?? null;
|
|
364
379
|
}
|
|
365
380
|
/**
|
|
366
381
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -455,6 +470,9 @@ export class MLNode extends MLToken {
|
|
|
455
470
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
456
471
|
*/
|
|
457
472
|
get syntacticalParentNode() {
|
|
473
|
+
if (this._astToken.type === 'attr' || this._astToken.type === 'spread') {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
458
476
|
if (!this._astToken.parentNode) {
|
|
459
477
|
return this.ownerMLDocument;
|
|
460
478
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { MLElement } from './element.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
3
3
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
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 extends PlainData = undefined, A extends
|
|
9
|
+
export declare abstract class MLParentNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLNode<T, O, A> implements ParentNode {
|
|
10
10
|
#private;
|
|
11
11
|
/**
|
|
12
12
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
@@ -1,10 +1,20 @@
|
|
|
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
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
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");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
1
12
|
var _MLParentNode_children, _MLParentNode_selectedElements;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { syncWalk } from '../helper/walkers.js';
|
|
4
14
|
import { getChildren } from '../manipulations/get-children.js';
|
|
5
15
|
import { toNodeList } from './node-list.js';
|
|
6
16
|
import { MLNode } from './node.js';
|
|
7
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
8
18
|
/**
|
|
9
19
|
*
|
|
10
20
|
* @see https://dom.spec.whatwg.org/#interface-parentnode
|
|
@@ -117,7 +127,7 @@ export class MLParentNode extends MLNode {
|
|
|
117
127
|
}
|
|
118
128
|
_descendantsToArray(filter) {
|
|
119
129
|
const nodeList = [];
|
|
120
|
-
syncWalk(
|
|
130
|
+
syncWalk([...this.childNodes], node => {
|
|
121
131
|
if (filter) {
|
|
122
132
|
const filtered = filter(node);
|
|
123
133
|
if (filtered) {
|